--- jsr166/src/test/tck/ExecutorsTest.java 2015/10/04 16:14:48 1.46 +++ jsr166/src/test/tck/ExecutorsTest.java 2017/08/16 17:18:34 1.50 @@ -140,7 +140,8 @@ public class ExecutorsTest extends JSR16 } /** - * A new newFixedThreadPool with null ThreadFactory throws NPE + * A new newFixedThreadPool with null ThreadFactory throws + * NullPointerException */ public void testNewFixedThreadPool3() { try { @@ -150,7 +151,7 @@ public class ExecutorsTest extends JSR16 } /** - * A new newFixedThreadPool with 0 threads throws IAE + * A new newFixedThreadPool with 0 threads throws IllegalArgumentException */ public void testNewFixedThreadPool4() { try { @@ -281,7 +282,7 @@ public class ExecutorsTest extends JSR16 delay(LONG_DELAY_MS); }}; - List threads = new ArrayList(); + List threads = new ArrayList<>(); for (final ExecutorService executor : executors) { threads.add(newStartedThread(new CheckedRunnable() { public void realRun() { @@ -306,16 +307,12 @@ public class ExecutorsTest extends JSR16 public void realRun() { try { Thread current = Thread.currentThread(); - assertTrue(!current.isDaemon()); + assertFalse(current.isDaemon()); assertTrue(current.getPriority() <= Thread.NORM_PRIORITY); - ThreadGroup g = current.getThreadGroup(); SecurityManager s = System.getSecurityManager(); - if (s != null) - assertTrue(g == s.getThreadGroup()); - else - assertTrue(g == egroup); - String name = current.getName(); - assertTrue(name.endsWith("thread-1")); + assertSame(current.getThreadGroup(), + (s == null) ? egroup : s.getThreadGroup()); + assertTrue(current.getName().endsWith("thread-1")); } catch (SecurityException ok) { // Also pass if not allowed to change setting } @@ -343,16 +340,12 @@ public class ExecutorsTest extends JSR16 Runnable r = new CheckedRunnable() { public void realRun() { Thread current = Thread.currentThread(); - assertTrue(!current.isDaemon()); + assertFalse(current.isDaemon()); assertTrue(current.getPriority() <= Thread.NORM_PRIORITY); - ThreadGroup g = current.getThreadGroup(); SecurityManager s = System.getSecurityManager(); - if (s != null) - assertTrue(g == s.getThreadGroup()); - else - assertTrue(g == egroup); - String name = current.getName(); - assertTrue(name.endsWith("thread-1")); + assertSame(current.getThreadGroup(), + (s == null) ? egroup : s.getThreadGroup()); + assertTrue(current.getName().endsWith("thread-1")); assertSame(thisccl, current.getContextClassLoader()); assertEquals(thisacc, AccessController.getContext()); done.countDown(); @@ -593,4 +586,56 @@ public class ExecutorsTest extends JSR16 } catch (NullPointerException success) {} } + /** + * callable(runnable, x).toString() contains toString of wrapped task + */ + public void testCallable_withResult_toString() { + if (testImplementationDetails) { + Runnable r = () -> {}; + Callable c = Executors.callable(r, ""); + assertEquals( + identityString(c) + "[Wrapped task = " + r.toString() + "]", + c.toString()); + } + } + + /** + * callable(runnable).toString() contains toString of wrapped task + */ + public void testCallable_toString() { + if (testImplementationDetails) { + Runnable r = () -> {}; + Callable c = Executors.callable(r); + assertEquals( + identityString(c) + "[Wrapped task = " + r.toString() + "]", + c.toString()); + } + } + + /** + * privilegedCallable(callable).toString() contains toString of wrapped task + */ + public void testPrivilegedCallable_toString() { + if (testImplementationDetails) { + Callable c = () -> ""; + Callable priv = Executors.privilegedCallable(c); + assertEquals( + identityString(priv) + "[Wrapped task = " + c.toString() + "]", + priv.toString()); + } + } + + /** + * privilegedCallableUsingCurrentClassLoader(callable).toString() + * contains toString of wrapped task + */ + public void testPrivilegedCallableUsingCurrentClassLoader_toString() { + if (testImplementationDetails) { + Callable c = () -> ""; + Callable priv = Executors.privilegedCallableUsingCurrentClassLoader(c); + assertEquals( + identityString(priv) + "[Wrapped task = " + c.toString() + "]", + priv.toString()); + } + } }