Skip to content

Commit

Permalink
[JSTEP-10] Migrate remaining datetime module tests to JUnit 5 (#348)
Browse files Browse the repository at this point in the history
  • Loading branch information
JooHyukKim authored Jan 27, 2025
1 parent 6d27f26 commit 0b949e8
Show file tree
Hide file tree
Showing 70 changed files with 1,126 additions and 1,177 deletions.
7 changes: 0 additions & 7 deletions datetime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,6 @@
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<!-- 20-Apr-2024, tatu: JUnit4 no longer from jackson-base, so: -->
<!-- TODO, remove this JUnit 4 test dep after JSTEP-10 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.fasterxml.jackson.databind.jsontype.PolymorphicTypeValidator;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;

public class ModuleTestBase
{
protected static final ZoneId UTC = ZoneId.of("UTC");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,46 +1,48 @@
package com.fasterxml.jackson.datatype.jsr310;

import org.junit.Test;

import java.math.BigDecimal;
import java.util.concurrent.TimeUnit;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;

public class TestDecimalUtils extends ModuleTestBase
{
@Test
public void testToDecimal01()
{
String decimal = DecimalUtils.toDecimal(0, 0);
assertEquals("The returned decimal is not correct.", NO_NANOSECS_SER, decimal);
assertEquals(NO_NANOSECS_SER, decimal, "The returned decimal is not correct.");

decimal = DecimalUtils.toDecimal(15, 72);
assertEquals("The returned decimal is not correct.", "15.000000072", decimal);
assertEquals("15.000000072", decimal, "The returned decimal is not correct.");

decimal = DecimalUtils.toDecimal(19827342231L, 192837465);
assertEquals("The returned decimal is not correct.", "19827342231.192837465", decimal);
assertEquals("19827342231.192837465", decimal, "The returned decimal is not correct.");

decimal = DecimalUtils.toDecimal(19827342231L, 0);
assertEquals("The returned decimal is not correct.",
"19827342231"+NO_NANOSECS_SUFFIX, decimal);
assertEquals("19827342231"+NO_NANOSECS_SUFFIX, decimal,
"The returned decimal is not correct.");

decimal = DecimalUtils.toDecimal(19827342231L, 999888000);
assertEquals("The returned decimal is not correct.",
"19827342231.999888000", decimal);
assertEquals("19827342231.999888000", decimal,
"The returned decimal is not correct.");

decimal = DecimalUtils.toDecimal(-22704862, 599000000);
assertEquals("The returned decimal is not correct.",
"-22704862.599000000", decimal);
assertEquals("-22704862.599000000", decimal,
"The returned decimal is not correct.");
}

@SuppressWarnings("deprecation")
private void checkExtractNanos(long expectedSeconds, int expectedNanos, BigDecimal decimal)
{
long seconds = decimal.longValue();
assertEquals("The second part is not correct.", expectedSeconds, seconds);
assertEquals(expectedSeconds, seconds, "The second part is not correct.");

int nanoseconds = DecimalUtils.extractNanosecondDecimal(decimal, seconds);
assertEquals("The nanosecond part is not correct.", expectedNanos, nanoseconds);
assertEquals(expectedNanos, nanoseconds, "The nanosecond part is not correct.");
}

@Test
Expand Down Expand Up @@ -89,8 +91,8 @@ public void testExtractNanosecondDecimal06()
private void checkExtractSecondsAndNanos(long expectedSeconds, int expectedNanos, BigDecimal decimal)
{
DecimalUtils.extractSecondsAndNanos(decimal, (Long s, Integer ns) -> {
assertEquals("The second part is not correct.", expectedSeconds, s.longValue());
assertEquals("The nanosecond part is not correct.", expectedNanos, ns.intValue());
assertEquals(expectedSeconds, s.longValue(), "The second part is not correct.");
assertEquals(expectedNanos, ns.intValue(), "The nanosecond part is not correct.");
return null;
});
}
Expand Down Expand Up @@ -144,7 +146,8 @@ public void testExtractSecondsAndNanosFromNegativeBigDecimal()
checkExtractSecondsAndNanos(-22704862L, 599000000, value);
}

@Test(timeout = 100)
@Timeout(value = 100, unit = TimeUnit.MILLISECONDS)
@Test
public void testExtractSecondsAndNanos07()
{
BigDecimal value = new BigDecimal("1e10000000");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,33 @@

package com.fasterxml.jackson.datatype.jsr310;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.junit.Test;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;

public class TestFeatures
{
@Test
public void testWriteDateTimestampsAsNanosecondsSettingEnabledByDefault()
{
assertTrue("Write date timestamps as nanoseconds setting should be enabled by default.",
SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS.enabledByDefault());
assertTrue(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS.enabledByDefault(),
"Write date timestamps as nanoseconds setting should be enabled by default.");
}

@Test
public void testReadDateTimestampsAsNanosecondsSettingEnabledByDefault()
{
assertTrue("Read date timestamps as nanoseconds setting should be enabled by default.",
DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS.enabledByDefault());
assertTrue(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS.enabledByDefault(),
"Read date timestamps as nanoseconds setting should be enabled by default.");
}

@Test
public void testAdjustDatesToContextTimeZoneSettingEnabledByDefault()
{
assertTrue("Adjust dates to context time zone setting should be enabled by default.",
DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE.enabledByDefault());
assertTrue(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE.enabledByDefault(),
"Adjust dates to context time zone setting should be enabled by default.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import java.time.ZoneId;

import org.junit.Test;

import static org.junit.Assert.assertEquals;
import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.ModuleTestBase;

import static org.junit.jupiter.api.Assertions.*;

public class DefaultTypingTest extends ModuleTestBase
{
private final ObjectMapper TYPING_MAPPER = newMapper();
Expand Down
Loading

0 comments on commit 0b949e8

Please sign in to comment.