--- jsr166/src/test/tck/ThreadLocalRandomTest.java 2014/12/31 19:05:43 1.20 +++ jsr166/src/test/tck/ThreadLocalRandomTest.java 2016/11/13 03:36:50 1.22 @@ -14,7 +14,7 @@ import junit.framework.TestSuite; public class ThreadLocalRandomTest extends JSR166TestCase { public static void main(String[] args) { - junit.textui.TestRunner.run(suite()); + main(suite(), args); } public static Test suite() { return new TestSuite(ThreadLocalRandomTest.class); @@ -52,6 +52,41 @@ public class ThreadLocalRandomTest exten } /** + * Repeated calls to next (only accessible via reflection) produce + * at least two distinct results, and repeated calls produce all + * possible values. + */ + public void testNext() throws ReflectiveOperationException { + ThreadLocalRandom rnd = ThreadLocalRandom.current(); + try { + java.lang.reflect.Method m + = ThreadLocalRandom.class.getDeclaredMethod( + "next", new Class[] { int.class }); + m.setAccessible(true); + + int i; + { + int val = new java.util.Random().nextInt(4); + for (i = 0; i < NCALLS; i++) { + int q = (int) m.invoke(rnd, new Object[] { 2 }); + if (val == q) break; + } + assertTrue(i < NCALLS); + } + + { + int r = (int) m.invoke(rnd, new Object[] { 3 }); + for (i = 0; i < NCALLS; i++) { + int q = (int) m.invoke(rnd, new Object[] { 3 }); + assertTrue(q < (1<<3)); + if (r != q) break; + } + assertTrue(i < NCALLS); + } + } catch (SecurityException acceptable) {} + } + + /** * Repeated calls to nextInt produce at least two distinct results */ public void testNextInt() {