コード例 #1
0
  /** Test of addFile method, of class Directory, when file already exists. */
  @Test
  public void testAddFileThatAlreadyExists() {
    System.out.println("addFileThatAlreadyExists");

    TextFile file1 = mock(TextFile.class);
    when(file1.getName()).thenReturn("file1");
    TextFile file2 = mock(TextFile.class);
    when(file2.getName()).thenReturn("file2");

    Directory instance = new Directory("dir1", root);

    instance.addFile(file1);

    assertEquals(1, instance.content.size());
    assertTrue(instance.content.contains(file1));

    instance.addFile(file2);

    assertEquals(2, instance.content.size());
    assertTrue(instance.content.contains(file2));

    instance.addFile(file1);

    assertEquals(2, instance.content.size());
  }
コード例 #2
0
  /** Test of removeFile method, of class Directory. */
  @Test
  public void testRemoveFile() {
    System.out.println("removeFile");

    TextFile file1 = mock(TextFile.class);
    when(file1.getName()).thenReturn("file1");

    TextFile file2 = mock(TextFile.class);
    when(file2.getName()).thenReturn("file2");

    TextFile file3 = mock(TextFile.class);
    when(file3.getName()).thenReturn("file3");

    TextFile f = file3;
    Directory instance = new Directory("dir1", root);
    instance.content.add(file1);
    instance.content.add(file2);
    instance.content.add(file3);

    assertEquals(3, instance.content.size());

    instance.removeFile(f);
    assertEquals(2, instance.content.size());
    assertFalse(instance.content.contains(file3));
  }
コード例 #3
0
  /** Test of findFile method, of class Directory. */
  @Test
  public void testFindFile() {
    System.out.println("findFile");

    TextFile file1 = mock(TextFile.class);
    when(file1.getName()).thenReturn("file1");

    TextFile file2 = mock(TextFile.class);
    when(file2.getName()).thenReturn("file2");

    TextFile file3 = mock(TextFile.class);
    when(file3.getName()).thenReturn("file3");

    Directory instance = new Directory("dir1", root);
    instance.content.add(file1);
    instance.content.add(file2);
    instance.content.add(file3);

    String filename = "file2";
    TextFile result = instance.findFile(filename);

    assertEquals(file2, result);
  }