From 33220dec3799a974fe6e10f86781b97b1092b4ea Mon Sep 17 00:00:00 2001 From: Jeff Thompson Date: Mon, 29 Oct 2018 13:01:07 -0600 Subject: [PATCH] Clean up warnings in tests about anonymous callable. Convert them to static, named classes. --- core/src/test/java/hudson/LauncherTest.java | 8 ++++---- core/src/test/java/hudson/os/SUTester.java | 18 +++++++++--------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/core/src/test/java/hudson/LauncherTest.java b/core/src/test/java/hudson/LauncherTest.java index 4df308b41d17..0d38795d274c 100644 --- a/core/src/test/java/hudson/LauncherTest.java +++ b/core/src/test/java/hudson/LauncherTest.java @@ -26,11 +26,11 @@ import hudson.model.StreamBuildListener; import hudson.model.TaskListener; -import hudson.remoting.Callable; import hudson.util.ProcessTree; import hudson.util.StreamTaskListener; import java.io.ByteArrayOutputStream; import java.io.File; + import jenkins.security.MasterToSlaveCallable; import org.apache.commons.io.FileUtils; import static org.junit.Assert.*; @@ -63,7 +63,7 @@ public class LauncherTest { long end = System.currentTimeMillis(); long terminationTime = end - start; assertTrue("Join did not finish promptly. The completion time (" + terminationTime + "ms) is longer than expected 15s", terminationTime < 15000); - channels.french.call(NOOP); // this only returns after the other side of the channel has finished executing cancellation + channels.french.call(new NoopCallable()); // this only returns after the other side of the channel has finished executing cancellation Thread.sleep(2000); // more delay to make sure it's gone assertNull("process should be gone",ProcessTree.get().get(Integer.parseInt(FileUtils.readFileToString(tmp).trim()))); @@ -76,11 +76,11 @@ public class LauncherTest { // hangs and on slave machine pgrep sleep => one process; after manual kill, script returns. } - private static final Callable NOOP = new MasterToSlaveCallable() { + private static class NoopCallable extends MasterToSlaveCallable { public Object call() throws RuntimeException { return null; } - }; + } @Issue("JENKINS-15733") @Test public void decorateByEnv() throws Exception { diff --git a/core/src/test/java/hudson/os/SUTester.java b/core/src/test/java/hudson/os/SUTester.java index 286391dffb4c..999391ef9b1c 100644 --- a/core/src/test/java/hudson/os/SUTester.java +++ b/core/src/test/java/hudson/os/SUTester.java @@ -5,19 +5,19 @@ import java.nio.file.Files; import jenkins.security.MasterToSlaveCallable; -import java.io.FileOutputStream; - /** * @author Kohsuke Kawaguchi */ public class SUTester { public static void main(String[] args) throws Throwable { - SU.execute(StreamTaskListener.fromStdout(),"kohsuke","bogus",new MasterToSlaveCallable() { - public Object call() throws Throwable { - System.out.println("Touching /tmp/x"); - Files.newOutputStream(new File("/tmp/x").toPath()).close(); - return null; - } - }); + SU.execute(StreamTaskListener.fromStdout(),"kohsuke","bogus", new TouchingCallable()); + } + + private static class TouchingCallable extends MasterToSlaveCallable { + public Object call() throws Throwable { + System.out.println("Touching /tmp/x"); + Files.newOutputStream(new File("/tmp/x").toPath()).close(); + return null; + } } }