Skip to content

Commit

Permalink
Minor test simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Oct 30, 2024
1 parent 0268305 commit 646b6fe
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ public WrapperWithReadTimestampsAsNanosEnabled() { }

@Test
public void testDeserializationAsFloat01() throws Exception {
assertEquals("The value is not correct.", Instant.ofEpochSecond(0L),
assertEquals(Instant.ofEpochSecond(0L),
READER.readValue("0.000000000"));
}

@Test
public void testDeserializationAsFloat02() throws Exception {
assertEquals("The value is not correct.", Instant.ofEpochSecond(123456789L, 183917322),
assertEquals(Instant.ofEpochSecond(123456789L, 183917322),
READER.readValue("123456789.183917322"));
}

Expand All @@ -107,7 +107,7 @@ public void testDeserializationAsFloat03() throws Exception
Instant date = Instant.now();
Instant value = READER.readValue(
DecimalUtils.toDecimal(date.getEpochSecond(), date.getNano()));
assertEquals("The value is not correct.", date, value);
assertEquals(date, value);
}

/**
Expand Down Expand Up @@ -230,7 +230,7 @@ public void testDeserializationAsInt01Nanoseconds() throws Exception
Instant value = READER
.with(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS)
.readValue("0");
assertEquals("The value is not correct.", date, value);
assertEquals(date, value);
}

@Test
Expand All @@ -241,7 +241,7 @@ public void testDeserializationAsInt02Nanoseconds() throws Exception
Instant value = READER
.with(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS)
.readValue(String.valueOf(ts));
assertEquals("The value is not correct.", date, value);
assertEquals(date, value);
}

@Test
Expand All @@ -253,7 +253,7 @@ public void testDeserializationAsInt03Nanoseconds() throws Exception
Instant value = READER
.with(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS)
.readValue(Long.toString(date.getEpochSecond()));
assertEquals("The value is not correct.", date, value);
assertEquals(date, value);
}

@Test
Expand All @@ -266,7 +266,7 @@ public void testDeserializationAsInt04Nanoseconds() throws Exception
new WrapperWithReadTimestampsAsNanosEnabled(date);
WrapperWithReadTimestampsAsNanosEnabled actual = reader.readValue(
a2q("{'value':" + date.getEpochSecond() + "}"));
assertEquals("The value is not correct.", expected.value, actual.value);
assertEquals(expected.value, actual.value);
}

/*
Expand All @@ -282,7 +282,7 @@ public void testDeserializationAsInt01Milliseconds() throws Exception
Instant value = READER
.without(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS)
.readValue("0");
assertEquals("The value is not correct.", date, value);
assertEquals(date, value);
}

@Test
Expand All @@ -292,7 +292,7 @@ public void testDeserializationAsInt02Milliseconds() throws Exception
Instant value = READER
.without(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS)
.readValue("123456789422");
assertEquals("The value is not correct.", date, value);
assertEquals(date, value);
}

@Test
Expand All @@ -304,7 +304,7 @@ public void testDeserializationAsInt03Milliseconds() throws Exception
Instant value = READER
.without(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS)
.readValue(Long.toString(date.toEpochMilli()));
assertEquals("The value is not correct.", date, value);
assertEquals(date, value);
}

@Test
Expand All @@ -317,7 +317,7 @@ public void testDeserializationAsInt04Milliseconds() throws Exception
new WrapperWithReadTimestampsAsNanosDisabled(date);
WrapperWithReadTimestampsAsNanosDisabled actual = reader.readValue(
a2q("{'value':" + date.toEpochMilli() + "}"));
assertEquals("The value is not correct.", expected.value, actual.value);
assertEquals(expected.value, actual.value);
}

/*
Expand All @@ -331,15 +331,15 @@ public void testDeserializationAsString01() throws Exception
{
Instant date = Instant.ofEpochSecond(0L);
Instant value = READER.readValue('"' + FORMATTER.format(date) + '"');
assertEquals("The value is not correct.", date, value);
assertEquals(date, value);
}

@Test
public void testDeserializationAsString02() throws Exception
{
Instant date = Instant.ofEpochSecond(123456789L, 183917322);
Instant value = READER.readValue('"' + FORMATTER.format(date) + '"');
assertEquals("The value is not correct.", date, value);
assertEquals(date, value);
}

@Test
Expand All @@ -348,7 +348,7 @@ public void testDeserializationAsString03() throws Exception
Instant date = Instant.now();

Instant value = READER.readValue('"' + FORMATTER.format(date) + '"');
assertEquals("The value is not correct.", date, value);
assertEquals(date, value);
}

/*
Expand All @@ -367,7 +367,7 @@ public void testDeserializationWithTypeInfo01() throws Exception
"[\"" + Instant.class.getName() + "\",123456789.183917322]", Temporal.class
);
assertTrue("The value should be an Instant.", value instanceof Instant);
assertEquals("The value is not correct.", date, value);
assertEquals(date, value);
}

@Test
Expand All @@ -381,7 +381,7 @@ public void testDeserializationWithTypeInfo02() throws Exception
"[\"" + Instant.class.getName() + "\",123456789]", Temporal.class
);
assertTrue("The value should be an Instant.", value instanceof Instant);
assertEquals("The value is not correct.", date, value);
assertEquals(date, value);
}

@Test
Expand All @@ -396,7 +396,7 @@ public void testDeserializationWithTypeInfo03() throws Exception
);

assertTrue("The value should be an Instant.", value instanceof Instant);
assertEquals("The value is not correct.", date, value);
assertEquals(date, value);
}

@Test
Expand All @@ -409,7 +409,7 @@ public void testDeserializationWithTypeInfo04() throws Exception
"[\"" + Instant.class.getName() + "\",\"" + FORMATTER.format(date) + "\"]", Temporal.class
);
assertTrue("The value should be an Instant.", value instanceof Instant);
assertEquals("The value is not correct.", date, value);
assertEquals(date, value);
}

/*
Expand Down Expand Up @@ -462,23 +462,23 @@ public void testDeserializationFromStringWithZeroZoneOffset01() throws Exception
Instant date = Instant.now();
String json = formatWithZeroZoneOffset(date, "+00:00");
Instant result = READER.readValue(json);
assertEquals("The value is not correct.", date, result);
assertEquals(date, result);
}

@Test
public void testDeserializationFromStringWithZeroZoneOffset02() throws Exception {
Instant date = Instant.now();
String json = formatWithZeroZoneOffset(date, "+0000");
Instant result = READER.readValue(json);
assertEquals("The value is not correct.", date, result);
assertEquals(date, result);
}

@Test
public void testDeserializationFromStringWithZeroZoneOffset03() throws Exception {
Instant date = Instant.now();
String json = formatWithZeroZoneOffset(date, "+00");
Instant result = READER.readValue(json);
assertEquals("The value is not correct.", date, result);
assertEquals(date, result);
}

@Test
Expand All @@ -487,7 +487,7 @@ public void testDeserializationFromStringWithZeroZoneOffset04() throws Exception
Instant date = Instant.now();
String json = formatWithZeroZoneOffset(date, "+00:30");
Instant result = READER.readValue(json);
assertNotEquals("The value is not correct.", date, result);
assertNotEquals(date, result);
}

@Test
Expand All @@ -496,7 +496,7 @@ public void testDeserializationFromStringWithZeroZoneOffset05() throws Exception
Instant date = Instant.now();
String json = formatWithZeroZoneOffset(date, "+01:30");
Instant result = READER.readValue(json);
assertNotEquals("The value is not correct.", date, result);
assertNotEquals(date, result);
}

@Test
Expand All @@ -505,7 +505,7 @@ public void testDeserializationFromStringWithZeroZoneOffset06() throws Exception
Instant date = Instant.now();
String json = formatWithZeroZoneOffset(date, "-00:00");
Instant result = READER.readValue(json);
assertEquals("The value is not correct.", date, result);
assertEquals(date, result);
}

private String formatWithZeroZoneOffset(Instant date, String offset){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public void ZonedDateTime_with_zone_name_can_be_deserialized() throws Exception
assertEquals("2015-07-24T12:23:34.184Z[UTC]", entry.getKey().toString());
}

// 29-Oct-2024, tatu: Following two tests are for Java 8+ only vs Java 9 or later

@Test
public void ZonedDateTime_with_place_name_can_be_deserialized() throws Exception {
assumeFalse(System.getProperty("java.version").startsWith("1.8"));
Expand Down
Loading

0 comments on commit 646b6fe

Please sign in to comment.