Skip to content

Commit 1b82082

Browse files
committed
test refactoring
1 parent 26827c5 commit 1b82082

17 files changed

+59
-59
lines changed

datetime/src/test/java/com/fasterxml/jackson/datatype/jsr310/ModuleTestBase.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ protected static JsonMapper.Builder mapperBuilder() {
3737
.addModule(new JavaTimeModule());
3838
}
3939

40-
protected String quote(String value) {
40+
protected String q(String value) {
4141
return "\"" + value + "\"";
4242
}
4343

44-
protected String aposToQuotes(String json) {
44+
protected String a2q(String json) {
4545
return json.replace("'", "\"");
4646
}
4747

datetime/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestOffsetDateTimeDeserialization.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ public void testDeserializationAsString01() throws Exception
3939
{
4040
assertEquals("The value is not correct.",
4141
OffsetDateTime.of(2000, 1, 1, 12, 0, 0, 0, ZoneOffset.UTC),
42-
READER.readValue(quote("2000-01-01T12:00Z")));
42+
READER.readValue(q("2000-01-01T12:00Z")));
4343
}
4444

4545
@Test
4646
public void testDeserializationAsString02() throws Exception
4747
{
4848
assertEquals("The value is not correct.",
4949
OffsetDateTime.of(2000, 1, 1, 7, 0, 0, 0, ZoneOffset.UTC),
50-
READER.readValue(quote("2000-01-01T12:00+05:00")));
50+
READER.readValue(q("2000-01-01T12:00+05:00")));
5151
}
5252

5353
// [modules-java8#34]
@@ -56,7 +56,7 @@ public void testDeserializationWithShortFraction() throws Exception
5656
{
5757
assertEquals("The value is not correct.",
5858
OffsetDateTime.of(2017, 7, 25, 20, 22, 58, 800_000_000, ZoneOffset.UTC),
59-
READER.readValue(quote("2017-07-25T20:22:58.8Z")));
59+
READER.readValue(q("2017-07-25T20:22:58.8Z")));
6060
}
6161

6262
@Test
@@ -66,7 +66,7 @@ public void testDeserializationAsString03() throws Exception
6666
// Verify that the offset in the json is preserved when we disable ADJUST_DATES_TO_CONTEXT_TIME_ZONE
6767
//
6868
ObjectReader reader2 = newMapper().disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE).readerFor(OffsetDateTime.class);
69-
OffsetDateTime parsed = reader2.readValue(aposToQuotes("'2000-01-01T12:00+05:00'"));
69+
OffsetDateTime parsed = reader2.readValue(a2q("'2000-01-01T12:00+05:00'"));
7070
assertEquals("The value is not correct.",
7171
OffsetDateTime.of(2000, 1, 1, 12, 0, 0, 0, ZoneOffset.ofHours(5)), parsed) ;
7272
}
@@ -94,31 +94,31 @@ public void testDeserializationWithoutContextTimezoneFeatureOverride() throws Ex
9494
@Test
9595
public void testBadDeserializationAsString01() throws Throwable
9696
{
97-
expectFailure(quote("notanoffsetdatetime"));
97+
expectFailure(q("notanoffsetdatetime"));
9898
}
9999

100100
@Test
101101
public void testDeserializationAsWithZeroZoneOffset01() throws Exception
102102
{
103103
assertEquals("The value is not correct.",
104104
OffsetDateTime.of(2000, 1, 1, 12, 0, 0, 0, ZoneOffset.UTC),
105-
READER.readValue(quote("2000-01-01T12:00+00:00")));
105+
READER.readValue(q("2000-01-01T12:00+00:00")));
106106
}
107107

108108
@Test
109109
public void testDeserializationAsWithZeroZoneOffset02() throws Exception
110110
{
111111
assertEquals("The value is not correct.",
112112
OffsetDateTime.of(2000, 1, 1, 12, 0, 0, 0, ZoneOffset.UTC),
113-
READER.readValue(quote("2000-01-01T12:00+0000")));
113+
READER.readValue(q("2000-01-01T12:00+0000")));
114114
}
115115

