mirror of https://github.com/jenkinsci/jenkins.git
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 <mark.earl.waite@gmail.com> * replaced junit4 with junit5-vintage engine Co-authored-by: Mark Waite <mark.earl.waite@gmail.com>
This commit is contained in:
parent
8cc32e956d
commit
dcc9a924d8
24
core/pom.xml
24
core/pom.xml
|
|
@ -40,6 +40,7 @@ THE SOFTWARE.
|
||||||
<properties>
|
<properties>
|
||||||
<staplerFork>true</staplerFork>
|
<staplerFork>true</staplerFork>
|
||||||
<hamcrest.version>2.2</hamcrest.version>
|
<hamcrest.version>2.2</hamcrest.version>
|
||||||
|
<junit.jupiter.version>5.6.2</junit.jupiter.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
|
|
@ -428,8 +429,27 @@ THE SOFTWARE.
|
||||||
<artifactId>spring-aop</artifactId>
|
<artifactId>spring-aop</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit-jupiter-api</artifactId>
|
||||||
|
<version>${junit.jupiter.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
|
<version>${junit.jupiter.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.vintage</groupId>
|
||||||
|
<artifactId>junit-vintage-engine</artifactId>
|
||||||
|
<version>${junit.jupiter.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter</artifactId>
|
||||||
|
<version>${junit.jupiter.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
||||||
|
|
@ -25,12 +25,14 @@ package hudson;
|
||||||
|
|
||||||
import hudson.util.VersionNumber;
|
import hudson.util.VersionNumber;
|
||||||
import jenkins.plugins.DetachedPluginsUtil;
|
import jenkins.plugins.DetachedPluginsUtil;
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static jenkins.plugins.DetachedPluginsUtil.DetachedPlugin;
|
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 <a href="mailto:tom.fennelly@gmail.com">tom.fennelly@gmail.com</a>
|
* @author <a href="mailto:tom.fennelly@gmail.com">tom.fennelly@gmail.com</a>
|
||||||
|
|
@ -41,21 +43,21 @@ public class ClassicPluginStrategyTest {
|
||||||
public void test_getDetachedPlugins() {
|
public void test_getDetachedPlugins() {
|
||||||
List<DetachedPlugin> list = DetachedPluginsUtil.getDetachedPlugins(new VersionNumber("1.296"));
|
List<DetachedPlugin> list = DetachedPluginsUtil.getDetachedPlugins(new VersionNumber("1.296"));
|
||||||
|
|
||||||
Assert.assertTrue(list.size() >= 14); // There were 14 at the time of writing this test
|
assertTrue(list.size() >= 14); // There were 14 at the time of writing this test
|
||||||
Assert.assertNotNull(findPlugin("maven-plugin", list));
|
assertNotNull(findPlugin("maven-plugin", list));
|
||||||
Assert.assertNotNull(findPlugin("subversion", list));
|
assertNotNull(findPlugin("subversion", list));
|
||||||
|
|
||||||
// Narrow the list to since "1.310" (the subversion detach version).
|
// Narrow the list to since "1.310" (the subversion detach version).
|
||||||
list = DetachedPluginsUtil.getDetachedPlugins(new VersionNumber("1.310"));
|
list = DetachedPluginsUtil.getDetachedPlugins(new VersionNumber("1.310"));
|
||||||
// Maven should no longer be in the list, but subversion should.
|
// Maven should no longer be in the list, but subversion should.
|
||||||
Assert.assertNull(findPlugin("maven-plugin", list));
|
assertNull(findPlugin("maven-plugin", list));
|
||||||
Assert.assertNotNull(findPlugin("subversion", list));
|
assertNotNull(findPlugin("subversion", list));
|
||||||
|
|
||||||
// Narrow the list to since "1.311" (after the subversion detach version).
|
// Narrow the list to since "1.311" (after the subversion detach version).
|
||||||
list = DetachedPluginsUtil.getDetachedPlugins(new VersionNumber("1.311"));
|
list = DetachedPluginsUtil.getDetachedPlugins(new VersionNumber("1.311"));
|
||||||
// Neither Maven or subversion should be in the list.
|
// Neither Maven or subversion should be in the list.
|
||||||
Assert.assertNull(findPlugin("maven-plugin", list));
|
assertNull(findPlugin("maven-plugin", list));
|
||||||
Assert.assertNull(findPlugin("subversion", list));
|
assertNull(findPlugin("subversion", list));
|
||||||
}
|
}
|
||||||
|
|
||||||
private DetachedPlugin findPlugin(String shortName, List<DetachedPlugin> list) {
|
private DetachedPlugin findPlugin(String shortName, List<DetachedPlugin> list) {
|
||||||
|
|
|
||||||
|
|
@ -25,15 +25,20 @@ package hudson;
|
||||||
|
|
||||||
import hudson.EnvVars.OverrideOrderCalculator;
|
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 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.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
*/
|
*/
|
||||||
|
|
@ -118,7 +123,7 @@ public class EnvVarsTest {
|
||||||
|
|
||||||
OverrideOrderCalculator calc = new OverrideOrderCalculator(env, overrides);
|
OverrideOrderCalculator calc = new OverrideOrderCalculator(env, overrides);
|
||||||
List<String> order = calc.getOrderedVariableNames();
|
List<String> order = calc.getOrderedVariableNames();
|
||||||
assertEquals(Arrays.asList("PATH"), order);
|
assertEquals(Collections.singletonList("PATH"), order);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
|
|
@ -23,14 +23,14 @@
|
||||||
*/
|
*/
|
||||||
package hudson;
|
package hudson;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
import hudson.MarkupText.SubText;
|
import hudson.MarkupText.SubText;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
*/
|
*/
|
||||||
|
|
@ -60,8 +60,8 @@ public class MarkupTextTest {
|
||||||
public void findTokensOnSubText() {
|
public void findTokensOnSubText() {
|
||||||
MarkupText t = new MarkupText("Fixed 2 issues in this commit, fixing issue 155, 145");
|
MarkupText t = new MarkupText("Fixed 2 issues in this commit, fixing issue 155, 145");
|
||||||
List<SubText> tokens = t.findTokens(Pattern.compile("issue .*"));
|
List<SubText> tokens = t.findTokens(Pattern.compile("issue .*"));
|
||||||
assertEquals("Expected one token", 1, tokens.size());
|
assertEquals(1, tokens.size(), "Expected one token");
|
||||||
assertEquals("Expected single token was incorrect", "issue 155, 145", tokens.get(0).group(0));
|
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]+)")))
|
for (SubText st : tokens.get(0).findTokens(Pattern.compile("([0-9]+)")))
|
||||||
st.surroundWith("<$1>","<$1>");
|
st.surroundWith("<$1>","<$1>");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,35 +28,40 @@ import java.io.File;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import org.apache.tools.ant.filters.StringInputStream;
|
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 org.xml.sax.SAXException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.jar.Attributes;
|
import java.util.jar.Attributes;
|
||||||
import java.util.jar.Manifest;
|
import java.util.jar.Manifest;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.jvnet.hudson.test.Issue;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.*;
|
import static org.hamcrest.CoreMatchers.*;
|
||||||
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.core.IsInstanceOf.instanceOf;
|
import static org.hamcrest.core.IsInstanceOf.instanceOf;
|
||||||
import static org.hamcrest.core.StringContains.containsString;
|
import static org.hamcrest.core.StringContains.containsString;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.rules.TemporaryFolder;
|
|
||||||
import org.jvnet.hudson.test.Issue;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests of {@link PluginManager}.
|
* Tests of {@link PluginManager}.
|
||||||
*/
|
*/
|
||||||
public class PluginManagerTest {
|
public class PluginManagerTest {
|
||||||
|
|
||||||
@Rule public TemporaryFolder tmp = new TemporaryFolder();
|
@TempDir Path tmp;
|
||||||
|
|
||||||
@Test public void parseRequestedPlugins() throws Exception {
|
@Test
|
||||||
assertEquals("{other=2.0, stuff=1.2}", new LocalPluginManager(tmp.getRoot())
|
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("<root><stuff plugin='stuff@1.0'><more plugin='other@2.0'><things plugin='stuff@1.2'/></more></stuff></root>")).toString());
|
.parseRequestedPlugins(new StringInputStream("<root><stuff plugin='stuff@1.0'><more plugin='other@2.0'><things plugin='stuff@1.2'/></more></stuff></root>")).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -145,12 +150,11 @@ public class PluginManagerTest {
|
||||||
"Plugin-Developers: ";
|
"Plugin-Developers: ";
|
||||||
|
|
||||||
private File createHpiWithManifest() throws IOException {
|
private File createHpiWithManifest() throws IOException {
|
||||||
File newFolder = tmp.newFolder("myJar");
|
|
||||||
String manifestPath = "META-INF/MANIFEST.MF";
|
String manifestPath = "META-INF/MANIFEST.MF";
|
||||||
new File("META-INF").mkdir();
|
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()))) {
|
try(ZipOutputStream out = new ZipOutputStream(Files.newOutputStream(f.toPath()))) {
|
||||||
ZipEntry e = new ZipEntry(manifestPath);
|
ZipEntry e = new ZipEntry(manifestPath);
|
||||||
out.putNextEntry(e);
|
out.putNextEntry(e);
|
||||||
|
|
|
||||||
|
|
@ -10,36 +10,37 @@ import java.util.jar.Attributes;
|
||||||
import java.util.jar.Manifest;
|
import java.util.jar.Manifest;
|
||||||
|
|
||||||
import jenkins.model.Jenkins;
|
import jenkins.model.Jenkins;
|
||||||
import org.junit.After;
|
import org.junit.jupiter.api.AfterAll;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.mockito.invocation.InvocationOnMock;
|
import org.mockito.invocation.InvocationOnMock;
|
||||||
import org.mockito.stubbing.Answer;
|
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 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.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
public class PluginWrapperTest {
|
public class PluginWrapperTest {
|
||||||
|
|
||||||
private Locale loc;
|
private static Locale loc;
|
||||||
|
|
||||||
@Before
|
@BeforeAll
|
||||||
public void before() throws Exception {
|
public static void before() {
|
||||||
Jenkins.VERSION = "2.0"; // Some value needed - tests will overwrite if necessary
|
Jenkins.VERSION = "2.0"; // Some value needed - tests will overwrite if necessary
|
||||||
loc = Locale.getDefault();
|
loc = Locale.getDefault();
|
||||||
Locale.setDefault(new Locale("en", "GB"));
|
Locale.setDefault(new Locale("en", "GB"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@AfterAll
|
||||||
public void after() {
|
public static void after() {
|
||||||
Locale.setDefault(loc);
|
Locale.setDefault(loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -62,7 +63,7 @@ public class PluginWrapperTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void jenkinsCoreTooOld() throws Exception {
|
public void jenkinsCoreTooOld() {
|
||||||
PluginWrapper pw = pluginWrapper("fake").requiredCoreVersion("3.0").buildLoaded();
|
PluginWrapper pw = pluginWrapper("fake").requiredCoreVersion("3.0").buildLoaded();
|
||||||
try {
|
try {
|
||||||
pw.resolvePluginDependencies();
|
pw.resolvePluginDependencies();
|
||||||
|
|
@ -73,7 +74,7 @@ public class PluginWrapperTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void dependencyNotInstalled() throws Exception {
|
public void dependencyNotInstalled() {
|
||||||
PluginWrapper pw = pluginWrapper("dependee").deps("dependency:42").buildLoaded();
|
PluginWrapper pw = pluginWrapper("dependee").deps("dependency:42").buildLoaded();
|
||||||
try {
|
try {
|
||||||
pw.resolvePluginDependencies();
|
pw.resolvePluginDependencies();
|
||||||
|
|
@ -84,7 +85,7 @@ public class PluginWrapperTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void dependencyOutdated() throws Exception {
|
public void dependencyOutdated() {
|
||||||
pluginWrapper("dependency").version("3").buildLoaded();
|
pluginWrapper("dependency").version("3").buildLoaded();
|
||||||
PluginWrapper pw = pluginWrapper("dependee").deps("dependency:5").buildLoaded();
|
PluginWrapper pw = pluginWrapper("dependee").deps("dependency:5").buildLoaded();
|
||||||
try {
|
try {
|
||||||
|
|
@ -96,7 +97,7 @@ public class PluginWrapperTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void dependencyFailedToLoad() throws Exception {
|
public void dependencyFailedToLoad() {
|
||||||
pluginWrapper("dependency").version("5").buildFailed();
|
pluginWrapper("dependency").version("5").buildFailed();
|
||||||
PluginWrapper pw = pluginWrapper("dependee").deps("dependency:3").buildLoaded();
|
PluginWrapper pw = pluginWrapper("dependee").deps("dependency:3").buildLoaded();
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -23,12 +23,12 @@
|
||||||
*/
|
*/
|
||||||
package hudson;
|
package hudson;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.net.Proxy;
|
import java.net.Proxy;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
public class ProxyConfigurationTest {
|
public class ProxyConfigurationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
|
|
@ -23,13 +23,13 @@
|
||||||
*/
|
*/
|
||||||
package hudson.console;
|
package hudson.console;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import hudson.MarkupText;
|
import hudson.MarkupText;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.jvnet.hudson.test.Issue;
|
import org.jvnet.hudson.test.Issue;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Alan Harder
|
* @author Alan Harder
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -31,31 +31,32 @@ import java.io.PrintStream;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
|
|
||||||
import org.apache.commons.io.output.NullOutputStream;
|
import org.apache.commons.io.output.NullOutputStream;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.jvnet.hudson.test.Issue;
|
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 {
|
public class ComputerLauncherTest {
|
||||||
|
|
||||||
@Test(expected=IOException.class) public void jdk7() throws IOException {
|
@Test public void jdk7() {
|
||||||
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");
|
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 {
|
@Test public void openJDK7() {
|
||||||
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");
|
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 {
|
@Test public void jdk6() {
|
||||||
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");
|
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 {
|
@Test public void jdk5() {
|
||||||
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")));
|
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 {
|
@Test public void j2sdk4() {
|
||||||
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")));
|
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 {
|
@Test public void jdk8() throws IOException {
|
||||||
|
|
@ -102,7 +103,6 @@ public class ComputerLauncherTest {
|
||||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||||
ComputerLauncher.checkJavaVersion(new PrintStream(os), "bin/java", new BufferedReader(new StringReader(text)));
|
ComputerLauncher.checkJavaVersion(new PrintStream(os), "bin/java", new BufferedReader(new StringReader(text)));
|
||||||
String logged = os.toString();
|
String logged = os.toString();
|
||||||
assertTrue(logged, logged.contains(Messages.ComputerLauncher_JavaVersionResult("bin/java", spec)));
|
assertTrue(logged.contains(Messages.ComputerLauncher_JavaVersionResult("bin/java", spec)), logged);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,8 @@
|
||||||
*/
|
*/
|
||||||
package hudson.slaves;
|
package hudson.slaves;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
import jenkins.model.Jenkins;
|
import jenkins.model.Jenkins;
|
||||||
|
|
@ -35,7 +35,7 @@ import java.io.File;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
*/
|
*/
|
||||||
package hudson.triggers;
|
package hudson.triggers;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.jvnet.hudson.test.Issue;
|
import org.jvnet.hudson.test.Issue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -24,63 +24,47 @@
|
||||||
|
|
||||||
package jenkins.model.labels;
|
package jenkins.model.labels;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Collections;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.junit.Test;
|
import java.util.stream.Stream;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.Parameterized;
|
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
|
* @author dty
|
||||||
*/
|
*/
|
||||||
@RunWith(Parameterized.class)
|
|
||||||
public class LabelAutoCompleteSeederTest {
|
public class LabelAutoCompleteSeederTest {
|
||||||
|
|
||||||
public static class TestData {
|
static Stream<Arguments> localParameters()
|
||||||
private final String seed;
|
{
|
||||||
private final List<String> expected;
|
return Stream.of(
|
||||||
|
Arguments.of("", Collections.singletonList("")),
|
||||||
public TestData(String seed, String... expected) {
|
Arguments.of("\"", Collections.singletonList("")),
|
||||||
this.seed = seed;
|
Arguments.of("\"\"", Collections.singletonList("")),
|
||||||
this.expected = Arrays.asList(expected);
|
Arguments.of("freebsd", Collections.singletonList("freebsd")),
|
||||||
}
|
Arguments.of(" freebsd", Collections.singletonList("freebsd")),
|
||||||
}
|
Arguments.of("freebsd ", Collections.singletonList("")),
|
||||||
|
Arguments.of("freebsd 6", Collections.singletonList("6")),
|
||||||
@Parameterized.Parameters
|
Arguments.of("\"freebsd", Collections.singletonList("freebsd")),
|
||||||
public static Collection<Object[]> data() {
|
Arguments.of("\"freebsd ", Collections.singletonList("freebsd ")),
|
||||||
return Arrays.asList( new Object[][] {
|
Arguments.of("\"freebsd\"", Collections.singletonList("")),
|
||||||
{ new TestData("", "") },
|
Arguments.of("\"freebsd\" ", Collections.singletonList("")),
|
||||||
{ new TestData("\"", "") },
|
Arguments.of("\"freebsd 6", Collections.singletonList("freebsd 6")),
|
||||||
{ new TestData("\"\"", "") },
|
Arguments.of("\"freebsd 6\"", Collections.singletonList(""))
|
||||||
{ 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\"", "") },
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final String seed;
|
@ParameterizedTest( name = "{index}" )
|
||||||
private final List<String> expected;
|
@MethodSource( "localParameters" )
|
||||||
|
public void testAutoCompleteSeeds(String underTest, List<String> expected) {
|
||||||
public LabelAutoCompleteSeederTest(TestData dataSet) {
|
LabelAutoCompleteSeeder seeder = new LabelAutoCompleteSeeder(underTest);
|
||||||
this.seed = dataSet.seed;
|
|
||||||
this.expected = dataSet.expected;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testAutoCompleteSeeds() throws Exception {
|
|
||||||
LabelAutoCompleteSeeder seeder = new LabelAutoCompleteSeeder(seed);
|
|
||||||
assertEquals(expected, seeder.getSeeds());
|
assertEquals(expected, seeder.getSeeds());
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,13 +1,16 @@
|
||||||
package jenkins.util;
|
package jenkins.util;
|
||||||
|
|
||||||
import hudson.util.OneShotEvent;
|
import hudson.util.OneShotEvent;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import org.junit.Test;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
|
||||||
|
|
||||||
public class AtmostOneTaskExecutorTest {
|
public class AtmostOneTaskExecutorTest {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,8 @@
|
||||||
package jenkins.util;
|
package jenkins.util;
|
||||||
|
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
import groovy.lang.GroovyClassLoader;
|
import groovy.lang.GroovyClassLoader;
|
||||||
import hudson.triggers.SafeTimerTask;
|
import hudson.triggers.SafeTimerTask;
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
import org.jvnet.hudson.test.Issue;
|
import org.jvnet.hudson.test.Issue;
|
||||||
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
|
@ -13,6 +10,9 @@ import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
public class TimerTest {
|
public class TimerTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -35,7 +35,7 @@ public class TimerTest {
|
||||||
|
|
||||||
SafeTimerTask task2 = new SafeTimerTask() {
|
SafeTimerTask task2 = new SafeTimerTask() {
|
||||||
@Override
|
@Override
|
||||||
protected void doRun() throws Exception {
|
protected void doRun() {
|
||||||
stopLatch.countDown();
|
stopLatch.countDown();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -60,7 +60,7 @@ public class TimerTest {
|
||||||
final CountDownLatch startLatch = new CountDownLatch(threadCount);
|
final CountDownLatch startLatch = new CountDownLatch(threadCount);
|
||||||
|
|
||||||
final ClassLoader[] contextClassloaders = new ClassLoader[threadCount];
|
final ClassLoader[] contextClassloaders = new ClassLoader[threadCount];
|
||||||
ScheduledFuture[] futures = new ScheduledFuture[threadCount];
|
ScheduledFuture<?>[] futures = new ScheduledFuture[threadCount];
|
||||||
final ClassLoader bogusClassloader = new GroovyClassLoader();
|
final ClassLoader bogusClassloader = new GroovyClassLoader();
|
||||||
|
|
||||||
Runnable timerTest = new Runnable() {
|
Runnable timerTest = new Runnable() {
|
||||||
|
|
@ -88,12 +88,12 @@ public class TimerTest {
|
||||||
};
|
};
|
||||||
|
|
||||||
Thread t = new Thread(timerTest);
|
Thread t = new Thread(timerTest);
|
||||||
t.run();
|
t.start();
|
||||||
t.join(1000L);
|
t.join(1000L);
|
||||||
|
|
||||||
for (int i=0; i<threadCount; i++) {
|
for (int i=0; i<threadCount; i++) {
|
||||||
futures[i].get();
|
futures[i].get();
|
||||||
Assert.assertEquals(Timer.class.getClassLoader(), contextClassloaders[i]);
|
assertEquals(Timer.class.getClassLoader(), contextClassloaders[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
package jenkins.util;
|
package jenkins.util;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.jvnet.hudson.test.Issue;
|
import org.jvnet.hudson.test.Issue;
|
||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
|
||||||
public class UrlHelperTest {
|
public class UrlHelperTest {
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue