Skip to content

Commit

Permalink
bruk av jupiter
Browse files Browse the repository at this point in the history
  • Loading branch information
stianStensli committed Apr 4, 2022
1 parent 9e5ee3e commit 0724db9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.13.1</version>
<version>2.13.2</version>
</dependency>

<!--Diverse-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
import com.fasterxml.jackson.databind.module.SimpleModule;
import no.nav.pto.veilarbfilter.domene.deserializer.DateDeserializer;
import no.nav.pto.veilarbfilter.domene.deserializer.DateSerializer;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.time.LocalDateTime;
import java.time.Month;

public class DateSerializerTest {
private ObjectMapper mapper;
private static ObjectMapper mapper;

@Before
public void setup() {
@BeforeAll
public static void setup() {
mapper = new ObjectMapper();

SimpleModule module = new SimpleModule();
Expand All @@ -28,18 +28,18 @@ public void setup() {

@Test
public void whenDateIsValidThenDeserializeIt() throws IOException {
String json = "{\"opprettetDato\": \"2020-03-05T23:05:45.224\"}";
String json = "{\"opprettetDato\": \"2020-03-05 23:05:45\"}";

MineLagredeFilterModel deserializedData = mapper.readValue(json, MineLagredeFilterModel.class);

LocalDateTime deserializedDate = deserializedData.getOpprettetDato();
Assert.assertTrue(deserializedDate != null);
Assert.assertTrue(deserializedDate.getYear() == 2020);
Assert.assertTrue(deserializedDate.getMonthValue() == 3);
Assert.assertTrue(deserializedDate.getDayOfMonth() == 5);
Assert.assertTrue(deserializedDate.getHour() == 23);
Assert.assertTrue(deserializedDate.getMinute() == 5);
Assert.assertTrue(deserializedDate.getSecond() == 45);
Assertions.assertNotNull(deserializedDate);
Assertions.assertEquals(2020, deserializedDate.getYear());
Assertions.assertEquals(3, deserializedDate.getMonthValue());
Assertions.assertEquals(5, deserializedDate.getDayOfMonth());
Assertions.assertEquals(deserializedDate.getHour(), 23);
Assertions.assertEquals(deserializedDate.getMinute(), 5);
Assertions.assertEquals(deserializedDate.getSecond(), 45);
}

@Test
Expand All @@ -49,17 +49,17 @@ public void whenDateIsInvalidThenReturnNull() {
String json = "{\"opprettetDato\": \"20220-03-05T23:05:45.224\"}";

deserializedData = mapper.readValue(json, MineLagredeFilterModel.class);
Assert.fail();
Assertions.fail();
} catch (JsonProcessingException e) {
Assert.assertNull(deserializedData.getOpprettetDato());
Assertions.assertNull(deserializedData.getOpprettetDato());
}
}

@Test
public void whenDateIsValidTestSerialization() throws IOException {
String jsonValue = mapper.writeValueAsString(LocalDateTime.of(2022, Month.JANUARY, 1, 0, 0));

Assert.assertNotNull(jsonValue);
Assert.assertTrue(jsonValue.length() > 10);
Assertions.assertNotNull(jsonValue);
Assertions.assertTrue(jsonValue.length() > 10);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public void testDeserialization() throws IOException {
""";
PortefoljeFilter filterModel = objectMapper.readValue(jsonString, PortefoljeFilter.class);

Assertions.assertTrue(filterModel.getArbeidslisteKategori() != null);
Assertions.assertTrue(filterModel.getArbeidslisteKategori().size() == 2);
Assertions.assertNotNull(filterModel.getArbeidslisteKategori());
Assertions.assertEquals(2, filterModel.getArbeidslisteKategori().size());
}


Expand All @@ -54,8 +54,8 @@ public void testDeserializationWithAktivitet() throws JsonProcessingException {
Assertions.assertNotNull(filterModel);
Assertions.assertNotNull(filterModel.getAktiviteter());
Assertions.assertNotNull(filterModel.getAktiviteter().getEGEN());
Assertions.assertTrue(filterModel.getAktiviteter().getEGEN().equals("JA"));
Assertions.assertTrue(filterModel.getAktiviteter().getMOTE().equals("NEI"));
Assertions.assertEquals("JA", filterModel.getAktiviteter().getEGEN());
Assertions.assertEquals("NEI", filterModel.getAktiviteter().getMOTE());
}

@Test
Expand Down

0 comments on commit 0724db9

Please sign in to comment.