@Test public void writeToRandomTemporaryFileWhenNoLocationDefined() throws Exception { CereebroProperties properties = new CereebroProperties(); final String componentName = "cereebro-unit-tests"; properties.getApplication().getComponent().setName(componentName); properties.getSnitch().getFile().setLocation(null); FileWriterSnitch snitch = new FileWriterSnitch(analyzerMock, objectMapper, properties); snitch.run(); File tempRoot = new File(System.getProperty("java.io.tmpdir")); File[] tempFiles = tempRoot.listFiles((FilenameFilter) (dir, fileName) -> fileName.contains(componentName)); Assertions.assertThat(tempFiles).isNotEmpty(); Stream.of(tempFiles).forEach(f -> f.deleteOnExit()); }
@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();  }