@@ -54,20 +54,13 @@ public class HeaderAssertionTests {
54
54
55
55
private final long currentTime = System .currentTimeMillis ();
56
56
57
- private String currentDate ;
58
-
59
- private SimpleDateFormat dateFormat ;
60
-
61
57
private MockMvc mockMvc ;
62
58
63
59
private PersonController personController ;
64
60
65
61
66
62
@ Before
67
63
public void setup () {
68
- this .dateFormat = new SimpleDateFormat ("EEE, dd MMM yyyy HH:mm:ss z" , Locale .US );
69
- this .dateFormat .setTimeZone (TimeZone .getTimeZone ("GMT" ));
70
- this .currentDate = dateFormat .format (currentTime );
71
64
this .personController = new PersonController ();
72
65
this .personController .setStubTimestamp (currentTime );
73
66
this .mockMvc = standaloneSetup (this .personController ).build ();
@@ -76,19 +69,19 @@ public void setup() {
76
69
@ Test
77
70
public void stringWithCorrectResponseHeaderValue () throws Exception {
78
71
this .mockMvc .perform (get ("/persons/1" ).header (IF_MODIFIED_SINCE , currentTime - (1000 * 60 )))//
79
- .andExpect (header ().string (LAST_MODIFIED , currentDate ));
72
+ .andExpect (header ().string (LAST_MODIFIED , String . valueOf ( currentTime ) ));
80
73
}
81
74
82
75
@ Test
83
76
public void stringWithMatcherAndCorrectResponseHeaderValue () throws Exception {
84
77
this .mockMvc .perform (get ("/persons/1" ).header (IF_MODIFIED_SINCE , currentTime - (1000 * 60 )))//
85
- .andExpect (header ().string (LAST_MODIFIED , equalTo (currentDate )));
78
+ .andExpect (header ().string (LAST_MODIFIED , equalTo (String . valueOf ( currentTime ) )));
86
79
}
87
80
88
81
@ Test
89
82
public void longValueWithCorrectResponseHeaderValue () throws Exception {
90
83
this .mockMvc .perform (get ("/persons/1" ).header (IF_MODIFIED_SINCE , currentTime - (1000 * 60 )))//
91
- .andExpect (header ().string (LAST_MODIFIED , currentDate ));
84
+ .andExpect (header ().longValue (LAST_MODIFIED , currentTime ));
92
85
}
93
86
94
87
@ Test
@@ -141,20 +134,20 @@ public void doesNotExistFail() throws Exception {
141
134
@ Test
142
135
public void stringWithIncorrectResponseHeaderValue () throws Exception {
143
136
long unexpected = currentTime + 1000 ;
144
- assertIncorrectResponseHeaderValue (header ().string (LAST_MODIFIED , dateFormat . format (unexpected )), unexpected );
137
+ assertIncorrectResponseHeaderValue (header ().string (LAST_MODIFIED , String . valueOf (unexpected )), unexpected );
145
138
}
146
139
147
140
@ Test
148
141
public void stringWithMatcherAndIncorrectResponseHeaderValue () throws Exception {
149
142
long unexpected = currentTime + 1000 ;
150
- assertIncorrectResponseHeaderValue (header ().string (LAST_MODIFIED , equalTo (dateFormat . format (unexpected ))),
143
+ assertIncorrectResponseHeaderValue (header ().string (LAST_MODIFIED , equalTo (String . valueOf (unexpected ))),
151
144
unexpected );
152
145
}
153
146
154
147
@ Test
155
148
public void longValueWithIncorrectResponseHeaderValue () throws Exception {
156
149
long unexpected = currentTime + 1000 ;
157
- assertIncorrectResponseHeaderValue (header ().string (LAST_MODIFIED , dateFormat . format ( unexpected ) ), unexpected );
150
+ assertIncorrectResponseHeaderValue (header ().longValue (LAST_MODIFIED , unexpected ), unexpected );
158
151
}
159
152
160
153
private void assertIncorrectResponseHeaderValue (ResultMatcher resultMatcher , long unexpected ) throws Exception {
@@ -173,8 +166,8 @@ private void assertIncorrectResponseHeaderValue(ResultMatcher resultMatcher, lon
173
166
// We don't use assertEquals() since we cannot control the formatting
174
167
// produced by JUnit or Hamcrest.
175
168
assertMessageContains (e , "Response header " + LAST_MODIFIED );
176
- assertMessageContains (e , dateFormat . format (unexpected ));
177
- assertMessageContains (e , currentDate );
169
+ assertMessageContains (e , String . valueOf (unexpected ));
170
+ assertMessageContains (e , String . valueOf ( currentTime ) );
178
171
}
179
172
}
180
173
0 commit comments