LoadIO { public String save(Args args) { new File(DIRECTORY_NAME).mkdir(); String fileName = filename(args); saveInternal(fileName, false); return fileName + " is saved.\n"; } LoadIO(Load load); String save(Args args); void load(Args args, String input); String showSavedFiles(Args args); static final String NO_SAVED_FILE; }
@Test public void testSave() throws Exception { String filename; String[] argsRaw = {"zookeeper", "table"}; Args args = new StatArgs(argsRaw); Load load = new Load(new LevelClass(TableName.class), args); LoadIO loadIO = createLoadIO(load); filename = loadIO.filename(args); long timestamp = loadIO.getTimestamp(args, filename); try { assertEquals(0, loadIO.savedFileNameList(args).size()); loadIO.save(args); List<String> strings = Files.readAllLines(Paths.get(filename), Charset.defaultCharset()); for (String string : strings) { System.out.println(string); } assertEquals(3, strings.size()); assertEquals("\"Table\",\"Timestamp\",\"Reads\",\"Writes\",\"Regions\",\"Files\",\"FileSize\",\"FileSizeUncomp\",\"MemstoreSize\",\"CompactedKVs\"", strings.get(0)); assertEquals("\"rec1\",\"" + timestamp + "\",\"2\",\"\",\"\",\"\",\"\",\"\",\"\",\"\"", strings.get(1)); assertEquals("\"rec2\",\"" + timestamp + "\",\"1\",\"\",\"\",\"\",\"\",\"\",\"\",\"\"", strings.get(2)); assertEquals(1, loadIO.savedFileNameList(args).size()); } finally { Files.delete(Paths.get(filename)); } }