Пример #1
0
  /** 同一ファイル名、同一時刻でも、完全に比較する場合のテスト。 */
  @Test
  public void testSame() throws Exception {
    long current = System.currentTimeMillis() - 10000L;
    File a = tempdir.newFolder("a");
    File a1 = tempdir.newFile("a/1");
    touch(a1, "data 11", current);
    File a2 = tempdir.newFile("a/2");
    touch(a2, "data 2222", current);
    File a3 = tempdir.newFile("a/3");
    touch(a3, "data 333333", current);

    current += 10000L;
    File b = tempdir.newFolder("b");
    File b1 = tempdir.newFile("b/1");
    touch(b1, "data 11", a1.lastModified());
    File b2 = tempdir.newFile("b/2");
    touch(b2, "data 1212", a2.lastModified());
    File b3 = tempdir.newFile("b/3");
    touch(b3, "data 131313", a3.lastModified());

    BackuperEx target = new BackuperEx(a, b);

    target.doCompare(System.out);

    assertEquals(new ArrayList<File>(), target.fromOnlyList);
    assertEquals(makeFilePairList(new File[] {a1, b1, a2, b2, a3, b3}), target.sameList);
    assertEquals(new ArrayList<File>(), target.toOnlyList);
    assertEquals(new ArrayList<FilePair>(), target.touchList);
    assertEquals(new ArrayList<File>(), target.moveList);

    target.compareSameList(System.out);

    assertEquals(Arrays.asList(new File[] {a2, a3}), target.fromOnlyList);
    assertEquals(makeFilePairList(new File[] {a1, b1}), target.sameList);
    assertEquals(Arrays.asList(new File[] {b2, b3}), target.toOnlyList);
    assertEquals(new ArrayList<FilePair>(), target.touchList);
    assertEquals(new ArrayList<File>(), target.moveList);

    target.doExecute(System.out);

    assertDirectory(
        b,
        new String[][] {
          {"1", "data 11"},
          {"2", "data 2222"},
          {"3", "data 333333"},
        });
  }