--- old/test/java/util/Arrays/ParallelPrefix.java 2017-05-02 14:20:08.000000000 +0800 +++ new/test/java/util/Arrays/ParallelPrefix.java 2017-05-02 14:20:05.000000000 +0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2017, 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 @@ -179,119 +179,65 @@ @Test public void testNPEs() { // null array - assertThrows( () -> Arrays.parallelPrefix((int[]) null, Integer::max), - NullPointerException.class, "should throw NPE"); - assertThrows( () -> Arrays.parallelPrefix((long []) null, Long::max), - NullPointerException.class, "should throw NPE"); - assertThrows( () -> Arrays.parallelPrefix((double []) null, Double::max), - NullPointerException.class, "should throw NPE"); - assertThrows( () -> Arrays.parallelPrefix((String []) null, String::concat), - NullPointerException.class, "should throw NPE"); + assertThrowsNPE(() -> Arrays.parallelPrefix((int[]) null, Integer::max)); + assertThrowsNPE(() -> Arrays.parallelPrefix((long []) null, Long::max)); + assertThrowsNPE(() -> Arrays.parallelPrefix((double []) null, Double::max)); + assertThrowsNPE(() -> Arrays.parallelPrefix((String []) null, String::concat)); // null array w/ range - assertThrows( () -> Arrays.parallelPrefix((int[]) null, 0, 0, Integer::max), - NullPointerException.class, "should throw NPE"); - assertThrows( () -> Arrays.parallelPrefix((long []) null, 0, 0, Long::max), - NullPointerException.class, "should throw NPE"); - assertThrows( () -> Arrays.parallelPrefix((double []) null, 0, 0, Double::max), - NullPointerException.class, "should throw NPE"); - assertThrows( () -> Arrays.parallelPrefix((String []) null, 0, 0, String::concat), - NullPointerException.class, "should throw NPE"); + assertThrowsNPE(() -> Arrays.parallelPrefix((int[]) null, 0, 0, Integer::max)); + assertThrowsNPE(() -> Arrays.parallelPrefix((long []) null, 0, 0, Long::max)); + assertThrowsNPE(() -> Arrays.parallelPrefix((double []) null, 0, 0, Double::max)); + assertThrowsNPE(() -> Arrays.parallelPrefix((String []) null, 0, 0, String::concat)); // null op - assertThrows( () -> Arrays.parallelPrefix(new int[] {}, null), - NullPointerException.class, "should throw NPE"); - assertThrows( () -> Arrays.parallelPrefix(new long[] {}, null), - NullPointerException.class, "should throw NPE"); - assertThrows( () -> Arrays.parallelPrefix(new double[] {}, null), - NullPointerException.class, "should throw NPE"); - assertThrows( () -> Arrays.parallelPrefix(new String[] {}, null), - NullPointerException.class, "should throw NPE"); + assertThrowsNPE(() -> Arrays.parallelPrefix(new int[] {}, null)); + assertThrowsNPE(() -> Arrays.parallelPrefix(new long[] {}, null)); + assertThrowsNPE(() -> Arrays.parallelPrefix(new double[] {}, null)); + assertThrowsNPE(() -> Arrays.parallelPrefix(new String[] {}, null)); // null op w/ range - assertThrows( () -> Arrays.parallelPrefix(new int[] {}, 0, 0, null), - NullPointerException.class, "should throw NPE"); - assertThrows( () -> Arrays.parallelPrefix(new long[] {}, 0, 0, null), - NullPointerException.class, "should throw NPE"); - assertThrows( () -> Arrays.parallelPrefix(new double[] {}, 0, 0, null), - NullPointerException.class, "should throw NPE"); - assertThrows( () -> Arrays.parallelPrefix(new String[] {}, 0, 0, null), - NullPointerException.class, "should throw NPE"); + assertThrowsNPE(() -> Arrays.parallelPrefix(new int[] {}, 0, 0, null)); + assertThrowsNPE(() -> Arrays.parallelPrefix(new long[] {}, 0, 0, null)); + assertThrowsNPE(() -> Arrays.parallelPrefix(new double[] {}, 0, 0, null)); + assertThrowsNPE(() -> Arrays.parallelPrefix(new String[] {}, 0, 0, null)); } @Test public void testIAEs() { - assertThrows( () -> Arrays.parallelPrefix(new int[] {}, 1, 0, Integer::max), - IllegalArgumentException.class, "should throw IAE"); - assertThrows( () -> Arrays.parallelPrefix(new long[] {}, 1, 0, Long::max), - IllegalArgumentException.class, "should throw IAE"); - assertThrows( () -> Arrays.parallelPrefix(new double[] {}, 1, 0, Double::max), - IllegalArgumentException.class, "should throw IAE"); - assertThrows( () -> Arrays.parallelPrefix(new String[] {}, 1, 0, String::concat), - IllegalArgumentException.class, "should throw IAE"); + assertThrowsIAE(() -> Arrays.parallelPrefix(new int[] {}, 1, 0, Integer::max)); + assertThrowsIAE(() -> Arrays.parallelPrefix(new long[] {}, 1, 0, Long::max)); + assertThrowsIAE(() -> Arrays.parallelPrefix(new double[] {}, 1, 0, Double::max)); + assertThrowsIAE(() -> Arrays.parallelPrefix(new String[] {}, 1, 0, String::concat)); } @Test - public void testAIOBEs() { + public void testAIOOBEs() { // bad "fromIndex" - assertThrows( () -> Arrays.parallelPrefix(new int[] {}, -1, 0, Integer::max), - ArrayIndexOutOfBoundsException.class, "should throw AIOBE"); - assertThrows( () -> Arrays.parallelPrefix(new long[] {}, -1, 0, Long::max), - ArrayIndexOutOfBoundsException.class, "should throw AIOBE"); - assertThrows( () -> Arrays.parallelPrefix(new double[] {}, -1, 0, Double::max), - ArrayIndexOutOfBoundsException.class, "should throw AIOBE"); - assertThrows( () -> Arrays.parallelPrefix(new String[] {}, -1, 0, String::concat), - ArrayIndexOutOfBoundsException.class, "should throw AIOBE"); + assertThrowsAIOOB(() -> Arrays.parallelPrefix(new int[] {}, -1, 0, Integer::max)); + assertThrowsAIOOB(() -> Arrays.parallelPrefix(new long[] {}, -1, 0, Long::max)); + assertThrowsAIOOB(() -> Arrays.parallelPrefix(new double[] {}, -1, 0, Double::max)); + assertThrowsAIOOB(() -> Arrays.parallelPrefix(new String[] {}, -1, 0, String::concat)); // bad "toIndex" - assertThrows( () -> Arrays.parallelPrefix(new int[] {}, 0, 1, Integer::max), - ArrayIndexOutOfBoundsException.class, "should throw AIOBE"); - assertThrows( () -> Arrays.parallelPrefix(new long[] {}, 0, 1, Long::max), - ArrayIndexOutOfBoundsException.class, "should throw AIOBE"); - assertThrows( () -> Arrays.parallelPrefix(new double[] {}, 0, 1, Double::max), - ArrayIndexOutOfBoundsException.class, "should throw AIOBE"); - assertThrows( () -> Arrays.parallelPrefix(new String[] {}, 0, 1, String::concat), - ArrayIndexOutOfBoundsException.class, "should throw AIOBE"); + assertThrowsAIOOB(() -> Arrays.parallelPrefix(new int[] {}, 0, 1, Integer::max)); + assertThrowsAIOOB(() -> Arrays.parallelPrefix(new long[] {}, 0, 1, Long::max)); + assertThrowsAIOOB(() -> Arrays.parallelPrefix(new double[] {}, 0, 1, Double::max)); + assertThrowsAIOOB(() -> Arrays.parallelPrefix(new String[] {}, 0, 1, String::concat)); } // "library" code - - public interface Thrower { - - public void run() throws T; - } - - - public static void assertThrows(Thrower thrower, Class throwable) { - assertThrows(thrower, throwable, null); - } - - public static void assertThrows(Thrower thrower, Class throwable, String message) { - Throwable thrown; - try { - thrower.run(); - thrown = null; - } catch (Throwable caught) { - thrown = caught; - } - - assertInstance(thrown, throwable, - ((null != message) ? message : "") + - " Failed to throw " + throwable.getCanonicalName()); - } - - public static void assertThrows(Class throwable, String message, Thrower... throwers) { - for(Thrower thrower : throwers) { - assertThrows(thrower, throwable, message); - } + + private void assertThrowsNPE(ThrowingRunnable r) { + assertThrows(NullPointerException.class, r); } - public static void assertInstance(Object actual, Class expected) { - assertInstance(expected.isInstance(actual), null); + private void assertThrowsIAE(ThrowingRunnable r) { + assertThrows(IllegalArgumentException.class, r); } - public static void assertInstance(Object actual, Class expected, String message) { - assertTrue(expected.isInstance(actual), message); + private void assertThrowsAIOOB(ThrowingRunnable r) { + assertThrows(ArrayIndexOutOfBoundsException.class, r); } static void assertArraysEqual(int[] actual, int[] expected) {