Exemplo n.º 1
0
  @Test
  public void testToListWithHashtable() {
    final Hashtable<String, Integer> expected = new Hashtable<String, Integer>();
    expected.put("one", Integer.valueOf(1));
    expected.put("two", Integer.valueOf(2));
    expected.put("three", Integer.valueOf(3));
    // validate elements.
    final List<Integer> actualEltList = EnumerationUtils.toList(expected.elements());
    assertEquals(expected.size(), actualEltList.size());
    assertTrue(actualEltList.contains(Integer.valueOf(1)));
    assertTrue(actualEltList.contains(Integer.valueOf(2)));
    assertTrue(actualEltList.contains(Integer.valueOf(3)));
    final List<Integer> expectedEltList = new ArrayList<Integer>();
    expectedEltList.add(Integer.valueOf(1));
    expectedEltList.add(Integer.valueOf(2));
    expectedEltList.add(Integer.valueOf(3));
    assertTrue(actualEltList.containsAll(expectedEltList));

    // validate keys.
    final List<String> actualKeyList = EnumerationUtils.toList(expected.keys());
    assertEquals(expected.size(), actualEltList.size());
    assertTrue(actualKeyList.contains("one"));
    assertTrue(actualKeyList.contains("two"));
    assertTrue(actualKeyList.contains("three"));
    final List<String> expectedKeyList = new ArrayList<String>();
    expectedKeyList.add("one");
    expectedKeyList.add("two");
    expectedKeyList.add("three");
    assertTrue(actualKeyList.containsAll(expectedKeyList));
  }
Exemplo n.º 2
0
  @Test
  public void getFromEnumeration() throws Exception {
    // Enumeration, entry exists
    final Vector<String> vector = new Vector<String>();
    vector.addElement("zero");
    vector.addElement("one");
    Enumeration<String> en = vector.elements();
    assertEquals("zero", EnumerationUtils.get(en, 0));
    en = vector.elements();
    assertEquals("one", EnumerationUtils.get(en, 1));

    // Enumerator, non-existent entry
    try {
      EnumerationUtils.get(en, 3);
      fail("Expecting IndexOutOfBoundsException.");
    } catch (final IndexOutOfBoundsException e) {
      // expected
    }
    assertTrue(!en.hasMoreElements());
  }
Exemplo n.º 3
0
 @Test
 public void testToListWithStringTokenizer() {
   final List<String> expectedList1 = new ArrayList<String>();
   final StringTokenizer st = new StringTokenizer(TO_LIST_FIXTURE);
   while (st.hasMoreTokens()) {
     expectedList1.add(st.nextToken());
   }
   final List<String> expectedList2 = new ArrayList<String>();
   expectedList2.add("this");
   expectedList2.add("is");
   expectedList2.add("a");
   expectedList2.add("test");
   final List<String> actualList = EnumerationUtils.toList(new StringTokenizer(TO_LIST_FIXTURE));
   assertEquals(expectedList1, expectedList2);
   assertEquals(expectedList1, actualList);
   assertEquals(expectedList2, actualList);
 }