Fix tests on newer java versions (#5182)

This commit is contained in:
Tim Jacomb authored and GitHub committed 2021-01-18 16:04:12 +00:00
1 parent d8c499bb85
commit ab5d044dcc
2 files changed
+20 -11

No files matched your search

+7 -3
View File
@@ -43,6 +43,9 @@ import java.util.regex.Pattern;
import hudson.util.VersionNumber;
import jenkins.model.Jenkins;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@@ -517,7 +520,8 @@ public class FunctionsTest {
stack1.cause(stack2);
stack2.cause(stack1);
//Format changed in 11.0.9 / 8.0.272 (JDK-8226809 / JDK-8252444 / JDK-8252489)
if ((getVersion().getDigitAt(0) == 11 && getVersion().isNewerThanOrEqualTo(new VersionNumber("11.0.9"))) ||
if ((getVersion().isNewerThanOrEqualTo(new VersionNumber("11.0.9"))) ||
(getVersion().getDigitAt(0) == 8 && getVersion().isNewerThanOrEqualTo(new VersionNumber("8.0.272")))) {
assertPrintThrowable(stack1,
"p.Exc1\n" +
@@ -554,10 +558,10 @@ public class FunctionsTest {
private static void assertPrintThrowable(Throwable t, String traditional, String custom) {
StringWriter sw = new StringWriter();
t.printStackTrace(new PrintWriter(sw));
assertEquals(sw.toString().replace(System.lineSeparator(), "\n"), traditional);
assertThat(sw.toString().replace(System.lineSeparator(), "\n"), is(traditional));
String actual = Functions.printThrowable(t);
System.out.println(actual);
assertEquals(actual.replace(System.lineSeparator(), "\n"), custom);
assertThat(actual.replace(System.lineSeparator(), "\n"), is(custom));
}
private static final class Stack extends Throwable {
private static final Pattern LINE = Pattern.compile("(.+)[.](.+)[.](.+):(\\d+)");
@@ -10,6 +10,10 @@ import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.stream.Collectors;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -27,22 +31,23 @@ public class DetachedPluginsUtilTest {
assertEquals(new VersionNumber("11"), jaxb.getMinimumJavaVersion());
final List<DetachedPluginsUtil.DetachedPlugin> detachedPlugins = DetachedPluginsUtil.getDetachedPlugins();
final List<String> detachedPlugins = mapToPluginShortName(DetachedPluginsUtil.getDetachedPlugins());
if (JavaUtils.isRunningWithJava8OrBelow()) {
assertEquals(0, detachedPlugins.stream()
.filter(plugin -> plugin.getShortName().equals("jaxb")).count());
} else if (JavaUtils.getCurrentJavaRuntimeVersionNumber().isNewerThanOrEqualTo(new VersionNumber("11.0.2"))) {
assertEquals(1, detachedPlugins.stream()
.filter(plugin -> plugin.getShortName().equals("jaxb")).count());
assertThat(detachedPlugins, not(hasItem("jaxb")));
} else {
assertThat(detachedPlugins, hasItem("jaxb"));
final List<DetachedPluginsUtil.DetachedPlugin> detachedPluginsSince2_161 =
DetachedPluginsUtil.getDetachedPlugins(new VersionNumber("2.161"));
assertEquals(1, detachedPluginsSince2_161.size());
assertEquals("jaxb", detachedPluginsSince2_161.get(0).getShortName());
assertThat(mapToPluginShortName(detachedPluginsSince2_161), contains("jaxb", "trilead-api"));
}
}
private List<String> mapToPluginShortName(List<DetachedPluginsUtil.DetachedPlugin> detachedPlugins) {
return detachedPlugins.stream().map(DetachedPluginsUtil.DetachedPlugin::getShortName).collect(Collectors.toList());
}
/**
* Checks the format of the {@code /jenkins/split-plugins.txt} file has maximum 4 columns.
*/