| 64 | } |
| 65 | |
| 66 | private static void testIterators() { |
| 67 | EnumSet<SmallEnum> set = EnumSet.allOf(SmallEnum.class); |
| 68 | Iterator<SmallEnum> iterator = set.iterator(); |
| 69 | boolean exceptionCaught = false; |
| 70 | try { |
| 71 | iterator.remove(); |
| 72 | } catch (IllegalStateException e) { |
| 73 | exceptionCaught = true; |
| 74 | } |
| 75 | if (!exceptionCaught) { |
| 76 | throw new RuntimeException("Calling remove() before next() should throw IllegalStateException"); |
| 77 | } |
| 78 | |
| 79 | while (iterator.hasNext()) { |
| 80 | iterator.next(); |
| 81 | iterator.remove(); |
| 82 | } |
| 83 | assertSize(0, set); |
| 84 | |
| 85 | exceptionCaught = false; |
| 86 | try { |
| 87 | iterator.next(); |
| 88 | } catch (NoSuchElementException e) { |
| 89 | exceptionCaught = true; |
| 90 | } |
| 91 | if (!exceptionCaught) { |
| 92 | throw new RuntimeException("Calling next() when hasNext() == false should throw NoSuchElementException"); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | private static void assertElementInSet(Enum<?> element, EnumSet<?> set) { |
| 97 | if (!set.contains(element)) { |