예제 #1
0
 @Test
 public void test002Relocate() throws InvalidFolderException {
   FileEditor file = new FileEditor(TEST_FILE_LOCATION, TEST_FILE_NAME);
   file.relocate(TEST_FILE_LOCATION_2);
   file.paths();
   file.delete();
 }
예제 #2
0
 @Test
 public void test001Rename() {
   FileEditor file = new FileEditor(TEST_FILE_LOCATION, TEST_FILE_NAME);
   file.rename(TEST_FILE_NAME_2);
   file.paths();
   file.delete();
 }
예제 #3
0
  /*
   * testing file not found exception
   */
  @Test
  public void test007Exception() {
    FileEditor file = new FileEditor(TEST_FILE_LOCATION, TEST_FILE_NAME);

    assertTrue(FileEditor.isExistingFile(TEST_FILE_LOCATION, TEST_FILE_NAME));

    file.delete();
    assertFalse(FileEditor.isExistingFile(TEST_FILE_LOCATION, TEST_FILE_NAME));
    String phrase = "test";
    file.writeToFile(phrase);
    String actual = file.retrieveFromFile();
    assertNull(actual);

    ArrayList<String> expected = new ArrayList<String>();
    file.writeToFile(expected, expected);
    ArrayList<String> actlData = new ArrayList<String>();
    ArrayList<String> actlArchive = new ArrayList<String>();
    file.retrieveFromFile(actlData, actlArchive);
    assertEquals(expected, actlData);
    assertEquals(expected, actlArchive);

    file.clearFile();
    try {
      file.relocate(TEST_FILE_LOCATION_2);
    } catch (InvalidFolderException e) {
      assertEquals(
          "TESTFILES\\TEST3 is an invalid folder path. Please enter a valid folder path.",
          e.getMessage());
    }
    assertFalse(FileEditor.isExistingFile(TEST_FILE_LOCATION, TEST_FILE_NAME));
  }
예제 #4
0
  @Test
  public void test004ReadWriteMultipleLinesOneArrayList() {
    FileEditor file = new FileEditor(TEST_FILE_LOCATION, TEST_FILE_NAME);
    ArrayList<String> inputArrayOne = new ArrayList<String>();
    ArrayList<String> inputArrayTwo = new ArrayList<String>();
    inputArrayOne.add("string 1");
    inputArrayOne.add("string 2");
    inputArrayOne.add("string 3");
    inputArrayOne.add("string 4");
    inputArrayOne.add("string 5");
    inputArrayOne.add("string 6");
    file.writeToFile(inputArrayOne, inputArrayTwo);
    ArrayList<String> retrievedArrayOne = new ArrayList<String>();
    ArrayList<String> retrievedArrayTwo = new ArrayList<String>();
    file.retrieveFromFile(retrievedArrayOne, retrievedArrayTwo);
    for (int i = 0; i < retrievedArrayOne.size(); i++) {
      assertEquals(i + "diff", inputArrayOne.get(i), retrievedArrayOne.get(i));
    }

    inputArrayOne.clear();
    retrievedArrayOne.clear();
    file.writeToFile(inputArrayOne, inputArrayTwo);
    file.retrieveFromFile(retrievedArrayOne, retrievedArrayTwo);
    assertEquals(inputArrayOne.size(), retrievedArrayOne.size());

    for (int i = 0; i < 1000; i++) {
      inputArrayOne.add("string" + i);
    }
    file.writeToFile(inputArrayOne, inputArrayTwo);
    file.retrieveFromFile(retrievedArrayOne, retrievedArrayTwo);
    for (int i = 0; i < retrievedArrayOne.size(); i++) {
      assertEquals(i + "diff", inputArrayOne.get(i), retrievedArrayOne.get(i));
    }
    file.delete();
  }
예제 #5
0
  @Test
  public void test003ReadWriteSingleLine() {
    FileEditor file = new FileEditor(TEST_FILE_LOCATION, TEST_FILE_NAME);
    String inputPhrase = "test phrase";
    file.writeToFile(inputPhrase);
    String retrievedPhrase = file.retrieveFromFile();
    assertEquals("not the same", inputPhrase, retrievedPhrase);

    inputPhrase = "";
    file.writeToFile(inputPhrase);
    retrievedPhrase = file.retrieveFromFile();
    assertEquals("not the same", inputPhrase, retrievedPhrase);
    file.delete();
  }
