From fbdef656b86a4143b545fce20b9320574f3d6a2c Mon Sep 17 00:00:00 2001 From: Benedetta-fabbri Date: Thu, 16 Jan 2025 16:46:48 +0100 Subject: [PATCH] added junit --- ...ateTimeToOffsetDateTimeSerializerTest.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/test/java/it/gov/pagopa/pu/organization/config/LocalDateTimeToOffsetDateTimeSerializerTest.java diff --git a/src/test/java/it/gov/pagopa/pu/organization/config/LocalDateTimeToOffsetDateTimeSerializerTest.java b/src/test/java/it/gov/pagopa/pu/organization/config/LocalDateTimeToOffsetDateTimeSerializerTest.java new file mode 100644 index 0000000..7c08743 --- /dev/null +++ b/src/test/java/it/gov/pagopa/pu/organization/config/LocalDateTimeToOffsetDateTimeSerializerTest.java @@ -0,0 +1,48 @@ +package it.gov.pagopa.pu.organization.config; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import it.gov.pagopa.pu.organization.config.json.LocalDateTimeToOffsetDateTimeSerializer; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.io.IOException; +import java.time.LocalDateTime; + +import static org.mockito.Mockito.*; + +@ExtendWith(MockitoExtension.class) +class LocalDateTimeToOffsetDateTimeSerializerTest { + + @Mock + private JsonGenerator jsonGenerator; + + @Mock + private SerializerProvider serializerProvider; + + private LocalDateTimeToOffsetDateTimeSerializer dateTimeSerializer; + + @BeforeEach + public void setUp() { + dateTimeSerializer = new LocalDateTimeToOffsetDateTimeSerializer(); + } + + @Test + void testDateSerializer() throws IOException { + LocalDateTime localDateTime = LocalDateTime.of(2025, 1, 16, 9, 15,20); + + dateTimeSerializer.serialize(localDateTime, jsonGenerator, serializerProvider); + + verify(jsonGenerator).writeString("2025-01-16T09:15:20+01:00"); + } + + @Test + void testNullDateSerializer() throws IOException { + dateTimeSerializer.serialize(null, jsonGenerator, serializerProvider); + + verifyNoInteractions(jsonGenerator); + } +}