test/java/util/Collection/IteratorAtEnd.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. --- 1,7 ---- /* ! * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation.
*** 82,119 **** static void test(Collection c) { try { final Iterator it = c.iterator(); THROWS(NoSuchElementException.class, ! new Fun() {void f() { while (true) it.next(); }}); try { it.remove(); } ! catch (UnsupportedOperationException _) { return; } pass(); } catch (Throwable t) { unexpected(t); } if (c instanceof List) { final List list = (List) c; try { final ListIterator it = list.listIterator(0); it.next(); final Object x = it.previous(); ! THROWS(NoSuchElementException.class, ! new Fun() {void f() { it.previous(); }}); try { it.remove(); } ! catch (UnsupportedOperationException _) { return; } pass(); check(! list.get(0).equals(x)); } catch (Throwable t) { unexpected(t); } try { final ListIterator it = list.listIterator(list.size()); it.previous(); final Object x = it.next(); ! THROWS(NoSuchElementException.class, ! new Fun() {void f() { it.next(); }}); try { it.remove(); } ! catch (UnsupportedOperationException _) { return; } pass(); check(! list.get(list.size()-1).equals(x)); } catch (Throwable t) { unexpected(t); } } } --- 82,117 ---- static void test(Collection c) { try { final Iterator it = c.iterator(); THROWS(NoSuchElementException.class, ! () -> { while (true) it.next(); }); try { it.remove(); } ! catch (UnsupportedOperationException exc) { return; } pass(); } catch (Throwable t) { unexpected(t); } if (c instanceof List) { final List list = (List) c; try { final ListIterator it = list.listIterator(0); it.next(); final Object x = it.previous(); ! THROWS(NoSuchElementException.class, () -> it.previous()); try { it.remove(); } ! catch (UnsupportedOperationException exc) { return; } pass(); check(! list.get(0).equals(x)); } catch (Throwable t) { unexpected(t); } try { final ListIterator it = list.listIterator(list.size()); it.previous(); final Object x = it.next(); ! THROWS(NoSuchElementException.class, () -> it.next()); try { it.remove(); } ! catch (UnsupportedOperationException exc) { return; } pass(); check(! list.get(list.size()-1).equals(x)); } catch (Throwable t) { unexpected(t); } } }
*** 130,140 **** else fail(x + " not equal to " + y);} public static void main(String[] args) throws Throwable { try {realMain(args);} catch (Throwable t) {unexpected(t);} System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); if (failed > 0) throw new AssertionError("Some tests failed");} ! private static abstract class Fun {abstract void f() throws Throwable;} static void THROWS(Class<? extends Throwable> k, Fun... fs) { for (Fun f : fs) try { f.f(); fail("Expected " + k.getName() + " not thrown"); } catch (Throwable t) { if (k.isAssignableFrom(t.getClass())) pass(); --- 128,138 ---- else fail(x + " not equal to " + y);} public static void main(String[] args) throws Throwable { try {realMain(args);} catch (Throwable t) {unexpected(t);} System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); if (failed > 0) throw new AssertionError("Some tests failed");} ! @FunctionalInterface interface Fun {void f() throws Throwable;} static void THROWS(Class<? extends Throwable> k, Fun... fs) { for (Fun f : fs) try { f.f(); fail("Expected " + k.getName() + " not thrown"); } catch (Throwable t) { if (k.isAssignableFrom(t.getClass())) pass();