Skip to content

Commit

Permalink
[JENKINS-71810] Token Macro tests fail on Java 21 (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
basil authored Aug 11, 2023
1 parent 3616110 commit f35bf26
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import java.util.Map;
import java.util.TimeZone;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.matchesPattern;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -74,8 +74,8 @@ public void testShouldPrintDate()

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

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

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
import static junit.framework.Assert.assertEquals;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.matchesPattern;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -148,10 +150,10 @@ public void testShouldPrintDate()

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

// Date format changed in Java 9, so we have to accomodate the potential additional comma
// See https://www.oracle.com/technetwork/java/javase/9-relnote-issues-3704069.html#JDK-8008577
Assert.assertTrue(contentStr.matches(
"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"));
// Date format changed in Java 21, so we have to accomodate the potential narrow no-break space
// See https://bugs.openjdk.org/browse/JDK-8225245
assertThat(contentStr, matchesPattern(
"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"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
import java.util.Map;
import java.util.TimeZone;

import static junit.framework.Assert.assertEquals;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.matchesPattern;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -151,10 +153,10 @@ public void testShouldPrintDate()

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

// Date format changed in Java 9, so we have to accomodate the potential additional comma
// See https://www.oracle.com/technetwork/java/javase/9-relnote-issues-3704069.html#JDK-8008577
Assert.assertTrue(contentStr.matches(
"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"));
// Date format changed in Java 21, so we have to accomodate the potential narrow no-break space
// See https://bugs.openjdk.org/browse/JDK-8225245
assertThat(contentStr, matchesPattern(
"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"));
}

@Test
Expand Down

0 comments on commit f35bf26

Please sign in to comment.