示例#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"));
 }
示例#2
0
文件: UnitTest.java 项目: tangwr/CE2
  /** 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));
  }
示例#3
0
文件: UnitTest.java 项目: tangwr/CE2
  /** 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));
  }
示例#4
0
文件: UnitTest.java 项目: tangwr/CE2
  /** 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));
  }
示例#5
0
文件: UnitTest.java 项目: tangwr/CE2
  /** 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));
  }
示例#6
0
文件: UnitTest.java 项目: tangwr/CE2
  /** 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));
  }
示例#7
0
文件: UnitTest.java 项目: tangwr/CE2
  /** 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));
  }
示例#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"));
 }
示例#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"));
 }
示例#10
0
 // Search for one partial item.
 @Test
 public void searchTc3() {
   tb.executeCommand("add apple");
   assertEquals("- apple", tb.executeCommand("search app"));
 }
示例#11
0
 // Search for nothing.
 @Test
 public void searchTc1() {
   assertEquals("Search invalid!", tb.executeCommand("search"));
 }
示例#12
0
 // Sort nothing.
 @Test
 public void sortTc1() {
   assertEquals("Successfully sorted! \"mytextfile.txt\"", tb.executeCommand("sort"));
 }
示例#13
0
 @After
 public void tearDown() throws Exception {
   tb.executeCommand("clear");
 }