| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.google.common.collect.testing; |
| 18 |
|
| 19 |
import com.google.common.annotations.GwtCompatible; |
| 20 |
import java.util.Collections; |
| 21 |
import java.util.Iterator; |
| 22 |
import java.util.NoSuchElementException; |
| 23 |
import junit.framework.TestCase; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
@GwtCompatible |
| 31 |
public class MinimalIterableTest extends TestCase { |
| 32 |
|
| 33 |
public void testOf_empty() { |
| 34 |
Iterable<String> iterable = MinimalIterable.<String>of(); |
| 35 |
Iterator<String> iterator = iterable.iterator(); |
| 36 |
assertFalse(iterator.hasNext()); |
| 37 |
try { |
| 38 |
iterator.next(); |
| 39 |
fail(); |
| 40 |
} catch (NoSuchElementException expected) { |
| 41 |
} |
| 42 |
try { |
| 43 |
iterable.iterator(); |
| 44 |
fail(); |
| 45 |
} catch (IllegalStateException expected) { |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
public void testOf_one() { |
| 50 |
Iterable<String> iterable = MinimalIterable.of("a"); |
| 51 |
Iterator<String> iterator = iterable.iterator(); |
| 52 |
assertTrue(iterator.hasNext()); |
| 53 |
assertEquals("a", iterator.next()); |
| 54 |
assertFalse(iterator.hasNext()); |
| 55 |
try { |
| 56 |
iterator.next(); |
| 57 |
fail(); |
| 58 |
} catch (NoSuchElementException expected) { |
| 59 |
} |
| 60 |
try { |
| 61 |
iterable.iterator(); |
| 62 |
fail(); |
| 63 |
} catch (IllegalStateException expected) { |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
public void testFrom_empty() { |
| 68 |
Iterable<String> iterable = MinimalIterable.from(Collections.<String>emptySet()); |
| 69 |
Iterator<String> iterator = iterable.iterator(); |
| 70 |
assertFalse(iterator.hasNext()); |
| 71 |
try { |
| 72 |
iterator.next(); |
| 73 |
fail(); |
| 74 |
} catch (NoSuchElementException expected) { |
| 75 |
} |
| 76 |
try { |
| 77 |
iterable.iterator(); |
| 78 |
fail(); |
| 79 |
} catch (IllegalStateException expected) { |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
public void testFrom_one() { |
| 84 |
Iterable<String> iterable = MinimalIterable.from(Collections.singleton("a")); |
| 85 |
Iterator<String> iterator = iterable.iterator(); |
| 86 |
assertTrue(iterator.hasNext()); |
| 87 |
assertEquals("a", iterator.next()); |
| 88 |
try { |
| 89 |
iterator.remove(); |
| 90 |
fail(); |
| 91 |
} catch (UnsupportedOperationException expected) { |
| 92 |
} |
| 93 |
assertFalse(iterator.hasNext()); |
| 94 |
try { |
| 95 |
iterator.next(); |
| 96 |
fail(); |
| 97 |
} catch (NoSuchElementException expected) { |
| 98 |
} |
| 99 |
try { |
| 100 |
iterable.iterator(); |
| 101 |
fail(); |
| 102 |
} catch (IllegalStateException expected) { |
| 103 |
} |
| 104 |
} |
| 105 |
} |