### Question:
FileWriterEngine { public static void write(Object result, FileOptions options) throws RendererException { Objects.requireNonNull(result); Object content = Objects.requireNonNull(getFileStrategy(options, result)).render(); FileWriter fileWriter = getFileWriter(options.getType()); fileWriter.write(new File(options.getName()).toPath(), content); } private  FileWriterEngine(); static void write(Object result, FileOptions options);  }### Answer:
@Test public void basicTest() throws RendererException { Set<TestVertex> set = new HashSet<>(); set.add(new TestVertex.Builder("actor1.as", "action1a",null).build()); set.add(new TestVertex.Builder("actor2bb", "action1b", null).build()); Result res = new Result(); res.put(ResultContent.RELATED_TESTS, Set.class, set); FileWriterEngine.write(set, new FileOptions.FileOptionsBuilder().with(fo -> {fo.name = MY_TEST_FILE; fo.type = FileType.CSV ;}).build()); assertTrue(new File(System.getProperty("user.dir"), MY_TEST_FILE).exists()); }
@Test public void basicTestJson() throws RendererException { Set<TestVertex> set = new HashSet<>(); set.add(new TestVertex.Builder("actor1.as", "action1a", null).build()); set.add(new TestVertex.Builder("actor2bb", "action1b", null).build()); Result res = new Result(); res.put(ResultContent.RELATED_TESTS, Set.class, set); FileWriterEngine.write(set, new FileOptions.FileOptionsBuilder().with(fo -> {fo.name = MY_JSON_TEST_FILE; fo.type = FileType.JSON ;}).build()); assertTrue(new File(System.getProperty("user.dir"), MY_JSON_TEST_FILE).exists()); }
@Test(expected = NullPointerException.class) public void testFileWriteWhenResultIsNull() throws RendererException { FileWriterEngine.write(null, new FileOptions.FileOptionsBuilder().with(fo -> {fo.name = MY_JSON_TEST_FILE; fo.type = FileType.JSON ;}).build()); }
@Test public void testBasicProperties() throws RendererException { Map<String, String> map = new HashMap<>(); map.put("key1", "val1"); map.put("key2", "val2"); Result res = new Result(); res.put(ResultContent.OUTPUT_TO_FILE, Map.class, map); FileWriterEngine.write(map, new FileOptions.FileOptionsBuilder().with(fo -> {fo.name = MY_PROP_TEST_FILE; fo.type = FileType.PROPERTIES ;}).build()); assertTrue(new File(System.getProperty("user.dir"), MY_PROP_TEST_FILE).exists()); }
@Test(expected = RendererException.class) public void testInvalidContent() throws RendererException { PropertiesFileWriter propertiesFileWriter = new PropertiesFileWriter(); Path path = Paths.get(MY_TEST_PROPERTIES_FILE_WRITER_FILE); propertiesFileWriter.write(path, null); }
@Test public void testPropertiesFileWriter() throws RendererException, IOException { Map<String, String> map = new HashMap<>(); map.put("key1", "val1"); map.put("key2", "val2"); PropertiesFileWriter propertiesFileWriter = new PropertiesFileWriter(); Path path = Paths.get(MY_TEST_PROPERTIES_FILE_WRITER_FILE); propertiesFileWriter.write(path, map); try (InputStream input = new FileInputStream(path.toString())) { Properties prop = new Properties(); prop.load(input); Assert.assertEquals(2, prop.size()); Assert.assertTrue(prop.containsKey("key1")); Assert.assertTrue(prop.containsKey("key2")); } assertTrue(new File(System.getProperty("user.dir"), MY_TEST_PROPERTIES_FILE_WRITER_FILE).exists()); }