--- jsr166/src/test/tck/AbstractQueueTest.java 2004/01/10 20:37:20 1.1 +++ jsr166/src/test/tck/AbstractQueueTest.java 2017/05/29 22:44:26 1.15 @@ -1,30 +1,31 @@ /* * Written by Doug Lea with assistance from members of JCP JSR-166 * Expert Group and released to the public domain, as explained at - * http://creativecommons.org/licenses/publicdomain - * Other contributors include Andrew Wright, Jeffrey Hayes, - * Pat Fisher, Mike Judd. + * http://creativecommons.org/publicdomain/zero/1.0/ + * Other contributors include Andrew Wright, Jeffrey Hayes, + * Pat Fisher, Mike Judd. */ +import java.util.AbstractQueue; +import java.util.Arrays; +import java.util.Iterator; +import java.util.NoSuchElementException; -import junit.framework.*; -import java.util.*; -import java.util.concurrent.*; -import java.util.concurrent.locks.*; -import java.io.*; +import junit.framework.Test; +import junit.framework.TestSuite; public class AbstractQueueTest extends JSR166TestCase { public static void main(String[] args) { - junit.textui.TestRunner.run (suite()); + main(suite(), args); } public static Test suite() { return new TestSuite(AbstractQueueTest.class); } static class Succeed extends AbstractQueue { - public boolean offer(Integer x) { + public boolean offer(Integer x) { if (x == null) throw new NullPointerException(); - return true; + return true; } public Integer peek() { return one; } public Integer poll() { return one; } @@ -33,9 +34,9 @@ public class AbstractQueueTest extends J } static class Fail extends AbstractQueue { - public boolean offer(Integer x) { + public boolean offer(Integer x) { if (x == null) throw new NullPointerException(); - return false; + return false; } public Integer peek() { return null; } public Integer poll() { return null; } @@ -52,27 +53,25 @@ public class AbstractQueueTest extends J } /** - * add throws ISE true if offer fails + * add throws IllegalStateException true if offer fails */ public void testAddF() { Fail q = new Fail(); try { q.add(one); shouldThrow(); - } catch (IllegalStateException success) { - } + } catch (IllegalStateException success) {} } /** - * add throws NPE if offer does + * add throws NullPointerException if offer does */ public void testAddNPE() { Succeed q = new Succeed(); try { q.add(null); shouldThrow(); - } catch (NullPointerException success) { - } + } catch (NullPointerException success) {} } /** @@ -91,11 +90,9 @@ public class AbstractQueueTest extends J try { q.remove(); shouldThrow(); - } catch (NoSuchElementException success) { - } + } catch (NoSuchElementException success) {} } - /** * element returns normally if peek succeeds */ @@ -112,75 +109,70 @@ public class AbstractQueueTest extends J try { q.element(); shouldThrow(); - } catch (NoSuchElementException success) { - } + } catch (NoSuchElementException success) {} } /** - * addAll(null) throws NPE + * addAll(null) throws NullPointerException */ public void testAddAll1() { + Succeed q = new Succeed(); try { - Succeed q = new Succeed(); q.addAll(null); shouldThrow(); - } - catch (NullPointerException success) {} + } catch (NullPointerException success) {} } /** - * addAll(this) throws IAE + * addAll(this) throws IllegalArgumentException */ public void testAddAllSelf() { + Succeed q = new Succeed(); try { - Succeed q = new Succeed(); q.addAll(q); shouldThrow(); - } - catch (IllegalArgumentException success) {} + } catch (IllegalArgumentException success) {} } - /** - * addAll of a collection with null elements throws NPE + * addAll of a collection with null elements throws NullPointerException */ public void testAddAll2() { + Succeed q = new Succeed(); + Integer[] ints = new Integer[SIZE]; try { - Succeed q = new Succeed(); - Integer[] ints = new Integer[SIZE]; q.addAll(Arrays.asList(ints)); shouldThrow(); - } - catch (NullPointerException success) {} + } catch (NullPointerException success) {} } + /** * addAll of a collection with any null elements throws NPE after * possibly adding some elements */ public void testAddAll3() { + Succeed q = new Succeed(); + Integer[] ints = new Integer[SIZE]; + for (int i = 0; i < SIZE - 1; ++i) + ints[i] = new Integer(i); try { - Succeed q = new Succeed(); - Integer[] ints = new Integer[SIZE]; - for (int i = 0; i < SIZE-1; ++i) - ints[i] = new Integer(i); q.addAll(Arrays.asList(ints)); shouldThrow(); - } - catch (NullPointerException success) {} + } catch (NullPointerException success) {} } + /** - * addAll throws ISE if an add fails + * addAll throws IllegalStateException if an add fails */ public void testAddAll4() { + Fail q = new Fail(); + Integer[] ints = new Integer[SIZE]; + for (int i = 0; i < SIZE; ++i) + ints[i] = new Integer(i); try { - Fail q = new Fail(); - Integer[] ints = new Integer[SIZE]; - for (int i = 0; i < SIZE; ++i) - ints[i] = new Integer(i); q.addAll(Arrays.asList(ints)); shouldThrow(); - } - catch (IllegalStateException success) {} + } catch (IllegalStateException success) {} } }