예제 #6
0
  @Test
  public void test005ReadWriteMultipleLinesTwoArrayList() {
    FileEditor file = new FileEditor(TEST_FILE_LOCATION, TEST_FILE_NAME);
    ArrayList<String> inputArrayOne = new ArrayList<String>();
    ArrayList<String> inputArrayTwo = new ArrayList<String>();
    // normal test scenario
    for (int i = 0; i < 3; i++) {
      inputArrayOne.add("String" + i);
    }
    for (int i = 0; i < 3; i++) {
      inputArrayTwo.add("String" + i);
    }
    file.writeToFile(inputArrayOne, inputArrayTwo);
    ArrayList<String> retrievedArrayOne = new ArrayList<String>();
    ArrayList<String> retrievedArrayTwo = new ArrayList<String>();
    file.retrieveFromFile(retrievedArrayOne, retrievedArrayTwo);
    for (int i = 0; i < retrievedArrayOne.size(); i++) {
      assertEquals(i + "diff", inputArrayOne.get(i), retrievedArrayOne.get(i));
    }
    for (int i = 0; i < retrievedArrayTwo.size(); i++) {
      assertEquals(i + "diff", inputArrayTwo.get(i), retrievedArrayTwo.get(i));
    }

    // testing empty arraylists to write and retrieve
    inputArrayOne.clear();
    inputArrayTwo.clear();
    retrievedArrayOne.clear();
    retrievedArrayTwo.clear();
    file.writeToFile(inputArrayOne, inputArrayTwo);
    file.retrieveFromFile(retrievedArrayOne, retrievedArrayTwo);
    assertEquals(inputArrayOne.size(), retrievedArrayOne.size());

    // testing large quantities to write and retrieve
    for (int i = 0; i < 2000; i++) {
      inputArrayOne.add("String" + i);
    }
    for (int i = 0; i < 3000; i++) {
      inputArrayTwo.add("String" + i);
    }
    file.writeToFile(inputArrayOne, inputArrayTwo);
    file.retrieveFromFile(retrievedArrayOne, retrievedArrayTwo);
    for (int i = 0; i < retrievedArrayOne.size(); i++) {
      assertEquals(i + "diff", inputArrayOne.get(i), retrievedArrayOne.get(i));
    }
    for (int i = 0; i < retrievedArrayTwo.size(); i++) {
      assertEquals(i + "diff", inputArrayTwo.get(i), retrievedArrayTwo.get(i));
    }

    inputArrayOne.clear();
    inputArrayTwo.clear();
    retrievedArrayOne.clear();
    retrievedArrayTwo.clear();
    for (int i = 0; i < 7000; i++) {
      inputArrayTwo.add(
          "String "
              + i
              + " is a very very long string used to test the robustness of the method in execution speed and smoothness");
    }
    file.writeToFile(inputArrayOne, inputArrayTwo);
    file.retrieveFromFile(retrievedArrayOne, retrievedArrayTwo);
    for (int i = 0; i < retrievedArrayTwo.size(); i++) {
      assertEquals(i + "diff", inputArrayTwo.get(i), retrievedArrayTwo.get(i));
    }

    inputArrayOne.clear();
    inputArrayTwo.clear();
    retrievedArrayOne.clear();
    retrievedArrayTwo.clear();
    for (int i = 0; i < 10000; i++) {
      inputArrayOne.add(
          "String "
              + i
              + " is a very very long string used to test the robustness of the method in execution speed and smoothness");
    }
    for (int i = 0; i < 10000; i++) {
      inputArrayTwo.add(
          "String "
              + i
              + " is a very very long string used to test the robustness of the method in execution speed and smoothness");
    }
    file.writeToFile(inputArrayOne, inputArrayTwo);
    file.retrieveFromFile(retrievedArrayOne, retrievedArrayTwo);
    for (int i = 0; i < retrievedArrayOne.size(); i++) {
      assertEquals(i + "diff", inputArrayOne.get(i), retrievedArrayOne.get(i));
    }
    for (int i = 0; i < retrievedArrayTwo.size(); i++) {
      assertEquals(i + "diff", inputArrayTwo.get(i), retrievedArrayTwo.get(i));
    }
    inputArrayOne.clear();
    inputArrayTwo.clear();
    retrievedArrayOne.clear();
    retrievedArrayTwo.clear();
    file.clearFile();
    file.delete();
  }