Skip to content

Commit add76ac

Browse files
committed
Fix tests failing due to current timezone
1 parent 63bbfe9 commit add76ac

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/test/java/org/springframework/samples/mvc/convert/ConvertControllerTests.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
77
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standaloneSetup;
88

9+
import java.util.Date;
10+
import java.util.TimeZone;
11+
912
import org.junit.Before;
1013
import org.junit.Test;
1114
import org.springframework.format.support.DefaultFormattingConversionService;
@@ -14,6 +17,14 @@
1417

1518
public class ConvertControllerTests {
1619

20+
private static String TIMEZONE;
21+
22+
static {
23+
TimeZone timezone = TimeZone.getDefault();
24+
boolean inDaylight = timezone.inDaylightTime(new Date());
25+
TIMEZONE = TimeZone.getDefault().getDisplayName(inDaylight, TimeZone.SHORT);
26+
}
27+
1728
private MockMvc mockMvc;
1829

1930
@Before
@@ -36,7 +47,7 @@ public void primitive() throws Exception {
3647
@Test
3748
public void date() throws Exception {
3849
this.mockMvc.perform(get("/convert/date/2010-07-04"))
39-
.andExpect(content().string("Converted date Sun Jul 04 00:00:00 EDT 2010"));
50+
.andExpect(content().string("Converted date Sun Jul 04 00:00:00 " + TIMEZONE + " 2010"));
4051
}
4152

4253
@Test
@@ -54,7 +65,9 @@ public void collection2() throws Exception {
5465
@Test
5566
public void formattedCollection() throws Exception {
5667
this.mockMvc.perform(get("/convert/formattedCollection?values=2010-07-04,2011-07-04"))
57-
.andExpect(content().string("Converted formatted collection [Sun Jul 04 00:00:00 EDT 2010, Mon Jul 04 00:00:00 EDT 2011]"));
68+
.andExpect(content().string(
69+
"Converted formatted collection [Sun Jul 04 00:00:00 "
70+
+ TIMEZONE + " 2010, Mon Jul 04 00:00:00 " + TIMEZONE + " 2011]"));
5871
}
5972

6073
@Test
@@ -79,7 +92,7 @@ public void beanPrimitive() throws Exception {
7992
@Test
8093
public void beanDate() throws Exception {
8194
this.mockMvc.perform(get("/convert/bean?date=2010-07-04"))
82-
.andExpect(content().string("Converted JavaBean date=Sun Jul 04 00:00:00 EDT 2010"));
95+
.andExpect(content().string("Converted JavaBean date=Sun Jul 04 00:00:00 " + TIMEZONE + " 2010"));
8396
}
8497

8598
@Test
@@ -98,7 +111,8 @@ public void beanCollection() throws Exception {
98111
public void beanFormattedCollection() throws Exception {
99112
this.mockMvc.perform(get("/convert/bean?formattedList[0]=2010-07-04&formattedList[1]=2011-07-04"))
100113
.andExpect(content().string(
101-
"Converted JavaBean formattedList=[Sun Jul 04 00:00:00 EDT 2010, Mon Jul 04 00:00:00 EDT 2011]"));
114+
"Converted JavaBean formattedList=[Sun Jul 04 00:00:00 " + TIMEZONE
115+
+ " 2010, Mon Jul 04 00:00:00 " + TIMEZONE + " 2011]"));
102116
}
103117

104118
@Test

src/test/resources/log4j.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
</logger>
3030

3131
<logger name="org.springframework.web">
32-
<level value="info" />
32+
<level value="debug" />
3333
</logger>
3434

3535
<!-- Root Logger -->

0 commit comments

Comments
 (0)