Skip to content

Commit

Permalink
added junit
Browse files Browse the repository at this point in the history
  • Loading branch information
Benedetta-fabbri committed Jan 16, 2025
1 parent c6e368f commit fbdef65
Showing 1 changed file with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit fbdef65

Please sign in to comment.