@Test public void ioExceptionShouldBeSwallowed() throws Exception { CereebroProperties properties = new CereebroProperties(); File temp = temporaryFolder.newFile(); properties.getSnitch().getFile().setLocation(temp.getAbsolutePath()); ObjectMapper messedUpMapperMock = Mockito.mock(ObjectMapper.class); Mockito.when(messedUpMapperMock.writeValueAsString(SystemFragment.empty())) .thenThrow(Mockito.mock(JsonProcessingException.class)); FileWriterSnitch snitch = new FileWriterSnitch(analyzerMock, messedUpMapperMock, properties); snitch.run(); Assertions.assertThat(temp.length()).isEqualTo(0); }
@Override public void run(String... args) throws Exception { String location = properties.getSnitch().getFile().getLocation(); try { file = StringUtils.hasText(location) ? new File(location) : File.createTempFile(properties.getApplication().getComponent().getName(), ".json"); write(file); } catch (IOException e) { LOGGER.error("Error while writing JSON to file : " + location, e); } }
FileWriterSnitch implements CommandLineRunner, Snitch { @Override public void run(String... args) throws Exception { String location = properties.getSnitch().getFile().getLocation(); try { file = StringUtils.hasText(location) ? new File(location) : File.createTempFile(properties.getApplication().getComponent().getName(), ".json"); write(file); } catch (IOException e) { LOGGER.error("Error while writing JSON to file : " + location, e); } } }
FileWriterSnitch implements CommandLineRunner, Snitch { @Override public void run(String... args) throws Exception { String location = properties.getSnitch().getFile().getLocation(); try { file = StringUtils.hasText(location) ? new File(location) : File.createTempFile(properties.getApplication().getComponent().getName(), ".json"); write(file); } catch (IOException e) { LOGGER.error("Error while writing JSON to file : " + location, e); } } FileWriterSnitch(ApplicationAnalyzer analyzer, ObjectMapper objectMapper, CereebroProperties properties); }
FileWriterSnitch implements CommandLineRunner, Snitch { @Override public void run(String... args) throws Exception { String location = properties.getSnitch().getFile().getLocation(); try { file = StringUtils.hasText(location) ? new File(location) : File.createTempFile(properties.getApplication().getComponent().getName(), ".json"); write(file); } catch (IOException e) { LOGGER.error("Error while writing JSON to file : " + location, e); } } FileWriterSnitch(ApplicationAnalyzer analyzer, ObjectMapper objectMapper, CereebroProperties properties); @Override void run(String... args); void write(File f); @Override URI getUri(); @Override SystemFragment snitch(); }
FileWriterSnitch implements CommandLineRunner, Snitch { @Override public void run(String... args) throws Exception { String location = properties.getSnitch().getFile().getLocation(); try { file = StringUtils.hasText(location) ? new File(location) : File.createTempFile(properties.getApplication().getComponent().getName(), ".json"); write(file); } catch (IOException e) { LOGGER.error("Error while writing JSON to file : " + location, e); } } FileWriterSnitch(ApplicationAnalyzer analyzer, ObjectMapper objectMapper, CereebroProperties properties); @Override void run(String... args); void write(File f); @Override URI getUri(); @Override SystemFragment snitch();  }