Sort Sort methods.

This commit is contained in:
Gary Gregory 2020-01-12 10:25:21 -05:00
parent a963a123f7
commit 45eee00385

View File

@ -38,21 +38,24 @@ public class EnumerationUtilsTest {
public static final String TO_LIST_FIXTURE = "this is a test"; public static final String TO_LIST_FIXTURE = "this is a test";
@Test @Test
public void testToListWithStringTokenizer() { public void getFromEnumeration() throws Exception {
final List<String> expectedList1 = new ArrayList<>(); // Enumeration, entry exists
final StringTokenizer st = new StringTokenizer(TO_LIST_FIXTURE); final Vector<String> vector = new Vector<>();
while (st.hasMoreTokens()) { vector.addElement("zero");
expectedList1.add(st.nextToken()); vector.addElement("one");
} Enumeration<String> en = vector.elements();
final List<String> expectedList2 = new ArrayList<>(); assertEquals("zero", EnumerationUtils.get(en, 0));
expectedList2.add("this"); en = vector.elements();
expectedList2.add("is"); assertEquals("one", EnumerationUtils.get(en, 1));
expectedList2.add("a");
expectedList2.add("test"); // Enumerator, non-existent entry
final List<String> actualList = EnumerationUtils.toList(new StringTokenizer(TO_LIST_FIXTURE)); try {
assertEquals(expectedList1, expectedList2); EnumerationUtils.get(en, 3);
assertEquals(expectedList1, actualList); fail("Expecting IndexOutOfBoundsException.");
assertEquals(expectedList2, actualList); } catch (final IndexOutOfBoundsException e) {
// expected
}
assertTrue(!en.hasMoreElements());
} }
@Test @Test
@ -87,24 +90,21 @@ public class EnumerationUtilsTest {
} }
@Test @Test
public void getFromEnumeration() throws Exception { public void testToListWithStringTokenizer() {
// Enumeration, entry exists final List<String> expectedList1 = new ArrayList<>();
final Vector<String> vector = new Vector<>(); final StringTokenizer st = new StringTokenizer(TO_LIST_FIXTURE);
vector.addElement("zero"); while (st.hasMoreTokens()) {
vector.addElement("one"); expectedList1.add(st.nextToken());
Enumeration<String> en = vector.elements(); }
assertEquals("zero", EnumerationUtils.get(en, 0)); final List<String> expectedList2 = new ArrayList<>();
en = vector.elements(); expectedList2.add("this");
assertEquals("one", EnumerationUtils.get(en, 1)); expectedList2.add("is");
expectedList2.add("a");
// Enumerator, non-existent entry expectedList2.add("test");
try { final List<String> actualList = EnumerationUtils.toList(new StringTokenizer(TO_LIST_FIXTURE));
EnumerationUtils.get(en, 3); assertEquals(expectedList1, expectedList2);
fail("Expecting IndexOutOfBoundsException."); assertEquals(expectedList1, actualList);
} catch (final IndexOutOfBoundsException e) { assertEquals(expectedList2, actualList);
// expected
}
assertTrue(!en.hasMoreElements());
} }
} }