/** * Returns a {@link RiposteUnhandledErrorHandler} that uses the given {@link ProjectApiErrors}. */ public static RiposteUnhandledErrorHandler defaultUnhandledErrorHandler(ProjectApiErrors projectApiErrors, ApiExceptionHandlerUtils utils) { return new RiposteUnhandledExceptionHandler(projectApiErrors, utils); }
@Before public void beforeMethod() { adapterSpy = spy(new RiposteUnhandledExceptionHandler(projectApiErrors, utils)); }
@Test(expected = IllegalArgumentException.class) public void constructorShouldBarfIfPassedNullUtils() { new RiposteUnhandledExceptionHandler(projectApiErrors, null); }
@Test(expected = IllegalArgumentException.class) public void constructorShouldBarfIfPassedNullProjectApiErrors() { new RiposteUnhandledExceptionHandler(null, utils); }
@Test public void constructorWorksIfPassedValidValues() { RiposteUnhandledExceptionHandler myAdapter = new RiposteUnhandledExceptionHandler(projectApiErrors, utils); assertThat(Whitebox.getInternalState(myAdapter, "projectApiErrors"), is(projectApiErrors)); assertThat(Whitebox.getInternalState(myAdapter, "utils"), is(utils)); }
@Test public void prepareFrameworkResponseUsesErrorResponseBodyNettyAdapterWrapper() { RiposteUnhandledExceptionHandler myAdapter = new RiposteUnhandledExceptionHandler(projectApiErrors, utils); DefaultErrorContractDTO errorContract = new DefaultErrorContractDTO(UUID.randomUUID().toString(), Arrays.asList(projectApiErrors.getUnauthorizedApiError(), projectApiErrors.getMalformedRequestApiError())); ErrorResponseBody result = myAdapter.prepareFrameworkRepresentation(errorContract, 42, null, null, null); assertThat(result, instanceOf(ErrorResponseBodyImpl.class)); ErrorResponseBodyImpl adapterResult = (ErrorResponseBodyImpl)result; assertThat(adapterResult.error_id, is(errorContract.error_id)); assertThat(adapterResult.errors, is(errorContract.errors)); }