/** * Returns a {@link RiposteErrorHandler} that uses the given {@link ProjectApiErrors}, and {@link * #defaultHandlerListeners(ProjectApiErrors, ApiExceptionHandlerUtils)} for the error handler listeners. */ public static RiposteErrorHandler defaultErrorHandler(ProjectApiErrors projectApiErrors, ApiExceptionHandlerUtils utils) { return new RiposteApiExceptionHandler( projectApiErrors, defaultHandlerListeners(projectApiErrors, utils), utils ); }
@Test(expected = IllegalArgumentException.class) public void constructorShouldBarfIfPassedNullProjectApiErrors() { new RiposteApiExceptionHandler(null, validListenerList, utils); }
@Before public void beforeMethod() { adapterSpy = spy(new RiposteApiExceptionHandler(projectApiErrors, validListenerList, utils)); }
@Test(expected = IllegalArgumentException.class) public void constructorShouldBarfIfPassedNullListenersList() { new RiposteApiExceptionHandler(projectApiErrors, null, utils); }
@Test(expected = IllegalArgumentException.class) public void constructorShouldBarfIfPassedNullApiExceptionHandlerUtils() { new RiposteApiExceptionHandler(projectApiErrors, validListenerList, null); }
@Test public void prepareFrameworkResponseUsesErrorResponseBodyNettyAdapterWrapper() { RiposteApiExceptionHandler myAdapter = new RiposteApiExceptionHandler(projectApiErrors, validListenerList, 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)); }
@Test public void constructorWorksIfPassedValidValues() { // when RiposteApiExceptionHandler myAdapter = new RiposteApiExceptionHandler(projectApiErrors, validListenerList, utils); // then List<ApiExceptionHandlerListener> actualListeners = (List<ApiExceptionHandlerListener>) Whitebox.getInternalState(myAdapter, "apiExceptionHandlerListenerList"); ProjectApiErrors actualProjectApiErrors = (ProjectApiErrors) Whitebox.getInternalState(myAdapter, "projectApiErrors"); ApiExceptionHandlerUtils actualUtils = (ApiExceptionHandlerUtils) Whitebox.getInternalState(myAdapter, "utils"); assertThat(actualListeners, is(validListenerList)); assertThat(actualProjectApiErrors, is(projectApiErrors)); assertThat(actualUtils, is(utils)); }