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";
@Test
public void testToListWithStringTokenizer() {
final List<String> expectedList1 = new ArrayList<>();
final StringTokenizer st = new StringTokenizer(TO_LIST_FIXTURE);
while (st.hasMoreTokens()) {
expectedList1.add(st.nextToken());
}
final List<String> expectedList2 = new ArrayList<>();
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);
public void getFromEnumeration() throws Exception {
// Enumeration, entry exists
final Vector<String> vector = new Vector<>();
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());
}
@Test
@ -87,24 +90,21 @@ public class EnumerationUtilsTest {
}
@Test
public void getFromEnumeration() throws Exception {
// Enumeration, entry exists
final Vector<String> vector = new Vector<>();
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());
public void testToListWithStringTokenizer() {
final List<String> expectedList1 = new ArrayList<>();
final StringTokenizer st = new StringTokenizer(TO_LIST_FIXTURE);
while (st.hasMoreTokens()) {
expectedList1.add(st.nextToken());
}
final List<String> expectedList2 = new ArrayList<>();
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);
}
}