// Sort two or more items. @Test public void sortTc3() { tb.executeCommand("add b"); tb.executeCommand("add a"); tb.executeCommand("sort"); assertEquals("1. a\n2. b", tb.executeCommand("display")); }
/** Test if the "Display" works in TextBuddy.java */ @Test public void testDisplay() { TextBuddy textBuddy = new TextBuddy("display.txt"); String fileName = textBuddy.getFileName(); ArrayList<String> originalDisplayList = TextBuddy.readFile("display.txt"); ArrayList<String> displayList = TextBuddy.display(fileName); assertEquals(true, isCompareList(displayList, originalDisplayList)); }
/** Test if the "Clear" works in TextBuddy.java */ @Test public void testClear() { TextBuddy textBuddy = new TextBuddy("clear.txt"); String fileName = textBuddy.getFileName(); String command = textBuddy.executeCommand("clear", "", fileName); String expectedOutput = "all content deleted from " + fileName; assertEquals(true, command.equals(expectedOutput)); }
/** Test if the "Add" works in TextBuddy.java */ @Test public void testAdd() { TextBuddy textBuddy = new TextBuddy("add.txt"); String fileName = textBuddy.getFileName(); String addLine = "hello my world"; String command = textBuddy.executeCommand("add", addLine, fileName); String expectedOutput = "added to " + fileName + ": \"" + "hello my world" + "\""; assertEquals(true, command.equals(expectedOutput)); }
/** Test if the "Delete" works in TextBuddy.java */ @Test public void testDelete() { TextBuddy textBuddy = new TextBuddy("delete.txt"); String fileName = textBuddy.getFileName(); String numLine = "2"; String command = textBuddy.executeCommand("delete", numLine, fileName); String deletedLine = "deleted from " + fileName + ": \"" + "why delete me" + "\""; assertEquals(true, command.equals(deletedLine)); }
/** Test if the "Search" works in TextBuddy.java */ @Test public void testSearchKeywords() { TextBuddy textBuddy = new TextBuddy("searchList.txt"); String fileName = textBuddy.getFileName(); String keyword = "name"; ArrayList<String> searchList = TextBuddy.search(keyword, fileName); ArrayList<String> searchResultList = TextBuddy.readFile("searchResultList.txt"); assertEquals(true, isCompareList(searchList, searchResultList)); }
/** Test if the "Sort" works in TextBuddy.java */ @Test public void testSortList() { TextBuddy textBuddy = new TextBuddy("unsortedList.txt"); String fileName = textBuddy.getFileName(); TextBuddy.sort(fileName); ArrayList<String> unsortedList = TextBuddy.readFile(fileName); ArrayList<String> sortedList = TextBuddy.readFile("sortedList.txt"); assertEquals(true, isCompareList(unsortedList, sortedList)); }
// Search for non-existent item. @Test public void searchTc5() { tb.executeCommand("add apple1"); tb.executeCommand("add apple2"); assertEquals("orange is not found.", tb.executeCommand("search orange")); }
// Search for two or more partial items. @Test public void searchTc4() { tb.executeCommand("add apple1"); tb.executeCommand("add apple2"); assertEquals("- apple1\n- apple2", tb.executeCommand("search app")); }
// Search for one partial item. @Test public void searchTc3() { tb.executeCommand("add apple"); assertEquals("- apple", tb.executeCommand("search app")); }
// Search for nothing. @Test public void searchTc1() { assertEquals("Search invalid!", tb.executeCommand("search")); }
// Sort nothing. @Test public void sortTc1() { assertEquals("Successfully sorted! \"mytextfile.txt\"", tb.executeCommand("sort")); }
@After public void tearDown() throws Exception { tb.executeCommand("clear"); }