116116
@Test
117117
public void testDeserializationAsWithZeroZoneOffset03() throws Exception
118118
{
119119
assertEquals("The value is not correct.",
120120
OffsetDateTime.of(2000, 1, 1, 12, 0, 0, 0, ZoneOffset.UTC),
121-
READER.readValue(quote("2000-01-01T12:00+00")));
121+
READER.readValue(q("2000-01-01T12:00+00")));
122122
}
123123

124124
@Test
@@ -170,13 +170,13 @@ public void testDeserializationAsEmptyArrayEnabled() throws Throwable
170170
OffsetDateTime value = READER
171171
.with(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)
172172
.with(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT)
173-
.readValue(aposToQuotes(json));
173+
.readValue(a2q(json));
174174
assertNull(value);
175175
}
176176

177177
private void expectFailure(String json) throws Exception {
178178
try {
179-
READER.readValue(aposToQuotes(json));
179+
READER.readValue(a2q(json));
180180
fail("expected JsonMappingException");
181181
} catch (JsonMappingException e) {
182182
Throwable t = e.getCause();

datetime/src/test/java/com/fasterxml/jackson/datatype/jsr310/deser/DurationDeserTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ public void testDeserializationAsEmptyArrayDisabled() throws Throwable
354354
try {
355355
newMapper()
356356
.configure(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS, true)
357-
.readerFor(Duration.class).readValue(aposToQuotes("[]"));
357+
.readerFor(Duration.class).readValue(a2q("[]"));
358358
fail("expected MismatchedInputException");
359359
} catch (MismatchedInputException e) {
360360
verifyException(e, "Cannot deserialize value of type `java.time.Duration` from Array value");
@@ -378,7 +378,7 @@ public void testDeserializationAsEmptyArrayEnabled() throws Throwable
378378
Duration value= newMapper()
379379
.configure(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS, true)
380380
.configure(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT, true)
381-
.readerFor(Duration.class).readValue(aposToQuotes(json));
381+
.readerFor(Duration.class).readValue(a2q(json));
382382
assertNull(value);
383383
}
384384

datetime/src/test/java/com/fasterxml/jackson/datatype/jsr310/deser/InstantDeserTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ public void testCustomPatternWithAnnotations01() throws Exception
374374
{
375375
final Wrapper input = new Wrapper(Instant.ofEpochMilli(0));
376376
String json = MAPPER.writeValueAsString(input);
377-
assertEquals(aposToQuotes("{'value':'1970-01-01T00:00:00Z'}"), json);
377+
assertEquals(a2q("{'value':'1970-01-01T00:00:00Z'}"), json);
378378

379379
Wrapper result = MAPPER.readValue(json, Wrapper.class);
380380
assertEquals(input.value, result.value);
@@ -394,7 +394,7 @@ public void testCustomPatternWithAnnotations02() throws Exception
394394
String json = MAPPER.writeValueAsString(input);
395395

396396
assertTrue("Instant in UTC timezone was not serialized as expected.",
397-
json.contains(aposToQuotes("'valueInUTC':'" + valueInUTC + "'")));
397+
json.contains(a2q("'valueInUTC':'" + valueInUTC + "'")));
398398

399399
WrapperWithCustomPattern result = MAPPER.readValue(json, WrapperWithCustomPattern.class);
400400
assertEquals("Instant in UTC timezone was not deserialized as expected.",

datetime/src/test/java/com/fasterxml/jackson/datatype/jsr310/deser/LocalDateDeserTest.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public void testDeserializationAsTimestamp02() throws Exception
9595
public void testDeserializationAsString01() throws Exception
9696
{
9797
assertEquals("The value is not correct.", LocalDate.of(2000, Month.JANUARY, 1),
98-
READER.readValue(quote("2000-01-01")));
98+
READER.readValue(q("2000-01-01")));
9999

100100
LocalDate date = LocalDate.of(1986, Month.JANUARY, 17);
101101
assertEquals("The value is not correct.", date,
@@ -128,7 +128,7 @@ public void testDeserializationAsString03() throws Exception
128128
public void testBadDeserializationAsString01() throws Throwable
129129
{
130130
try {
131-
READER.readValue(quote("notalocaldate"));
131+
READER.readValue(q("notalocaldate"));
132132
fail("Should not pass");
133133
} catch (MismatchedInputException e) {
134134
verifyException(e, "Cannot deserialize value of type");
@@ -140,7 +140,7 @@ public void testBadDeserializationAsString01() throws Throwable
140140
public void testBadDeserializationAsString02() throws Exception
141141
{
142142
try {
143-
READER.readValue(quote("2015-06-19TShouldNotParse"));
143+
READER.readValue(q("2015-06-19TShouldNotParse"));
144144
fail("Should not pass");
145145
} catch (JsonMappingException e) {
146146
verifyException(e, "Cannot deserialize value of type");
@@ -423,7 +423,7 @@ public void testStrictDeserializeFromString() throws Exception
423423
*/
424424
private void expectFailure(ObjectReader reader, String json) throws Throwable {
425425
try {
426-
reader.readValue(aposToQuotes(json));
426+
reader.readValue(a2q(json));
427427
fail("expected DateTimeParseException");
428428
} catch (JsonProcessingException e) {
429429
if (e.getCause() == null) {
@@ -436,7 +436,7 @@ private void expectFailure(ObjectReader reader, String json) throws Throwable {
436436
}
437437

438438
private void expectSuccess(ObjectReader reader, Object exp, String json) throws IOException {
439-
final LocalDate value = reader.readValue(aposToQuotes(json));
439+
final LocalDate value = reader.readValue(a2q(json));
440440
assertNotNull("The value should not be null.", value);
441441
assertEquals("The value is not correct.", exp, value);
442442
}

datetime/src/test/java/com/fasterxml/jackson/datatype/jsr310/deser/LocalDateTimeDeserTest.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,12 @@ public void testDeserializationAsTimestamp04Milliseconds02() throws Exception
143143
public void testDeserializationAsString01() throws Exception
144144
{
145145
LocalDateTime exp = LocalDateTime.of(1986, Month.JANUARY, 17, 15, 43);
146-
LocalDateTime value = READER.readValue(quote(exp.toString()));
146+
LocalDateTime value = READER.readValue(q(exp.toString()));
147147
assertEquals("The value is not correct.", exp, value);
148148

149149
assertEquals("The value is not correct.",
150150
LocalDateTime.of(2000, Month.JANUARY, 1, 12, 0),
151-
READER.readValue(quote("2000-01-01T12:00")));
151+
READER.readValue(q("2000-01-01T12:00")));
152152
}
153153

154154
@Test
@@ -172,7 +172,7 @@ public void testDeserializationAsString03() throws Exception
172172
public void testBadDeserializationOfTimeWithTimeZone() throws Exception
173173
{
174174
try {
175-
MAPPER.readValue(quote("2020-10-22T00:16:20.504Z"), LocalDateTime.class);
175+
MAPPER.readValue(q("2020-10-22T00:16:20.504Z"), LocalDateTime.class);
176176
fail("expected fail");
177177
} catch (InvalidFormatException e) {
178178
verifyException(e, "Invalid value");
@@ -184,7 +184,7 @@ public void testBadDeserializationOfTimeWithTimeZone() throws Exception
184184
public void testBadDeserializationAsString01() throws Throwable
185185
{
186186
try {
187-
READER.readValue(quote("notalocaldatetime"));
187+
READER.readValue(q("notalocaldatetime"));
188188
fail("expected fail");
189189
} catch (InvalidFormatException e) {
190190
verifyException(e, "Cannot deserialize value of type");
@@ -354,7 +354,7 @@ public Object handleWeirdStringValue(DeserializationContext ctxt, Class<?> targe
354354
}
355355
};
356356
ObjectMapper handledMapper = mapperBuilder().addHandler(handler).build();
357-
assertEquals(now, handledMapper.readValue(quote("now"), LocalDateTime.class));
357+
assertEquals(now, handledMapper.readValue(q("now"), LocalDateTime.class));
358358
}
359359

360360
@Test
@@ -497,14 +497,14 @@ public void testStrictCustomFormatInvalidDateAndTime() throws Exception
497497
}
498498

499499
private void expectSuccess(ObjectReader reader, Object exp, String json) throws IOException {
500-
final LocalDateTime value = reader.readValue(aposToQuotes(json));
500+
final LocalDateTime value = reader.readValue(a2q(json));
501501
assertNotNull("The value should not be null.", value);
502502
assertEquals("The value is not correct.", exp, value);
503503
}
504504

505505
private void expectFailure(ObjectReader reader, String json) throws Throwable {
506506
try {
507-
reader.readValue(aposToQuotes(json));
507+
reader.readValue(a2q(json));
508508
fail("expected DateTimeParseException");
509509
} catch (JsonProcessingException e) {
510510
if (e.getCause() == null) {

datetime/src/test/java/com/fasterxml/jackson/datatype/jsr310/deser/LocalTimeDeserTest.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public void testBadDeserializationFromString() throws Throwable
147147
public void testDeserializationAsArrayDisabled() throws Throwable
148148
{
149149
try {
150-
reader.readValue(aposToQuotes("['12:00']"));
150+
reader.readValue(a2q("['12:00']"));
151151
fail("expected MismatchedInputException");
152152
} catch (MismatchedInputException e) {
153153
verifyException(e, "Unexpected token (VALUE_STRING) within Array");
@@ -163,7 +163,7 @@ public void testDeserializationAsArrayEnabled() throws Throwable
163163
{
164164
LocalTime value= newMapper()
165165
.configure(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS, true)
166-
.readerFor(LocalTime.class).readValue(aposToQuotes("['12:00']"));
166+
.readerFor(LocalTime.class).readValue(a2q("['12:00']"));
167167
expect(LocalTime.of(12, 0), value);
168168
}
169169

@@ -173,7 +173,7 @@ public void testDeserializationAsEmptyArrayEnabled() throws Throwable
173173
LocalTime value= newMapper()
174174
.configure(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS, true)
175175
.configure(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT, true)
176-
.readerFor(LocalTime.class).readValue(aposToQuotes("[]"));
176+
.readerFor(LocalTime.class).readValue(a2q("[]"));
177177
assertNull(value);
178178
}
179179

@@ -285,7 +285,7 @@ public void testStrictCustomFormatInvalidTime() throws Exception
285285

286286
private void expectFailure(String aposJson) throws Throwable {
287287
try {
288-
reader.readValue(aposToQuotes(aposJson));
288+
reader.readValue(a2q(aposJson));
289289
fail("expected DateTimeParseException");
290290
} catch (JsonProcessingException e) {
291291
if (e.getCause() == null) {
@@ -298,7 +298,7 @@ private void expectFailure(String aposJson) throws Throwable {
298298
}
299299

300300
private void expectSuccess(Object exp, String aposJson) throws IOException {
301-
final LocalTime value = reader.readValue(aposToQuotes(aposJson));
301+
final LocalTime value = reader.readValue(a2q(aposJson));
302302
notNull(value);
303303
expect(exp, value);
304304
}

datetime/src/test/java/com/fasterxml/jackson/datatype/jsr310/deser/MonthDayDeserTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void testDeserializationAsArrayEnabled() throws Throwable
9393
{
9494
MonthDay value = newMapper()
9595
.configure(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS, true)
96-
.readerFor(MonthDay.class).readValue(aposToQuotes("['--01-01']"));
96+
.readerFor(MonthDay.class).readValue(a2q("['--01-01']"));
9797
notNull(value);
9898
expect(MonthDay.of(Month.JANUARY, 1), value);
9999
}
@@ -216,7 +216,7 @@ private void expectSuccess(Object exp, String aposJson) throws IOException {
216216
}
217217

218218
private MonthDay read(final String aposJson) throws IOException {
219-
return READER.readValue(aposToQuotes(aposJson));
219+
return READER.readValue(a2q(aposJson));
220220
}
221221

222222
private static void notNull(Object value) {

datetime/src/test/java/com/fasterxml/jackson/datatype/jsr310/deser/OffsetDateTimeDeserTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ public void testCustomPatternWithAnnotations() throws Exception
591591
final Wrapper input = new Wrapper(inputValue);
592592
final ObjectMapper m = newMapper();
593593
String json = m.writeValueAsString(input);
594-
assertEquals(aposToQuotes("{'value':'1970_01_01T00:00:00+0000'}"), json);
594+
assertEquals(a2q("{'value':'1970_01_01T00:00:00+0000'}"), json);
595595

596596
Wrapper result = m.readValue(json, Wrapper.class);
597597
assertEquals(input.value, result.value);

datetime/src/test/java/com/fasterxml/jackson/datatype/jsr310/deser/OffsetTimeDeserTest.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public void testDeserializationFromString01() throws Exception
146146
@Test
147147
public void testBadDeserializationFromString01() throws Throwable
148148
{
149-
expectFailure(quote("notanoffsettime"));
149+
expectFailure(q("notanoffsettime"));
150150
}
151151

152152
@Test
@@ -201,7 +201,7 @@ public void testDeserializationWithTypeInfo03() throws Exception
201201
@Test
202202
public void testDeserOfArrayOf() throws Exception
203203
{
204-
final String JSON = aposToQuotes
204+
final String JSON = a2q
205205
("{'name':'test','objects':[{'partDate':[2015,10,13],'starttime':[15,7,'+0'],'endtime':[2,14,'+0'],'comments':'in the comments'}]}");
206206
Pojo45s result = READER.forType(Pojo45s.class).readValue(JSON);
207207
assertNotNull(result);
@@ -231,7 +231,7 @@ public void testDeserializationAsEmptyArrayDisabled() throws Throwable
231231
public void testDeserializationAsArrayEnabled() throws Throwable
232232
{
233233
OffsetTime value = READER.with(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)
234-
.readValue(aposToQuotes("['12:00Z']"));
234+
.readValue(a2q("['12:00Z']"));
235235
expect(OffsetTime.of(12, 0, 0, 0, ZoneOffset.UTC), value);
236236
}
237237

@@ -307,7 +307,7 @@ private void expectSuccess(Object exp, String json) throws IOException {
307307
}
308308

309309
private OffsetTime read(final String json) throws IOException {
310-
return READER.readValue(aposToQuotes(json));
310+
return READER.readValue(a2q(json));
311311
}
312312

313313
private static void notNull(Object value) {

datetime/src/test/java/com/fasterxml/jackson/datatype/jsr310/deser/YearDeserTest.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ public FormattedYear(Year year) {
6363
public void testDeserializationAsString01() throws Exception
6464
{
6565
assertEquals("The value is not correct.",Year.of(2000),
66-
READER.readValue(quote("2000")));
66+
READER.readValue(q("2000")));
6767
}
6868

6969
@Test
7070
public void testBadDeserializationAsString01() throws Throwable
7171
{
72-
expectFailure(quote("notayear"));
72+
expectFailure(q("notayear"));
7373
}
7474

7575
@Test
@@ -100,7 +100,7 @@ public void testDeserializationAsEmptyArrayDisabled() throws Throwable
100100
String json="[]";
101101
newMapper()
102102
.configure(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS, true)
103-
.readerFor(Year.class).readValue(aposToQuotes(json));
103+
.readerFor(Year.class).readValue(a2q(json));
104104
fail("expected JsonMappingException");
105105
} catch (JsonMappingException e) {
106106
// OK
@@ -125,7 +125,7 @@ public void testDeserializationAsEmptyArrayEnabled() throws Throwable
125125
Year value= newMapper()
126126
.configure(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS, true)
127127
.configure(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT, true)
128-
.readerFor(Year.class).readValue(aposToQuotes(json));
128+
.readerFor(Year.class).readValue(a2q(json));
129129
assertNull(value);
130130
}
131131

@@ -253,7 +253,7 @@ public void testDeserializeFromEmptyString() throws Exception
253253
*/
254254

255255
private Year read(final String json) throws IOException {
256-
return READER.readValue(aposToQuotes(json));
256+
return READER.readValue(a2q(json));
257257
}
258258

259259
private void expectFailure(String json) throws Throwable {

0 commit comments

Comments
 (0)