コード例 #1
0
 public synchronized void addAll(ChecklistStatus list) {
   Enumeration cur = list.elements();
   while (cur.hasMoreElements()) {
     CheckItem item = (CheckItem) cur.nextElement();
     addItem(item);
   }
 }
コード例 #2
0
  /** Test constructor and some basic methods. */
  public void testBasics() {

    String category = "";
    String description = "";

    // initialize the ChecklistStatus
    ChecklistStatus list = new ChecklistStatus();

    // add some test data
    list.addItem("Test1");
    list.addItem("Test2");
    list.setNextCategory("Test Category");
    list.addItem("Test3");
    list.addItem("Test4");

    // verify the size of the list
    assertTrue("ChecklistStatus.size() is incorrect", list.size() == 4);

    // verify the items were correctly added
    int iter = 0;
    for (CheckItem item : list.getCheckItemList()) {

      switch (++iter) {
        case 1:
          category = "General";
          description = "Test1";
          break;

        case 2:
          category = "General";
          description = "Test2";
          break;

        case 3:
          category = "Test Category";
          description = "Test3";
          break;

        case 4:
          category = "Test Category";
          description = "Test4";
          break;
      }

      // test that the category and description are correct
      assertTrue(
          "ChecklistStatus items incorrectly added (category: "
              + category
              + ", description: )"
              + description,
          category == item.getCategory() && description == item.getDescription());
    }

    // create a new list to test the addAll
    ChecklistStatus list2 = new ChecklistStatus();

    // add all of the test items from the first list
    list2.addAll(list);

    // verify the size of the new list
    assertTrue("ChecklistStatus.addAll(Checklist) failed", list2.size() == 4);
  }