Skip to content

Commit 153fed7

Browse files
committed
fix RollingCalendarTest JoranConfiguratorTest
Signed-off-by: Ceki Gulcu <[email protected]>
1 parent 538c762 commit 153fed7

File tree

2 files changed

+42
-36
lines changed

2 files changed

+42
-36
lines changed

logback-classic/src/test/java/ch/qos/logback/classic/joran/JoranConfiguratorTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ public void sequenceNumberGenerator_missingClass() throws JoranException {
647647
//StatusPrinter.print(loggerContext);
648648
final ListAppender<ILoggingEvent> listAppender= (ListAppender<ILoggingEvent>) root.getAppender("LIST");
649649
assertNotNull(listAppender);
650-
checker.assertContainsMatch(Status.ERROR, "Missing attribute \\[class\\] in element \\[sequenceNumberGenerator\\]");
650+
checker.assertContainsMatch(Status.ERROR, "Missing attribute \\[class\\]. See element \\[sequenceNumberGenerator\\]");
651651
}
652652

653653
@Test

logback-core/src/test/java/ch/qos/logback/core/rolling/helper/RollingCalendarTest.java

+41-35
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,23 @@
1818
import java.util.Locale;
1919
import java.util.TimeZone;
2020

21-
import org.junit.jupiter.api.AfterEach;
22-
import org.junit.jupiter.api.Assertions;
23-
import org.junit.jupiter.api.BeforeEach;
24-
import org.junit.jupiter.api.Test;
21+
import org.junit.jupiter.api.*;
2522

2623
import ch.qos.logback.core.CoreConstants;
2724
import ch.qos.logback.core.util.EnvUtil;
2825

26+
import static org.junit.jupiter.api.Assertions.assertEquals;
27+
2928
public class RollingCalendarTest {
3029

3130
String dailyPattern = "yyyy-MM-dd";
3231

32+
3333
@BeforeEach
3434
public void setUp() {
3535

36-
// Most surprisingly, in certain environments (e.g. Windows 7), setting the
37-
// default locale
38-
// allows certain tests to pass which otherwise fail.
36+
// Due to fist day of week differences, tests may fail
37+
// certain locales, namely GB.
3938
//
4039
// These tests are:
4140
//
@@ -47,55 +46,58 @@ public void setUp() {
4746
// assertEquals(PeriodicityType.TOP_OF_WEEK, rc.getPeriodicityType());
4847
// }
4948
//
49+
}
5050

51-
Locale oldLocale = Locale.getDefault();
52-
Locale.setDefault(oldLocale);
51+
void set_EN_US_Locale() {
52+
Locale usEn_Locale = Locale.forLanguageTag("en-US");
53+
Locale.setDefault(usEn_Locale);
5354
}
5455

5556
@AfterEach
5657
public void tearDown() {
58+
5759
}
5860

5961
@Test
6062
public void testPeriodicity() {
6163
{
6264
RollingCalendar rc = new RollingCalendar("yyyy-MM-dd_HH_mm_ss");
63-
Assertions.assertEquals(PeriodicityType.TOP_OF_SECOND, rc.getPeriodicityType());
65+
assertEquals(PeriodicityType.TOP_OF_SECOND, rc.getPeriodicityType());
6466
}
6567

6668
{
6769
RollingCalendar rc = new RollingCalendar("yyyy-MM-dd_HH_mm");
68-
Assertions.assertEquals(PeriodicityType.TOP_OF_MINUTE, rc.getPeriodicityType());
70+
assertEquals(PeriodicityType.TOP_OF_MINUTE, rc.getPeriodicityType());
6971
}
7072

7173
{
7274
RollingCalendar rc = new RollingCalendar("yyyy-MM-dd_HH");
73-
Assertions.assertEquals(PeriodicityType.TOP_OF_HOUR, rc.getPeriodicityType());
75+
assertEquals(PeriodicityType.TOP_OF_HOUR, rc.getPeriodicityType());
7476
}
7577

7678
{
7779
RollingCalendar rc = new RollingCalendar("yyyy-MM-dd_hh");
78-
Assertions.assertEquals(PeriodicityType.TOP_OF_HOUR, rc.getPeriodicityType());
80+
assertEquals(PeriodicityType.TOP_OF_HOUR, rc.getPeriodicityType());
7981
}
8082

8183
{
8284
RollingCalendar rc = new RollingCalendar("yyyy-MM-dd");
83-
Assertions.assertEquals(PeriodicityType.TOP_OF_DAY, rc.getPeriodicityType());
85+
assertEquals(PeriodicityType.TOP_OF_DAY, rc.getPeriodicityType());
8486
}
8587

8688
{
8789
RollingCalendar rc = new RollingCalendar("yyyy-MM");
88-
Assertions.assertEquals(PeriodicityType.TOP_OF_MONTH, rc.getPeriodicityType());
90+
assertEquals(PeriodicityType.TOP_OF_MONTH, rc.getPeriodicityType());
8991
}
9092

9193
{
9294
RollingCalendar rc = new RollingCalendar("yyyy-ww");
93-
Assertions.assertEquals(PeriodicityType.TOP_OF_WEEK, rc.getPeriodicityType());
95+
assertEquals(PeriodicityType.TOP_OF_WEEK, rc.getPeriodicityType());
9496
}
9597

9698
{
9799
RollingCalendar rc = new RollingCalendar("yyyy-W");
98-
Assertions.assertEquals(PeriodicityType.TOP_OF_WEEK, rc.getPeriodicityType());
100+
assertEquals(PeriodicityType.TOP_OF_WEEK, rc.getPeriodicityType());
99101
}
100102
}
101103

@@ -109,7 +111,7 @@ public void testVaryingNumberOfHourlyPeriods() {
109111
long now = 1223325293589L; // Mon Oct 06 22:34:53 CEST 2008
110112
Instant result = rc.getEndOfNextNthPeriod(Instant.ofEpochMilli(now), p);
111113
long expected = now - (now % (MILLIS_IN_HOUR)) + p * MILLIS_IN_HOUR;
112-
Assertions.assertEquals(expected, result.toEpochMilli());
114+
assertEquals(expected, result.toEpochMilli());
113115
}
114116
}
115117

@@ -126,7 +128,7 @@ public void testVaryingNumberOfDailyPeriods() {
126128

127129
long origin = now - ((now + offset) % (MILLIS_IN_DAY));
128130
long expected = origin + p * MILLIS_IN_DAY;
129-
Assertions.assertEquals(expected, result.toEpochMilli(), "p=" + p);
131+
assertEquals(expected, result.toEpochMilli(), "p=" + p);
130132
}
131133
}
132134

