Esempio n. 1
0
  public void testRemove() throws IOException {
    int i = 0;
    TextFile tf = new TextFile(TEST_FILE_NAME);

    for (String name : tf) {
      System.out.println("::: " + name);
      assertEquals(names.get(i++), name);
    }

    // testing remove()
    for (Iterator<String> it = tf.iterator(); it.hasNext(); ) {
      String name = it.next();
      if ("Dirk".equals(name)) {
        it.remove();
        System.out.println("removing dirk");
      }
    }

    names.remove("Dirk");

    i = 0;
    for (String name : tf) {
      System.out.println("::: " + name);
      assertEquals(names.get(i++), name);
    }
  }
Esempio n. 2
0
  public void testBadRemove() throws IOException {
    TextFile tf = new TextFile(TEST_FILE_NAME);
    Iterator<String> it = tf.iterator();
    try {
      it.remove();
      fail("Expected an IllegalStateException");
    } catch (IllegalStateException success) {

    }
  }
Esempio n. 3
0
  public void testAllRemove() throws IOException {
    TextFile tf = new TextFile(TEST_FILE_NAME);

    // testing remove() on first element
    Iterator<String> it = tf.iterator();
    while (it.hasNext()) {
      it.next();
      it.remove();
    }

    it = tf.iterator();
    assertFalse(it.hasNext());
  }
Esempio n. 4
0
  public void testFirstRemove() throws IOException {
    int i = 0;
    TextFile tf = new TextFile(TEST_FILE_NAME);

    // testing remove() on first element
    Iterator<String> it = tf.iterator();
    it.next();
    it.remove();

    names.remove("John");

    i = 0;
    for (String name : tf) {
      System.out.println("::: " + name);
      assertEquals(names.get(i++), name);
    }
  }
Esempio n. 5
0
  public void testConcurrentModificationException() throws IOException {
    TextFile tf = new TextFile(TEST_FILE_NAME);

    Iterator<String> broken = tf.iterator();

    for (Iterator<String> it = tf.iterator(); it.hasNext(); ) {
      String name = it.next();
      if ("Dirk".equals(name)) {
        it.remove();
      }
    }
    try {
      broken.next();
      fail("Expected a ConcurrentModificationException");
    } catch (ConcurrentModificationException success) {
    }
  }