forked from I2P_Developers/i2p.i2p
more appropriate junit test
This commit is contained in:
@ -10,33 +10,43 @@ import org.junit.Test;
|
|||||||
|
|
||||||
public class CachedIteratorArrayListTest {
|
public class CachedIteratorArrayListTest {
|
||||||
|
|
||||||
private List<Integer> l;
|
private List<Character> l;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
l = new CachedIteratorArrayList<Integer>();
|
l = new CachedIteratorArrayList<Character>();
|
||||||
l.add(1);
|
l.add('a');
|
||||||
l.add(2);
|
l.add('b');
|
||||||
l.add(3);
|
l.add('c');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** test iterations work */
|
||||||
@Test
|
@Test
|
||||||
public void test() {
|
public void test() {
|
||||||
// test for-each worx
|
String total = "";
|
||||||
int total = 0;
|
|
||||||
for (int i : l)
|
|
||||||
total += i;
|
|
||||||
assertEquals(6, total);
|
|
||||||
for (int i : l)
|
|
||||||
total += i;
|
|
||||||
assertEquals(12, total);
|
|
||||||
|
|
||||||
|
// two full for-each iterations
|
||||||
|
for (char i : l)
|
||||||
|
total += i;
|
||||||
|
assertEquals("abc", total);
|
||||||
|
for (char i : l)
|
||||||
|
total += i;
|
||||||
|
assertEquals("abcabc", total);
|
||||||
|
|
||||||
|
// and one partial
|
||||||
|
total = "";
|
||||||
|
Iterator<Character> iter = l.iterator();
|
||||||
|
total += iter.next();
|
||||||
|
total += iter.next();
|
||||||
|
iter = l.iterator();
|
||||||
|
total += iter.next();
|
||||||
|
assertEquals("aba",total);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSameness() {
|
public void testSameness() {
|
||||||
Iterator<Integer> two = l.iterator();
|
Iterator<Character> two = l.iterator();
|
||||||
Iterator<Integer> one = l.iterator();
|
Iterator<Character> one = l.iterator();
|
||||||
assertSame(one, two);
|
assertSame(one, two);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user