Skip to content

Commit cf7e600

Browse files
committed
Adapt tests to Java 21 date format change
Java 21 changed the date format to use a narrow no-break space, so the regular expression used in the tests now fails to match. Changed the test to use the '\h' character class, which matches. jenkinsci/token-macro-plugin#191 uses the same technique to handle test compatibility between Java 11, Java 17, and Java 21.
1 parent 813c21b commit cf7e600

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/test/java/org/jenkinsci/plugins/schedulebuild/ScheduleBuildActionTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static org.hamcrest.CoreMatchers.is;
44
import static org.hamcrest.MatcherAssert.assertThat;
55
import static org.hamcrest.Matchers.endsWith;
6+
import static org.hamcrest.Matchers.matchesPattern;
67
import static org.hamcrest.Matchers.nullValue;
78
import static org.junit.Assert.assertFalse;
89
import static org.junit.Assert.assertTrue;
@@ -89,7 +90,7 @@ public void testSchedule() throws Exception {
8990

9091
@Test
9192
public void testGetDefaultDate() throws Exception {
92-
assertThat(scheduleBuildAction.getDefaultDate(), endsWith(" 10:00:00 PM"));
93+
assertThat(scheduleBuildAction.getDefaultDate(), matchesPattern(".* 10:00:00\\hPM"));
9394
}
9495

9596
@Test

src/test/java/org/jenkinsci/plugins/schedulebuild/ScheduleBuildGlobalConfigurationTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static org.hamcrest.CoreMatchers.*;
44
import static org.hamcrest.MatcherAssert.*;
5+
import static org.hamcrest.Matchers.matchesPattern;
56
import static org.junit.Assert.assertThrows;
67

78
import java.time.ZoneId;
@@ -30,7 +31,7 @@ public void setUp() {
3031
@Test
3132
public void configRoundTripTestNoChanges() throws Exception {
3233
assertThat(globalConfig, is(not(nullValue())));
33-
assertThat(globalConfig.getDefaultScheduleTime(), is("10:00:00 PM"));
34+
assertThat(globalConfig.getDefaultScheduleTime(), matchesPattern("10:00:00\\hPM"));
3435
assertThat(globalConfig.getTimeZone(), is(TimeZone.getDefault().getID()));
3536

3637
// Submit the global configuration page with no changes
@@ -39,7 +40,7 @@ public void configRoundTripTestNoChanges() throws Exception {
3940
ScheduleBuildGlobalConfiguration newGlobalConfig =
4041
GlobalConfiguration.all().getInstance(ScheduleBuildGlobalConfiguration.class);
4142
assertThat(newGlobalConfig, is(not(nullValue())));
42-
assertThat(newGlobalConfig.getDefaultScheduleTime(), is("10:00:00 PM"));
43+
assertThat(newGlobalConfig.getDefaultScheduleTime(), matchesPattern("10:00:00\\hPM"));
4344
assertThat(newGlobalConfig.getTimeZone(), is(TimeZone.getDefault().getID()));
4445
}
4546

@@ -79,14 +80,14 @@ public void testDoCheckTimeZone() throws Exception {
7980

8081
@Test
8182
public void testGetDefaultScheduleTime() {
82-
assertThat(globalConfig.getDefaultScheduleTime(), is("10:00:00 PM"));
83+
assertThat(globalConfig.getDefaultScheduleTime(), matchesPattern("10:00:00\\hPM"));
8384
}
8485

8586
@Test
8687
public void testSetDefaultScheduleTime() throws Exception {
8788
String defaultScheduleTime = "12:34:56 PM";
8889
globalConfig.setDefaultScheduleTime(defaultScheduleTime);
89-
assertThat(globalConfig.getDefaultScheduleTime(), is(defaultScheduleTime));
90+
assertThat(globalConfig.getDefaultScheduleTime(), matchesPattern("12:34:56\\hPM"));
9091
}
9192

9293
@Test

0 commit comments

Comments
 (0)