Skip to content

Commit f35bf26

Browse files
authored
[JENKINS-71810] Token Macro tests fail on Java 21 (#191)
1 parent 3616110 commit f35bf26

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

src/test/java/org/jenkinsci/plugins/tokenmacro/impl/ChangesSinceLastBuildMacroTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
import java.util.Map;
2222
import java.util.TimeZone;
2323

24-
import static junit.framework.Assert.assertEquals;
25-
import static junit.framework.Assert.assertTrue;
26-
import static org.mockito.ArgumentMatchers.anyInt;
24+
import static org.hamcrest.MatcherAssert.assertThat;
25+
import static org.hamcrest.Matchers.matchesPattern;
26+
import static org.junit.Assert.assertEquals;
2727
import static org.mockito.Mockito.mock;
2828
import static org.mockito.Mockito.when;
2929

@@ -74,8 +74,8 @@ public void testShouldPrintDate()
7474

7575
String content = changesSinceLastBuildMacro.evaluate(currentBuild, listener, ChangesSinceLastBuildMacro.MACRO_NAME);
7676

77-
// Java 9 changed the SHORT date format... https://www.oracle.com/technetwork/java/javase/9-relnote-issues-3704069.html#JDK-8008577
78-
assertTrue(content.matches("Oct 21, 2013,? 7:39:00 PM"));
77+
// Java 21 changed the SHORT date format... https://bugs.openjdk.org/browse/JDK-8225245
78+
assertThat(content, matchesPattern("Oct 21, 2013, 7:39:00\\hPM"));
7979
}
8080

8181
@Test

src/test/java/org/jenkinsci/plugins/tokenmacro/impl/ChangesSinceLastSuccessfulBuildMacroTest.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919
import java.util.Locale;
2020
import java.util.Map;
2121
import java.util.TimeZone;
22-
import static junit.framework.Assert.assertEquals;
2322

23+
import static org.hamcrest.MatcherAssert.assertThat;
24+
import static org.hamcrest.Matchers.matchesPattern;
25+
import static org.junit.Assert.assertEquals;
2426
import static org.mockito.Mockito.mock;
2527
import static org.mockito.Mockito.when;
2628

@@ -148,10 +150,10 @@ public void testShouldPrintDate()
148150

149151
String contentStr = content.evaluate(currentBuild, listener, ChangesSinceLastSuccessfulBuildMacro.MACRO_NAME);
150152

151-
// Date format changed in Java 9, so we have to accomodate the potential additional comma
152-
// See https://www.oracle.com/technetwork/java/javase/9-relnote-issues-3704069.html#JDK-8008577
153-
Assert.assertTrue(contentStr.matches(
154-
"Changes for Build #41\n" + "Oct 21, 2013,? 7:39:00 PM\n" + "Changes for Build #42\n" + "Oct 21, 2013,? 7:39:00 PM\n"));
153+
// Date format changed in Java 21, so we have to accomodate the potential narrow no-break space
154+
// See https://bugs.openjdk.org/browse/JDK-8225245
155+
assertThat(contentStr, matchesPattern(
156+
"Changes for Build #41\n" + "Oct 21, 2013, 7:39:00\\hPM\n" + "Changes for Build #42\n" + "Oct 21, 2013, 7:39:00\\hPM\n"));
155157
}
156158

157159
@Test

src/test/java/org/jenkinsci/plugins/tokenmacro/impl/ChangesSinceLastUnstableBuildMacroTest.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
import java.util.Map;
2525
import java.util.TimeZone;
2626

27-
import static junit.framework.Assert.assertEquals;
27+
import static org.hamcrest.MatcherAssert.assertThat;
28+
import static org.hamcrest.Matchers.matchesPattern;
29+
import static org.junit.Assert.assertEquals;
2830
import static org.mockito.Mockito.mock;
2931
import static org.mockito.Mockito.when;
3032

@@ -151,10 +153,10 @@ public void testShouldPrintDate()
151153

152154
String contentStr = content.evaluate(currentBuild, listener, ChangesSinceLastUnstableBuildMacro.MACRO_NAME);
153155

154-
// Date format changed in Java 9, so we have to accomodate the potential additional comma
155-
// See https://www.oracle.com/technetwork/java/javase/9-relnote-issues-3704069.html#JDK-8008577
156-
Assert.assertTrue(contentStr.matches(
157-
"Changes for Build #41\n" + "Oct 21, 2013,? 7:39:00 PM\n" + "Changes for Build #42\n" + "Oct 21, 2013,? 7:39:00 PM\n"));
156+
// Date format changed in Java 21, so we have to accomodate the potential narrow no-break space
157+
// See https://bugs.openjdk.org/browse/JDK-8225245
158+
assertThat(contentStr, matchesPattern(
159+
"Changes for Build #41\n" + "Oct 21, 2013, 7:39:00\\hPM\n" + "Changes for Build #42\n" + "Oct 21, 2013, 7:39:00\\hPM\n"));
158160
}
159161

160162
@Test

0 commit comments

Comments
 (0)