oop/test/uebung/uebung09/iterator/Array2dIteratorTest.java
2024-06-13 15:37:45 +02:00

44 lines
1.3 KiB
Java

package iterator;
import org.junit.Test;
import java.util.Iterator;
import java.util.NoSuchElementException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
public class Array2dIteratorTest {
@Test
public void testArray2dIterator() {
final String[][] array = {{}, {"foo", "bar"}, {"baz"}, {}};
final Iterator<String> it = new Array2dIterator<>(array);
assertTrue(it.hasNext());
assertEquals("foo", it.next());
assertTrue(it.hasNext());
assertEquals("bar", it.next());
assertTrue(it.hasNext());
assertEquals("baz", it.next());
assertFalse(it.hasNext());
assertThrows(NoSuchElementException.class, it::next);
}
@Test
public void testArray2dIteratorOnlyEmpty() {
final String[][] array = {{}, {}, {}};
final Iterator<String> it = new Array2dIterator<>(array);
assertFalse(it.hasNext());
assertThrows(NoSuchElementException.class, it::next);
}
@Test
public void testArray2dIteratorEmpty() {
final String[][] array = {};
final Iterator<String> it = new Array2dIterator<>(array);
assertFalse(it.hasNext());
assertThrows(NoSuchElementException.class, it::next);
}
}