< prev index next >

test/java/util/Objects/CheckIndex.java

Print this page
rev 14354 : 8155794: Move Objects.checkIndex BiFunction accepting methods to an internal package
Reviewed-by:

*** 1,7 **** /* ! * Copyright (c) 2015, 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) 2015, 2016 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.
*** 21,35 **** * questions. */ /** * @test ! * @summary IndexOutOfBoundsException check index tests * @run testng CheckIndex ! * @bug 8135248 8142493 */ import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import java.util.ArrayList; import java.util.List; --- 21,37 ---- * questions. */ /** * @test ! * @summary Objects.checkIndex/jdk.internal.util.Preconditions.checkIndex tests * @run testng CheckIndex ! * @bug 8135248 8142493 8155794 ! * @modules java.base/jdk.internal.util */ + import jdk.internal.util.Preconditions; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import java.util.ArrayList; import java.util.List;
*** 93,103 **** @Test(dataProvider = "checkIndexProvider") public void testCheckIndex(int index, int length, boolean withinBounds) { String expectedMessage = withinBounds ? null ! : Objects.outOfBoundsExceptionFormatter(IndexOutOfBoundsException::new). apply("checkIndex", List.of(index, length)).getMessage(); BiConsumer<Class<? extends RuntimeException>, IntSupplier> checker = (ec, s) -> { try { int rIndex = s.getAsInt(); --- 95,105 ---- @Test(dataProvider = "checkIndexProvider") public void testCheckIndex(int index, int length, boolean withinBounds) { String expectedMessage = withinBounds ? null ! : Preconditions.outOfBoundsExceptionFormatter(IndexOutOfBoundsException::new). apply("checkIndex", List.of(index, length)).getMessage(); BiConsumer<Class<? extends RuntimeException>, IntSupplier> checker = (ec, s) -> { try { int rIndex = s.getAsInt();
*** 115,139 **** assertEquals(e.getMessage(), expectedMessage); } }; checker.accept(AssertingOutOfBoundsException.class, ! () -> Objects.checkIndex(index, length, assertingOutOfBounds(expectedMessage, "checkIndex", index, length))); checker.accept(IndexOutOfBoundsException.class, ! () -> Objects.checkIndex(index, length, assertingOutOfBoundsReturnNull("checkIndex", index, length))); checker.accept(IndexOutOfBoundsException.class, ! () -> Objects.checkIndex(index, length, null)); checker.accept(IndexOutOfBoundsException.class, () -> Objects.checkIndex(index, length)); checker.accept(ArrayIndexOutOfBoundsException.class, ! () -> Objects.checkIndex(index, length, ! Objects.outOfBoundsExceptionFormatter(ArrayIndexOutOfBoundsException::new))); checker.accept(StringIndexOutOfBoundsException.class, ! () -> Objects.checkIndex(index, length, ! Objects.outOfBoundsExceptionFormatter(StringIndexOutOfBoundsException::new))); } @DataProvider static Object[][] checkFromToIndexProvider() { --- 117,141 ---- assertEquals(e.getMessage(), expectedMessage); } }; checker.accept(AssertingOutOfBoundsException.class, ! () -> Preconditions.checkIndex(index, length, assertingOutOfBounds(expectedMessage, "checkIndex", index, length))); checker.accept(IndexOutOfBoundsException.class, ! () -> Preconditions.checkIndex(index, length, assertingOutOfBoundsReturnNull("checkIndex", index, length))); checker.accept(IndexOutOfBoundsException.class, ! () -> Preconditions.checkIndex(index, length, null)); checker.accept(IndexOutOfBoundsException.class, () -> Objects.checkIndex(index, length)); checker.accept(ArrayIndexOutOfBoundsException.class, ! () -> Preconditions.checkIndex(index, length, ! Preconditions.outOfBoundsExceptionFormatter(ArrayIndexOutOfBoundsException::new))); checker.accept(StringIndexOutOfBoundsException.class, ! () -> Preconditions.checkIndex(index, length, ! Preconditions.outOfBoundsExceptionFormatter(StringIndexOutOfBoundsException::new))); } @DataProvider static Object[][] checkFromToIndexProvider() {
*** 155,165 **** @Test(dataProvider = "checkFromToIndexProvider") public void testCheckFromToIndex(int fromIndex, int toIndex, int length, boolean withinBounds) { String expectedMessage = withinBounds ? null ! : Objects.outOfBoundsExceptionFormatter(IndexOutOfBoundsException::new). apply("checkFromToIndex", List.of(fromIndex, toIndex, length)).getMessage(); BiConsumer<Class<? extends RuntimeException>, IntSupplier> check = (ec, s) -> { try { int rIndex = s.getAsInt(); --- 157,167 ---- @Test(dataProvider = "checkFromToIndexProvider") public void testCheckFromToIndex(int fromIndex, int toIndex, int length, boolean withinBounds) { String expectedMessage = withinBounds ? null ! : Preconditions.outOfBoundsExceptionFormatter(IndexOutOfBoundsException::new). apply("checkFromToIndex", List.of(fromIndex, toIndex, length)).getMessage(); BiConsumer<Class<? extends RuntimeException>, IntSupplier> check = (ec, s) -> { try { int rIndex = s.getAsInt();
*** 177,201 **** assertEquals(e.getMessage(), expectedMessage); } }; check.accept(AssertingOutOfBoundsException.class, ! () -> Objects.checkFromToIndex(fromIndex, toIndex, length, assertingOutOfBounds(expectedMessage, "checkFromToIndex", fromIndex, toIndex, length))); check.accept(IndexOutOfBoundsException.class, ! () -> Objects.checkFromToIndex(fromIndex, toIndex, length, assertingOutOfBoundsReturnNull("checkFromToIndex", fromIndex, toIndex, length))); check.accept(IndexOutOfBoundsException.class, ! () -> Objects.checkFromToIndex(fromIndex, toIndex, length, null)); check.accept(IndexOutOfBoundsException.class, () -> Objects.checkFromToIndex(fromIndex, toIndex, length)); check.accept(ArrayIndexOutOfBoundsException.class, ! () -> Objects.checkFromToIndex(fromIndex, toIndex, length, ! Objects.outOfBoundsExceptionFormatter(ArrayIndexOutOfBoundsException::new))); check.accept(StringIndexOutOfBoundsException.class, ! () -> Objects.checkFromToIndex(fromIndex, toIndex, length, ! Objects.outOfBoundsExceptionFormatter(StringIndexOutOfBoundsException::new))); } @DataProvider static Object[][] checkFromIndexSizeProvider() { --- 179,203 ---- assertEquals(e.getMessage(), expectedMessage); } }; check.accept(AssertingOutOfBoundsException.class, ! () -> Preconditions.checkFromToIndex(fromIndex, toIndex, length, assertingOutOfBounds(expectedMessage, "checkFromToIndex", fromIndex, toIndex, length))); check.accept(IndexOutOfBoundsException.class, ! () -> Preconditions.checkFromToIndex(fromIndex, toIndex, length, assertingOutOfBoundsReturnNull("checkFromToIndex", fromIndex, toIndex, length))); check.accept(IndexOutOfBoundsException.class, ! () -> Preconditions.checkFromToIndex(fromIndex, toIndex, length, null)); check.accept(IndexOutOfBoundsException.class, () -> Objects.checkFromToIndex(fromIndex, toIndex, length)); check.accept(ArrayIndexOutOfBoundsException.class, ! () -> Preconditions.checkFromToIndex(fromIndex, toIndex, length, ! Preconditions.outOfBoundsExceptionFormatter(ArrayIndexOutOfBoundsException::new))); check.accept(StringIndexOutOfBoundsException.class, ! () -> Preconditions.checkFromToIndex(fromIndex, toIndex, length, ! Preconditions.outOfBoundsExceptionFormatter(StringIndexOutOfBoundsException::new))); } @DataProvider static Object[][] checkFromIndexSizeProvider() {
*** 224,234 **** @Test(dataProvider = "checkFromIndexSizeProvider") public void testCheckFromIndexSize(int fromIndex, int size, int length, boolean withinBounds) { String expectedMessage = withinBounds ? null ! : Objects.outOfBoundsExceptionFormatter(IndexOutOfBoundsException::new). apply("checkFromIndexSize", List.of(fromIndex, size, length)).getMessage(); BiConsumer<Class<? extends RuntimeException>, IntSupplier> check = (ec, s) -> { try { int rIndex = s.getAsInt(); --- 226,236 ---- @Test(dataProvider = "checkFromIndexSizeProvider") public void testCheckFromIndexSize(int fromIndex, int size, int length, boolean withinBounds) { String expectedMessage = withinBounds ? null ! : Preconditions.outOfBoundsExceptionFormatter(IndexOutOfBoundsException::new). apply("checkFromIndexSize", List.of(fromIndex, size, length)).getMessage(); BiConsumer<Class<? extends RuntimeException>, IntSupplier> check = (ec, s) -> { try { int rIndex = s.getAsInt();
*** 246,276 **** assertEquals(e.getMessage(), expectedMessage); } }; check.accept(AssertingOutOfBoundsException.class, ! () -> Objects.checkFromIndexSize(fromIndex, size, length, assertingOutOfBounds(expectedMessage, "checkFromIndexSize", fromIndex, size, length))); check.accept(IndexOutOfBoundsException.class, ! () -> Objects.checkFromIndexSize(fromIndex, size, length, assertingOutOfBoundsReturnNull("checkFromIndexSize", fromIndex, size, length))); check.accept(IndexOutOfBoundsException.class, ! () -> Objects.checkFromIndexSize(fromIndex, size, length, null)); check.accept(IndexOutOfBoundsException.class, () -> Objects.checkFromIndexSize(fromIndex, size, length)); check.accept(ArrayIndexOutOfBoundsException.class, ! () -> Objects.checkFromIndexSize(fromIndex, size, length, ! Objects.outOfBoundsExceptionFormatter(ArrayIndexOutOfBoundsException::new))); check.accept(StringIndexOutOfBoundsException.class, ! () -> Objects.checkFromIndexSize(fromIndex, size, length, ! Objects.outOfBoundsExceptionFormatter(StringIndexOutOfBoundsException::new))); } @Test public void uniqueMessagesForCheckKinds() { BiFunction<String, List<Integer>, IndexOutOfBoundsException> f = ! Objects.outOfBoundsExceptionFormatter(IndexOutOfBoundsException::new); List<String> messages = new ArrayList<>(); // Exact arguments messages.add(f.apply("checkIndex", List.of(-1, 0)).getMessage()); messages.add(f.apply("checkFromToIndex", List.of(-1, 0, 0)).getMessage()); --- 248,278 ---- assertEquals(e.getMessage(), expectedMessage); } }; check.accept(AssertingOutOfBoundsException.class, ! () -> Preconditions.checkFromIndexSize(fromIndex, size, length, assertingOutOfBounds(expectedMessage, "checkFromIndexSize", fromIndex, size, length))); check.accept(IndexOutOfBoundsException.class, ! () -> Preconditions.checkFromIndexSize(fromIndex, size, length, assertingOutOfBoundsReturnNull("checkFromIndexSize", fromIndex, size, length))); check.accept(IndexOutOfBoundsException.class, ! () -> Preconditions.checkFromIndexSize(fromIndex, size, length, null)); check.accept(IndexOutOfBoundsException.class, () -> Objects.checkFromIndexSize(fromIndex, size, length)); check.accept(ArrayIndexOutOfBoundsException.class, ! () -> Preconditions.checkFromIndexSize(fromIndex, size, length, ! Preconditions.outOfBoundsExceptionFormatter(ArrayIndexOutOfBoundsException::new))); check.accept(StringIndexOutOfBoundsException.class, ! () -> Preconditions.checkFromIndexSize(fromIndex, size, length, ! Preconditions.outOfBoundsExceptionFormatter(StringIndexOutOfBoundsException::new))); } @Test public void uniqueMessagesForCheckKinds() { BiFunction<String, List<Integer>, IndexOutOfBoundsException> f = ! Preconditions.outOfBoundsExceptionFormatter(IndexOutOfBoundsException::new); List<String> messages = new ArrayList<>(); // Exact arguments messages.add(f.apply("checkIndex", List.of(-1, 0)).getMessage()); messages.add(f.apply("checkFromToIndex", List.of(-1, 0, 0)).getMessage());
< prev index next >