From dcc9a924d84d2d35166166dde0ebfe2e9ef52ab0 Mon Sep 17 00:00:00 2001 From: StefanSpieker Date: Mon, 20 Jul 2020 23:14:21 +0200 Subject: [PATCH] Converting tests to junit5 (#4699) * started converting tests to junit5 * replaced TempFolder with JUnit TempDir * migrated some test classes to JUnit5 * migrated a parameterized testclass to junit5 * Update core/pom.xml Co-authored-by: Mark Waite * replaced junit4 with junit5-vintage engine Co-authored-by: Mark Waite --- core/pom.xml | 24 +++++- .../hudson/ClassicPluginStrategyTest.java | 20 ++--- core/src/test/java/hudson/EnvVarsTest.java | 11 ++- core/src/test/java/hudson/MarkupTextTest.java | 10 +-- .../test/java/hudson/PluginManagerTest.java | 32 ++++---- .../test/java/hudson/PluginWrapperTest.java | 37 ++++----- .../java/hudson/ProxyConfigurationTest.java | 6 +- .../java/hudson/console/UrlAnnotatorTest.java | 6 +- .../hudson/slaves/ComputerLauncherTest.java | 28 +++---- .../test/java/hudson/slaves/NodeListTest.java | 6 +- .../java/hudson/triggers/SCMTriggerTest.java | 2 +- .../labels/LabelAutoCompleteSeederTest.java | 76 ++++++++----------- .../util/AtmostOneTaskExecutorTest.java | 9 ++- .../src/test/java/jenkins/util/TimerTest.java | 16 ++-- .../test/java/jenkins/util/UrlHelperTest.java | 7 +- 15 files changed, 155 insertions(+), 135 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index d33df39a93..f975bb3447 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -40,6 +40,7 @@ THE SOFTWARE. true 2.2 + 5.6.2 @@ -428,8 +429,27 @@ THE SOFTWARE. spring-aop - junit - junit + org.junit.jupiter + junit-jupiter-api + ${junit.jupiter.version} + test + + + org.junit.jupiter + junit-jupiter-engine + ${junit.jupiter.version} + test + + + org.junit.vintage + junit-vintage-engine + ${junit.jupiter.version} + test + + + org.junit.jupiter + junit-jupiter + ${junit.jupiter.version} test diff --git a/core/src/test/java/hudson/ClassicPluginStrategyTest.java b/core/src/test/java/hudson/ClassicPluginStrategyTest.java index 766676ad21..558b8a3dd1 100644 --- a/core/src/test/java/hudson/ClassicPluginStrategyTest.java +++ b/core/src/test/java/hudson/ClassicPluginStrategyTest.java @@ -25,12 +25,14 @@ package hudson; import hudson.util.VersionNumber; import jenkins.plugins.DetachedPluginsUtil; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.List; import static jenkins.plugins.DetachedPluginsUtil.DetachedPlugin; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author tom.fennelly@gmail.com @@ -41,21 +43,21 @@ public class ClassicPluginStrategyTest { public void test_getDetachedPlugins() { List list = DetachedPluginsUtil.getDetachedPlugins(new VersionNumber("1.296")); - Assert.assertTrue(list.size() >= 14); // There were 14 at the time of writing this test - Assert.assertNotNull(findPlugin("maven-plugin", list)); - Assert.assertNotNull(findPlugin("subversion", list)); + assertTrue(list.size() >= 14); // There were 14 at the time of writing this test + assertNotNull(findPlugin("maven-plugin", list)); + assertNotNull(findPlugin("subversion", list)); // Narrow the list to since "1.310" (the subversion detach version). list = DetachedPluginsUtil.getDetachedPlugins(new VersionNumber("1.310")); // Maven should no longer be in the list, but subversion should. - Assert.assertNull(findPlugin("maven-plugin", list)); - Assert.assertNotNull(findPlugin("subversion", list)); + assertNull(findPlugin("maven-plugin", list)); + assertNotNull(findPlugin("subversion", list)); // Narrow the list to since "1.311" (after the subversion detach version). list = DetachedPluginsUtil.getDetachedPlugins(new VersionNumber("1.311")); // Neither Maven or subversion should be in the list. - Assert.assertNull(findPlugin("maven-plugin", list)); - Assert.assertNull(findPlugin("subversion", list)); + assertNull(findPlugin("maven-plugin", list)); + assertNull(findPlugin("subversion", list)); } private DetachedPlugin findPlugin(String shortName, List list) { diff --git a/core/src/test/java/hudson/EnvVarsTest.java b/core/src/test/java/hudson/EnvVarsTest.java index 9cfee90fc5..2a219de589 100644 --- a/core/src/test/java/hudson/EnvVarsTest.java +++ b/core/src/test/java/hudson/EnvVarsTest.java @@ -25,15 +25,20 @@ package hudson; import hudson.EnvVars.OverrideOrderCalculator; -import java.util.*; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.TreeMap; import com.google.common.collect.Sets; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; + /** * @author Kohsuke Kawaguchi */ @@ -118,7 +123,7 @@ public class EnvVarsTest { OverrideOrderCalculator calc = new OverrideOrderCalculator(env, overrides); List order = calc.getOrderedVariableNames(); - assertEquals(Arrays.asList("PATH"), order); + assertEquals(Collections.singletonList("PATH"), order); } @Test diff --git a/core/src/test/java/hudson/MarkupTextTest.java b/core/src/test/java/hudson/MarkupTextTest.java index 31549685bf..ca6549a935 100644 --- a/core/src/test/java/hudson/MarkupTextTest.java +++ b/core/src/test/java/hudson/MarkupTextTest.java @@ -23,14 +23,14 @@ */ package hudson; -import static org.junit.Assert.assertEquals; - import hudson.MarkupText.SubText; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.List; import java.util.regex.Pattern; +import static org.junit.jupiter.api.Assertions.assertEquals; + /** * @author Kohsuke Kawaguchi */ @@ -60,8 +60,8 @@ public class MarkupTextTest { public void findTokensOnSubText() { MarkupText t = new MarkupText("Fixed 2 issues in this commit, fixing issue 155, 145"); List tokens = t.findTokens(Pattern.compile("issue .*")); - assertEquals("Expected one token", 1, tokens.size()); - assertEquals("Expected single token was incorrect", "issue 155, 145", tokens.get(0).group(0)); + assertEquals(1, tokens.size(), "Expected one token"); + assertEquals("issue 155, 145", tokens.get(0).group(0), "Expected single token was incorrect"); for (SubText st : tokens.get(0).findTokens(Pattern.compile("([0-9]+)"))) st.surroundWith("<$1>","<$1>"); diff --git a/core/src/test/java/hudson/PluginManagerTest.java b/core/src/test/java/hudson/PluginManagerTest.java index 411dd3af7e..2aefe87f16 100644 --- a/core/src/test/java/hudson/PluginManagerTest.java +++ b/core/src/test/java/hudson/PluginManagerTest.java @@ -28,35 +28,40 @@ import java.io.File; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import org.apache.tools.ant.filters.StringInputStream; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import org.xml.sax.SAXException; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; +import java.nio.file.Path; import java.util.jar.Attributes; import java.util.jar.Manifest; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; import org.apache.commons.io.FileUtils; +import org.jvnet.hudson.test.Issue; + import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.hamcrest.core.StringContains.containsString; -import static org.junit.Assert.assertEquals; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.fail; -import org.junit.Rule; -import org.junit.rules.TemporaryFolder; -import org.jvnet.hudson.test.Issue; - +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; + /** * Tests of {@link PluginManager}. */ public class PluginManagerTest { - @Rule public TemporaryFolder tmp = new TemporaryFolder(); + @TempDir Path tmp; - @Test public void parseRequestedPlugins() throws Exception { - assertEquals("{other=2.0, stuff=1.2}", new LocalPluginManager(tmp.getRoot()) + @Test + public void parseRequestedPlugins() throws Exception { + Path output = Files.createFile( + tmp.resolve("output.txt") + ); + assertEquals("{other=2.0, stuff=1.2}", new LocalPluginManager(output.toFile()) .parseRequestedPlugins(new StringInputStream("")).toString()); } @@ -145,12 +150,11 @@ public class PluginManagerTest { "Plugin-Developers: "; private File createHpiWithManifest() throws IOException { - File newFolder = tmp.newFolder("myJar"); String manifestPath = "META-INF/MANIFEST.MF"; new File("META-INF").mkdir(); - FileUtils.write(new File(newFolder, manifestPath), SAMPLE_MANIFEST_FILE, StandardCharsets.UTF_8); + FileUtils.write(new File(tmp.toFile(), manifestPath), SAMPLE_MANIFEST_FILE, StandardCharsets.UTF_8); - final File f = new File(tmp.getRoot(), "my.hpi"); + final File f = new File(tmp.toFile(), "my.hpi"); try(ZipOutputStream out = new ZipOutputStream(Files.newOutputStream(f.toPath()))) { ZipEntry e = new ZipEntry(manifestPath); out.putNextEntry(e); diff --git a/core/src/test/java/hudson/PluginWrapperTest.java b/core/src/test/java/hudson/PluginWrapperTest.java index dba6df30d4..5fc7795de4 100644 --- a/core/src/test/java/hudson/PluginWrapperTest.java +++ b/core/src/test/java/hudson/PluginWrapperTest.java @@ -10,36 +10,37 @@ import java.util.jar.Attributes; import java.util.jar.Manifest; import jenkins.model.Jenkins; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; -import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import org.jvnet.hudson.test.Issue; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; public class PluginWrapperTest { - private Locale loc; + private static Locale loc; - @Before - public void before() throws Exception { + @BeforeAll + public static void before() { Jenkins.VERSION = "2.0"; // Some value needed - tests will overwrite if necessary loc = Locale.getDefault(); Locale.setDefault(new Locale("en", "GB")); } - @After - public void after() { + @AfterAll + public static void after() { Locale.setDefault(loc); } @@ -62,7 +63,7 @@ public class PluginWrapperTest { } @Test - public void jenkinsCoreTooOld() throws Exception { + public void jenkinsCoreTooOld() { PluginWrapper pw = pluginWrapper("fake").requiredCoreVersion("3.0").buildLoaded(); try { pw.resolvePluginDependencies(); @@ -73,7 +74,7 @@ public class PluginWrapperTest { } @Test - public void dependencyNotInstalled() throws Exception { + public void dependencyNotInstalled() { PluginWrapper pw = pluginWrapper("dependee").deps("dependency:42").buildLoaded(); try { pw.resolvePluginDependencies(); @@ -84,7 +85,7 @@ public class PluginWrapperTest { } @Test - public void dependencyOutdated() throws Exception { + public void dependencyOutdated() { pluginWrapper("dependency").version("3").buildLoaded(); PluginWrapper pw = pluginWrapper("dependee").deps("dependency:5").buildLoaded(); try { @@ -96,7 +97,7 @@ public class PluginWrapperTest { } @Test - public void dependencyFailedToLoad() throws Exception { + public void dependencyFailedToLoad() { pluginWrapper("dependency").version("5").buildFailed(); PluginWrapper pw = pluginWrapper("dependee").deps("dependency:3").buildLoaded(); try { diff --git a/core/src/test/java/hudson/ProxyConfigurationTest.java b/core/src/test/java/hudson/ProxyConfigurationTest.java index 43c6bc4fc7..3dd723fab3 100644 --- a/core/src/test/java/hudson/ProxyConfigurationTest.java +++ b/core/src/test/java/hudson/ProxyConfigurationTest.java @@ -23,12 +23,12 @@ */ package hudson; -import static org.junit.Assert.assertEquals; - -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.net.Proxy; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class ProxyConfigurationTest { @Test diff --git a/core/src/test/java/hudson/console/UrlAnnotatorTest.java b/core/src/test/java/hudson/console/UrlAnnotatorTest.java index f86fc07a22..76ca850f2d 100644 --- a/core/src/test/java/hudson/console/UrlAnnotatorTest.java +++ b/core/src/test/java/hudson/console/UrlAnnotatorTest.java @@ -23,13 +23,13 @@ */ package hudson.console; -import static org.junit.Assert.assertEquals; import hudson.MarkupText; -import org.junit.Test; - +import org.junit.jupiter.api.Test; import org.jvnet.hudson.test.Issue; +import static org.junit.jupiter.api.Assertions.assertEquals; + /** * @author Alan Harder */ diff --git a/core/src/test/java/hudson/slaves/ComputerLauncherTest.java b/core/src/test/java/hudson/slaves/ComputerLauncherTest.java index 8e5ecfc741..4aa8cb2036 100644 --- a/core/src/test/java/hudson/slaves/ComputerLauncherTest.java +++ b/core/src/test/java/hudson/slaves/ComputerLauncherTest.java @@ -31,31 +31,32 @@ import java.io.PrintStream; import java.io.StringReader; import org.apache.commons.io.output.NullOutputStream; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.jvnet.hudson.test.Issue; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; public class ComputerLauncherTest { - @Test(expected=IOException.class) public void jdk7() throws IOException { - assertChecked("java version \"1.7.0_05\"\nJava(TM) SE Runtime Environment (build 1.7.0_05-b05)\nJava HotSpot(TM) Server VM (build 23.1-b03, mixed mode)\n", "1.7.0"); + @Test public void jdk7() { + assertThrows(IOException.class, () -> assertChecked("java version \"1.7.0_05\"\nJava(TM) SE Runtime Environment (build 1.7.0_05-b05)\nJava HotSpot(TM) Server VM (build 23.1-b03, mixed mode)\n", "1.7.0")); } - @Test(expected=IOException.class) public void openJDK7() throws IOException { - assertChecked("openjdk version \"1.7.0-internal\"\nOpenJDK Runtime Environment (build 1.7.0-internal-pkgsrc_2010_01_03_06_54-b00)\nOpenJDK 64-Bit Server VM (build 17.0-b04, mixed mode)\n", "1.7.0"); + @Test public void openJDK7() { + assertThrows(IOException.class, () -> assertChecked("openjdk version \"1.7.0-internal\"\nOpenJDK Runtime Environment (build 1.7.0-internal-pkgsrc_2010_01_03_06_54-b00)\nOpenJDK 64-Bit Server VM (build 17.0-b04, mixed mode)\n", "1.7.0")); } - @Test(expected=IOException.class) public void jdk6() throws IOException { - assertChecked("java version \"1.6.0_33\"\nJava(TM) SE Runtime Environment (build 1.6.0_33-b03)\nJava HotSpot(TM) Server VM (build 20.8-b03, mixed mode)\n", "1.6.0"); + @Test public void jdk6() { + assertThrows(IOException.class, () -> assertChecked("java version \"1.6.0_33\"\nJava(TM) SE Runtime Environment (build 1.6.0_33-b03)\nJava HotSpot(TM) Server VM (build 20.8-b03, mixed mode)\n", "1.6.0")); } - @Test(expected=IOException.class) public void jdk5() throws IOException { - ComputerLauncher.checkJavaVersion(new PrintStream(new NullOutputStream()), "-", new BufferedReader(new StringReader("java version \"1.5.0_22\"\nJava(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_22-b03)\nJava HotSpot(TM) Server VM (build 1.5.0_22-b03, mixed mode)\n"))); + @Test public void jdk5() { + assertThrows(IOException.class, () -> ComputerLauncher.checkJavaVersion(new PrintStream(new NullOutputStream()), "-", new BufferedReader(new StringReader("java version \"1.5.0_22\"\nJava(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_22-b03)\nJava HotSpot(TM) Server VM (build 1.5.0_22-b03, mixed mode)\n")))); } - @Test(expected=IOException.class) public void j2sdk4() throws IOException { - ComputerLauncher.checkJavaVersion(new PrintStream(new NullOutputStream()), "-", new BufferedReader(new StringReader("java version \"1.4.2_19\"\nJava(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_19-b04)\nJava HotSpot(TM) Client VM (build 1.4.2_19-b04, mixed mode)\n"))); + @Test public void j2sdk4() { + assertThrows(IOException.class, () -> ComputerLauncher.checkJavaVersion(new PrintStream(new NullOutputStream()), "-", new BufferedReader(new StringReader("java version \"1.4.2_19\"\nJava(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_19-b04)\nJava HotSpot(TM) Client VM (build 1.4.2_19-b04, mixed mode)\n")))); } @Test public void jdk8() throws IOException { @@ -102,7 +103,6 @@ public class ComputerLauncherTest { ByteArrayOutputStream os = new ByteArrayOutputStream(); ComputerLauncher.checkJavaVersion(new PrintStream(os), "bin/java", new BufferedReader(new StringReader(text))); String logged = os.toString(); - assertTrue(logged, logged.contains(Messages.ComputerLauncher_JavaVersionResult("bin/java", spec))); + assertTrue(logged.contains(Messages.ComputerLauncher_JavaVersionResult("bin/java", spec)), logged); } - } diff --git a/core/src/test/java/hudson/slaves/NodeListTest.java b/core/src/test/java/hudson/slaves/NodeListTest.java index ee379e24bf..64ae0bb312 100644 --- a/core/src/test/java/hudson/slaves/NodeListTest.java +++ b/core/src/test/java/hudson/slaves/NodeListTest.java @@ -23,8 +23,8 @@ */ package hudson.slaves; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.*; import jenkins.model.Jenkins; @@ -35,7 +35,7 @@ import java.io.File; import java.nio.charset.Charset; import org.apache.commons.io.FileUtils; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Kohsuke Kawaguchi diff --git a/core/src/test/java/hudson/triggers/SCMTriggerTest.java b/core/src/test/java/hudson/triggers/SCMTriggerTest.java index 42e1a121bb..5b4a0d5363 100644 --- a/core/src/test/java/hudson/triggers/SCMTriggerTest.java +++ b/core/src/test/java/hudson/triggers/SCMTriggerTest.java @@ -23,7 +23,7 @@ */ package hudson.triggers; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.jvnet.hudson.test.Issue; /** diff --git a/core/src/test/java/jenkins/model/labels/LabelAutoCompleteSeederTest.java b/core/src/test/java/jenkins/model/labels/LabelAutoCompleteSeederTest.java index 31154f7508..5c2efe3417 100644 --- a/core/src/test/java/jenkins/model/labels/LabelAutoCompleteSeederTest.java +++ b/core/src/test/java/jenkins/model/labels/LabelAutoCompleteSeederTest.java @@ -24,63 +24,47 @@ package jenkins.model.labels; -import java.util.Arrays; -import java.util.Collection; +import java.util.Collections; import java.util.List; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import java.util.stream.Stream; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.Assert.assertEquals; /** * * @author dty */ -@RunWith(Parameterized.class) public class LabelAutoCompleteSeederTest { - public static class TestData { - private final String seed; - private final List expected; - - public TestData(String seed, String... expected) { - this.seed = seed; - this.expected = Arrays.asList(expected); - } - } - - @Parameterized.Parameters - public static Collection data() { - return Arrays.asList( new Object[][] { - { new TestData("", "") }, - { new TestData("\"", "") }, - { new TestData("\"\"", "") }, - { new TestData("freebsd", "freebsd") }, - { new TestData(" freebsd", "freebsd") }, - { new TestData("freebsd ", "") }, - { new TestData("freebsd 6", "6") }, - { new TestData("\"freebsd", "freebsd") }, - { new TestData("\"freebsd ", "freebsd ") }, - { new TestData("\"freebsd\"", "") }, - { new TestData("\"freebsd\" ", "") }, - { new TestData("\"freebsd 6", "freebsd 6") }, - { new TestData("\"freebsd 6\"", "") }, - }); + static Stream localParameters() + { + return Stream.of( + Arguments.of("", Collections.singletonList("")), + Arguments.of("\"", Collections.singletonList("")), + Arguments.of("\"\"", Collections.singletonList("")), + Arguments.of("freebsd", Collections.singletonList("freebsd")), + Arguments.of(" freebsd", Collections.singletonList("freebsd")), + Arguments.of("freebsd ", Collections.singletonList("")), + Arguments.of("freebsd 6", Collections.singletonList("6")), + Arguments.of("\"freebsd", Collections.singletonList("freebsd")), + Arguments.of("\"freebsd ", Collections.singletonList("freebsd ")), + Arguments.of("\"freebsd\"", Collections.singletonList("")), + Arguments.of("\"freebsd\" ", Collections.singletonList("")), + Arguments.of("\"freebsd 6", Collections.singletonList("freebsd 6")), + Arguments.of("\"freebsd 6\"", Collections.singletonList("")) + ); } - private final String seed; - private final List expected; - - public LabelAutoCompleteSeederTest(TestData dataSet) { - this.seed = dataSet.seed; - this.expected = dataSet.expected; - } - - @Test - public void testAutoCompleteSeeds() throws Exception { - LabelAutoCompleteSeeder seeder = new LabelAutoCompleteSeeder(seed); + @ParameterizedTest( name = "{index}" ) + @MethodSource( "localParameters" ) + public void testAutoCompleteSeeds(String underTest, List expected) { + LabelAutoCompleteSeeder seeder = new LabelAutoCompleteSeeder(underTest); assertEquals(expected, seeder.getSeeds()); - } + } } \ No newline at end of file diff --git a/core/src/test/java/jenkins/util/AtmostOneTaskExecutorTest.java b/core/src/test/java/jenkins/util/AtmostOneTaskExecutorTest.java index 1cc249bcba..2bd586227d 100644 --- a/core/src/test/java/jenkins/util/AtmostOneTaskExecutorTest.java +++ b/core/src/test/java/jenkins/util/AtmostOneTaskExecutorTest.java @@ -1,13 +1,16 @@ package jenkins.util; import hudson.util.OneShotEvent; +import org.junit.Test; + import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.atomic.AtomicInteger; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import org.junit.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; + public class AtmostOneTaskExecutorTest { diff --git a/core/src/test/java/jenkins/util/TimerTest.java b/core/src/test/java/jenkins/util/TimerTest.java index 14938bb56e..dde07b3cae 100644 --- a/core/src/test/java/jenkins/util/TimerTest.java +++ b/core/src/test/java/jenkins/util/TimerTest.java @@ -1,11 +1,8 @@ package jenkins.util; -import static org.junit.Assert.fail; - import groovy.lang.GroovyClassLoader; import hudson.triggers.SafeTimerTask; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.jvnet.hudson.test.Issue; import java.util.concurrent.CountDownLatch; @@ -13,6 +10,9 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; + public class TimerTest { /** @@ -35,7 +35,7 @@ public class TimerTest { SafeTimerTask task2 = new SafeTimerTask() { @Override - protected void doRun() throws Exception { + protected void doRun() { stopLatch.countDown(); } }; @@ -60,7 +60,7 @@ public class TimerTest { final CountDownLatch startLatch = new CountDownLatch(threadCount); final ClassLoader[] contextClassloaders = new ClassLoader[threadCount]; - ScheduledFuture[] futures = new ScheduledFuture[threadCount]; + ScheduledFuture[] futures = new ScheduledFuture[threadCount]; final ClassLoader bogusClassloader = new GroovyClassLoader(); Runnable timerTest = new Runnable() { @@ -88,12 +88,12 @@ public class TimerTest { }; Thread t = new Thread(timerTest); - t.run(); + t.start(); t.join(1000L); for (int i=0; i