@Test void testHandleException() { Exception exception = when(mock(Exception.class).getLocalizedMessage()).thenReturn("message").getMock(); ImportWizard importWizard = mock(ImportWizard.class); BindingResult bindingResult = mock(BindingResult.class); Logger logger = mock(Logger.class); String dataImportOption = "dataImportOption"; ImportWizardUtil.handleException( exception, importWizard, bindingResult, logger, dataImportOption); verify(bindingResult) .addError(new ObjectError("wizard", "<b>Your import failed:</b><br />message")); }
static void handleException( Exception e, ImportWizard importWizard, BindingResult result, Logger logger, String dataImportOption) { File file = importWizard.getFile(); if (logger.isWarnEnabled()) { logger.warn( format( "Import of file [%s] failed for action [%s]", Optional.ofNullable(file).map(File::getName).orElse("UNKNOWN"), dataImportOption), e); } result.addError( new ObjectError("wizard", "<b>Your import failed:</b><br />" + e.getLocalizedMessage())); }
ImportWizardUtil { static void handleException( Exception e, ImportWizard importWizard, BindingResult result, Logger logger, String dataImportOption) { File file = importWizard.getFile(); if (logger.isWarnEnabled()) { logger.warn( format( "Import of file [%s] failed for action [%s]", Optional.ofNullable(file).map(File::getName).orElse("UNKNOWN"), dataImportOption), e); } result.addError( new ObjectError("wizard", "<b>Your import failed:</b><br />" + e.getLocalizedMessage())); } }
ImportWizardUtil { static void handleException( Exception e, ImportWizard importWizard, BindingResult result, Logger logger, String dataImportOption) { File file = importWizard.getFile(); if (logger.isWarnEnabled()) { logger.warn( format( "Import of file [%s] failed for action [%s]", Optional.ofNullable(file).map(File::getName).orElse("UNKNOWN"), dataImportOption), e); } result.addError( new ObjectError("wizard", "<b>Your import failed:</b><br />" + e.getLocalizedMessage())); } private  ImportWizardUtil(); }
ImportWizardUtil { static void handleException( Exception e, ImportWizard importWizard, BindingResult result, Logger logger, String dataImportOption) { File file = importWizard.getFile(); if (logger.isWarnEnabled()) { logger.warn( format( "Import of file [%s] failed for action [%s]", Optional.ofNullable(file).map(File::getName).orElse("UNKNOWN"), dataImportOption), e); } result.addError( new ObjectError("wizard", "<b>Your import failed:</b><br />" + e.getLocalizedMessage())); } private  ImportWizardUtil();  }
ImportWizardUtil { static void handleException( Exception e, ImportWizard importWizard, BindingResult result, Logger logger, String dataImportOption) { File file = importWizard.getFile(); if (logger.isWarnEnabled()) { logger.warn( format( "Import of file [%s] failed for action [%s]", Optional.ofNullable(file).map(File::getName).orElse("UNKNOWN"), dataImportOption), e); } result.addError( new ObjectError("wizard", "<b>Your import failed:</b><br />" + e.getLocalizedMessage())); } private  ImportWizardUtil();   }