@Test public void logShouldSwallowExceptions() throws JsonProcessingException { SystemFragment frag = SystemFragment.empty(); Mockito.when(analyzerMock.analyzeSystem()).thenReturn(frag); Mockito.when(objectMapperMock.writeValueAsString(frag)).thenThrow(Mockito.mock(JsonGenerationException.class)); logSnitch.log(); Mockito.verify(analyzerMock).analyzeSystem(); Mockito.verify(objectMapperMock).writeValueAsString(frag); }
public void log() { if (LOGGER.isInfoEnabled()) { try { SystemFragment frag = analyzer.analyzeSystem(); String fragString = objectMapper.writeValueAsString(frag); LOGGER.info("System fragment : {}", fragString); } catch (IOException | RuntimeException e) { LOGGER.error("Error while logging system fragment", e); } } }
Slf4jSnitchLogger implements CommandLineRunner { public void log() { if (LOGGER.isInfoEnabled()) { try { SystemFragment frag = analyzer.analyzeSystem(); String fragString = objectMapper.writeValueAsString(frag); LOGGER.info("System fragment : {}", fragString); } catch (IOException | RuntimeException e) { LOGGER.error("Error while logging system fragment", e); } } } }
Slf4jSnitchLogger implements CommandLineRunner { public void log() { if (LOGGER.isInfoEnabled()) { try { SystemFragment frag = analyzer.analyzeSystem(); String fragString = objectMapper.writeValueAsString(frag); LOGGER.info("System fragment : {}", fragString); } catch (IOException | RuntimeException e) { LOGGER.error("Error while logging system fragment", e); } } } Slf4jSnitchLogger(ApplicationAnalyzer analyzer, ObjectMapper objectMapper); }
Slf4jSnitchLogger implements CommandLineRunner { public void log() { if (LOGGER.isInfoEnabled()) { try { SystemFragment frag = analyzer.analyzeSystem(); String fragString = objectMapper.writeValueAsString(frag); LOGGER.info("System fragment : {}", fragString); } catch (IOException | RuntimeException e) { LOGGER.error("Error while logging system fragment", e); } } } Slf4jSnitchLogger(ApplicationAnalyzer analyzer, ObjectMapper objectMapper); void log(); @Override void run(String... args); }
Slf4jSnitchLogger implements CommandLineRunner { public void log() { if (LOGGER.isInfoEnabled()) { try { SystemFragment frag = analyzer.analyzeSystem(); String fragString = objectMapper.writeValueAsString(frag); LOGGER.info("System fragment : {}", fragString); } catch (IOException | RuntimeException e) { LOGGER.error("Error while logging system fragment", e); } } } Slf4jSnitchLogger(ApplicationAnalyzer analyzer, ObjectMapper objectMapper); void log(); @Override void run(String... args);  }