@@ -147,7 +149,7 @@ public void testBarrierCrossingComputation() {
147149

148150
private void checkPeriodBarriersCrossed(String pattern, long start, long end, int count) {
149151
RollingCalendar rc = new RollingCalendar(pattern);
150-
Assertions.assertEquals(count, rc.periodBarriersCrossed(start, end));
152+
assertEquals(count, rc.periodBarriersCrossed(start, end));
151153
}
152154

153155
@Test
@@ -177,12 +179,20 @@ public void testCollisionFreenes() {
177179
// checkCollisionFreeness("yyyy-MM-uu", false);
178180
// }
179181

180-
// weekly
181-
checkCollisionFreeness("yyyy-MM-W", true);
182-
dumpCurrentLocale(Locale.getDefault());
183-
checkCollisionFreeness("yyyy-W", false);
184-
checkCollisionFreeness("yyyy-ww", true);
185-
checkCollisionFreeness("ww", false);
182+
183+
Locale oldLocale = Locale.getDefault();
184+
try {
185+
set_EN_US_Locale();
186+
// weekly
187+
checkCollisionFreeness("yyyy-MM-W", true);
188+
dumpCurrentLocale(Locale.getDefault());
189+
checkCollisionFreeness("yyyy-W", false);
190+
checkCollisionFreeness("yyyy-ww", true);
191+
checkCollisionFreeness("ww", false);
192+
} finally {
193+
if(oldLocale != null)
194+
Locale.setDefault(oldLocale);
195+
}
186196
}
187197

188198
private void dumpCurrentLocale(Locale locale) {
@@ -192,11 +202,7 @@ private void dumpCurrentLocale(Locale locale) {
192202

193203
private void checkCollisionFreeness(String pattern, boolean expected) {
194204
RollingCalendar rc = new RollingCalendar(pattern);
195-
if (expected) {
196-
Assertions.assertTrue(rc.isCollisionFree());
197-
} else {
198-
Assertions.assertFalse(rc.isCollisionFree());
199-
}
205+
assertEquals(expected, rc.isCollisionFree());
200206
}
201207

202208
@Test
@@ -206,7 +212,7 @@ public void basicPeriodBarriersCrossed() {
206212
long start = 1485456418969L;
207213
// Fri Jan 27 19:46:58 CET 2017, GMT offset = -1h
208214
long end = start + CoreConstants.MILLIS_IN_ONE_DAY;
209-
Assertions.assertEquals(1, rc.periodBarriersCrossed(start, end));
215+
assertEquals(1, rc.periodBarriersCrossed(start, end));
210216
}
211217

212218
@Test
@@ -217,7 +223,7 @@ public void testPeriodBarriersCrossedWhenGoingIntoDaylightSaving() {
217223
// Mon Mar 27 00:02:03 CEST 2017, GMT offset = -2h
218224
long end = 1490565723333L;
219225

220-
Assertions.assertEquals(1, rc.periodBarriersCrossed(start, end));
226+
assertEquals(1, rc.periodBarriersCrossed(start, end));
221227
}
222228

223229
@Test
@@ -227,7 +233,7 @@ public void testPeriodBarriersCrossedWhenLeavingDaylightSaving() {
227233
long start = 1509228123333L;// 1490482923333L+217*CoreConstants.MILLIS_IN_ONE_DAY-CoreConstants.MILLIS_IN_ONE_HOUR;
228234
// Mon Oct 30 00:02:03 CET 2017, GMT offset = -1h
229235
long end = 1509228123333L + 25 * CoreConstants.MILLIS_IN_ONE_HOUR;
230-
Assertions.assertEquals(1, rc.periodBarriersCrossed(start, end));
236+
assertEquals(1, rc.periodBarriersCrossed(start, end));
231237
}
232238

233239
@Test
@@ -240,7 +246,7 @@ public void testPeriodBarriersCrossedJustBeforeEnteringDaylightSaving() {
240246
// Mon Mar 27 00:05:18 CEST 2017, GMT offset = +2h
241247
long end = 1490565918333L;
242248
System.out.println(new Date(end));
243-
Assertions.assertEquals(1, rc.periodBarriersCrossed(start, end));
249+
assertEquals(1, rc.periodBarriersCrossed(start, end));
244250

245251
}
246252
}

0 commit comments

Comments
 (0)