@Test public void testMapShouldCoverAllErrorCodes() { Stream.of(ErrorCode.values()).forEach( e -> { final AbstractPublishingPluginException exception = AppExceptionMapper.map(new AppException("", e)); assertThat(exception, notNullValue()); }); }
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; }
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; } }
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(); }
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); }
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);  }