NamedCountersFileWriter { public void writeCounters(NamedCounters counters, String filePath) throws IOException { Properties counterProperties = buildPropertiesFromCounters(counters); File file = new File(filePath); try (OutputStream os = new FileOutputStream(file)) { counterProperties.store(os, null); } }  void writeCounters(NamedCounters counters, String filePath);  }
@Test public void writeCounters() throws IOException { NamedCounters namedCounters = new NamedCounters(new String[] { counterName1, counterName2 }); namedCounters.increment(counterName1, 4L); namedCounters.increment(counterName2, 2L); countersFileWriter.writeCounters(namedCounters, tempFolder.getRoot().getPath() + "/counters.properties"); Properties actualProperties = loadProperties(new File(tempFolder.getRoot(), "counters.properties")); Properties expectedProperties = new Properties(); expectedProperties.put(counterName1, "4"); expectedProperties.put(counterName2, "2"); assertEquals(expectedProperties, actualProperties); }