< 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 +1,7 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * 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,15 +21,17 @@
  * questions.
  */
 
 /**
  * @test
- * @summary IndexOutOfBoundsException check index tests
+ * @summary Objects.checkIndex/jdk.internal.util.Preconditions.checkIndex tests
  * @run testng CheckIndex
- * @bug 8135248 8142493
+ * @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,11 +95,11 @@
 
     @Test(dataProvider = "checkIndexProvider")
     public void testCheckIndex(int index, int length, boolean withinBounds) {
         String expectedMessage = withinBounds
                                  ? null
-                                 : Objects.outOfBoundsExceptionFormatter(IndexOutOfBoundsException::new).
+                                 : 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,25 +117,25 @@
                     assertEquals(e.getMessage(), expectedMessage);
             }
         };
 
         checker.accept(AssertingOutOfBoundsException.class,
-                     () -> Objects.checkIndex(index, length,
+                     () -> Preconditions.checkIndex(index, length,
                                               assertingOutOfBounds(expectedMessage, "checkIndex", index, length)));
         checker.accept(IndexOutOfBoundsException.class,
-                     () -> Objects.checkIndex(index, length,
+                     () -> Preconditions.checkIndex(index, length,
                                               assertingOutOfBoundsReturnNull("checkIndex", index, length)));
         checker.accept(IndexOutOfBoundsException.class,
-                     () -> Objects.checkIndex(index, length, null));
+                     () -> Preconditions.checkIndex(index, length, null));
         checker.accept(IndexOutOfBoundsException.class,
                      () -> Objects.checkIndex(index, length));
         checker.accept(ArrayIndexOutOfBoundsException.class,
-                     () -> Objects.checkIndex(index, length,
-                                              Objects.outOfBoundsExceptionFormatter(ArrayIndexOutOfBoundsException::new)));
+                     () -> Preconditions.checkIndex(index, length,
+                                                    Preconditions.outOfBoundsExceptionFormatter(ArrayIndexOutOfBoundsException::new)));
         checker.accept(StringIndexOutOfBoundsException.class,
-                     () -> Objects.checkIndex(index, length,
-                                              Objects.outOfBoundsExceptionFormatter(StringIndexOutOfBoundsException::new)));
+                     () -> Preconditions.checkIndex(index, length,
+                                                    Preconditions.outOfBoundsExceptionFormatter(StringIndexOutOfBoundsException::new)));
     }
 
 
     @DataProvider
     static Object[][] checkFromToIndexProvider() {

@@ -155,11 +157,11 @@
 
     @Test(dataProvider = "checkFromToIndexProvider")
     public void testCheckFromToIndex(int fromIndex, int toIndex, int length, boolean withinBounds) {
         String expectedMessage = withinBounds
                                  ? null
-                                 : Objects.outOfBoundsExceptionFormatter(IndexOutOfBoundsException::new).
+                                 : 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,25 +179,25 @@
                     assertEquals(e.getMessage(), expectedMessage);
             }
         };
 
         check.accept(AssertingOutOfBoundsException.class,
-                     () -> Objects.checkFromToIndex(fromIndex, toIndex, length,
+                     () -> Preconditions.checkFromToIndex(fromIndex, toIndex, length,
                                                     assertingOutOfBounds(expectedMessage, "checkFromToIndex", fromIndex, toIndex, length)));
         check.accept(IndexOutOfBoundsException.class,
-                     () -> Objects.checkFromToIndex(fromIndex, toIndex, length,
+                     () -> Preconditions.checkFromToIndex(fromIndex, toIndex, length,
                                                     assertingOutOfBoundsReturnNull("checkFromToIndex", fromIndex, toIndex, length)));
         check.accept(IndexOutOfBoundsException.class,
-                     () -> Objects.checkFromToIndex(fromIndex, toIndex, length, null));
+                     () -> Preconditions.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)));
+                     () -> Preconditions.checkFromToIndex(fromIndex, toIndex, length,
+                                                          Preconditions.outOfBoundsExceptionFormatter(ArrayIndexOutOfBoundsException::new)));
         check.accept(StringIndexOutOfBoundsException.class,
-                     () -> Objects.checkFromToIndex(fromIndex, toIndex, length,
-                                              Objects.outOfBoundsExceptionFormatter(StringIndexOutOfBoundsException::new)));
+                     () -> Preconditions.checkFromToIndex(fromIndex, toIndex, length,
+                                                          Preconditions.outOfBoundsExceptionFormatter(StringIndexOutOfBoundsException::new)));
     }
 
 
     @DataProvider
     static Object[][] checkFromIndexSizeProvider() {

@@ -224,11 +226,11 @@
 
     @Test(dataProvider = "checkFromIndexSizeProvider")
     public void testCheckFromIndexSize(int fromIndex, int size, int length, boolean withinBounds) {
         String expectedMessage = withinBounds
                                  ? null
-                                 : Objects.outOfBoundsExceptionFormatter(IndexOutOfBoundsException::new).
+                                 : 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,31 +248,31 @@
                     assertEquals(e.getMessage(), expectedMessage);
             }
         };
 
         check.accept(AssertingOutOfBoundsException.class,
-                     () -> Objects.checkFromIndexSize(fromIndex, size, length,
+                     () -> Preconditions.checkFromIndexSize(fromIndex, size, length,
                                                       assertingOutOfBounds(expectedMessage, "checkFromIndexSize", fromIndex, size, length)));
         check.accept(IndexOutOfBoundsException.class,
-                     () -> Objects.checkFromIndexSize(fromIndex, size, length,
+                     () -> Preconditions.checkFromIndexSize(fromIndex, size, length,
                                                       assertingOutOfBoundsReturnNull("checkFromIndexSize", fromIndex, size, length)));
         check.accept(IndexOutOfBoundsException.class,
-                     () -> Objects.checkFromIndexSize(fromIndex, size, length, null));
+                     () -> Preconditions.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)));
+                     () -> Preconditions.checkFromIndexSize(fromIndex, size, length,
+                                                            Preconditions.outOfBoundsExceptionFormatter(ArrayIndexOutOfBoundsException::new)));
         check.accept(StringIndexOutOfBoundsException.class,
-                     () -> Objects.checkFromIndexSize(fromIndex, size, length,
-                                                    Objects.outOfBoundsExceptionFormatter(StringIndexOutOfBoundsException::new)));
+                     () -> Preconditions.checkFromIndexSize(fromIndex, size, length,
+                                                            Preconditions.outOfBoundsExceptionFormatter(StringIndexOutOfBoundsException::new)));
     }
 
     @Test
     public void uniqueMessagesForCheckKinds() {
         BiFunction<String, List<Integer>, IndexOutOfBoundsException> f =
-                Objects.outOfBoundsExceptionFormatter(IndexOutOfBoundsException::new);
+                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 >