### Question:
AppExceptionMapper { public static AbstractPublishingPluginException map(final AppException appException) { if (appException == null || appException.getErrorCode() == null) return new UnkonwnException("Unknown Exception"); final String message = appException.getMessage(); final ErrorCode errorCode = appException.getErrorCode(); AbstractPublishingPluginException mappedException; if (apiGatewayCommunicationErrors.contains(errorCode)) { mappedException = new ApiGatewayCommunicationException(message, appException, errorCode); } else if (apiGatewayInternalErrors.contains(errorCode)) { mappedException = new ApiGatewayPublishingException(message, appException, errorCode); } else { switch (errorCode) { case NO_CHANGE: mappedException = new NoChangesInApiForPublishException(message, appException, errorCode); break; case BREAKING_CHANGE_DETECTED: mappedException = new BreakingChangeException(message, appException, errorCode); break; case MISSING_PARAMETER: mappedException = new ArgumentParseException(message, appException, errorCode); break; case CANT_READ_CONFIG_FILE: return new ApiConfigurationFileException(message, appException, errorCode); case CANT_READ_API_DEFINITION_FILE: mappedException = new ApiSpecificationFileException(message, appException, errorCode); break; default: mappedException = new UnkonwnException("Unkonwn Error", appException); } } return mappedException; } private  AppExceptionMapper(); static AbstractPublishingPluginException map(final AppException appException);  }### Answer:
@Test public void map() throws Exception { checkTypeOfException(ErrorCode.NO_CHANGE, NoChangesInApiForPublishException.class); checkTypeOfException(ErrorCode.BREAKING_CHANGE_DETECTED, BreakingChangeException.class); checkTypeOfException(ErrorCode.MISSING_PARAMETER, ArgumentParseException.class); checkTypeOfException(ErrorCode.CANT_READ_CONFIG_FILE, ApiConfigurationFileException.class); checkTypeOfException(ErrorCode.CANT_READ_API_DEFINITION_FILE, ApiSpecificationFileException.class); checkTypeOfException(ErrorCode.CANT_PARSE_HTTP_RESPONSE, ApiGatewayCommunicationException.class); checkTypeOfException(ErrorCode.CANT_READ_JSON_PAYLOAD, ApiGatewayCommunicationException.class); checkTypeOfException(ErrorCode.CANT_SEND_HTTP_REQUEST, ApiGatewayCommunicationException.class); checkTypeOfException(ErrorCode.API_MANAGER_COMMUNICATION, ApiGatewayCommunicationException.class); checkTypeOfException(ErrorCode.CANT_CREATE_API_PROXY, ApiGatewayPublishingException.class); checkTypeOfException(ErrorCode.CANT_CREATE_STATE_CHANGE, ApiGatewayPublishingException.class); checkTypeOfException(ErrorCode.CANT_SETUP_VHOST, ApiGatewayPublishingException.class); checkTypeOfException(ErrorCode.CANT_UPDATE_API_PROXY, ApiGatewayPublishingException.class); checkTypeOfException(ErrorCode.CANT_CREATE_BE_API, ApiGatewayPublishingException.class); checkTypeOfException(ErrorCode.CANT_UPDATE_API_STATUS, ApiGatewayPublishingException.class); checkTypeOfException(ErrorCode.CANT_UPDATE_QUOTA_CONFIG, ApiGatewayPublishingException.class); checkTypeOfException(ErrorCode.CANT_UPGRADE_API_ACCESS, ApiGatewayPublishingException.class); }
@Test public void testMapShouldThrowUnknownException() { final AbstractPublishingPluginException exception = AppExceptionMapper.map(null); assertThat(exception, instanceOf(UnkonwnException.class)); assertThat(exception.getErrorCode(), nullValue()); }
@Test public void testMapShouldCoverAllErrorCodes() { Stream.of(ErrorCode.values()).forEach( e -> { final AbstractPublishingPluginException exception = AppExceptionMapper.map(new AppException("", e)); assertThat(exception, notNullValue()); }); }