Ejemplo n.º 1
0
 // 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"));
 }
Ejemplo n.º 2
0
  /** 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));
  }
Ejemplo n.º 3
0
  /** 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));
  }
Ejemplo n.º 4
0
  /** 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));
  }
Ejemplo n.º 5
0
  /** 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));
  }
Ejemplo n.º 6
0
  /** 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));
  }
Ejemplo n.º 7
0
  /** 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));
  }
Ejemplo n.º 8
0
 // 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"));
 }
Ejemplo n.º 9
0
 // 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"));
 }
Ejemplo n.º 10
0
 // Search for one partial item.
 @Test
 public void searchTc3() {
   tb.executeCommand("add apple");
   assertEquals("- apple", tb.executeCommand("search app"));
 }
Ejemplo n.º 11
0
 // Search for nothing.
 @Test
 public void searchTc1() {
   assertEquals("Search invalid!", tb.executeCommand("search"));
 }
Ejemplo n.º 12
0
 // Sort nothing.
 @Test
 public void sortTc1() {
   assertEquals("Successfully sorted! \"mytextfile.txt\"", tb.executeCommand("sort"));
 }
Ejemplo n.º 13
0
 @After
 public void tearDown() throws Exception {
   tb.executeCommand("clear");
 }