-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow search location properties by empty parentId (#465)
* Allow search location properties by empty parentId * Test LocalDate serializer and deserializer
- Loading branch information
Showing
6 changed files
with
54 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/test/java/org/opensrp/util/LocalDateDeserializerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.opensrp.util; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.core.JsonToken; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.mockito.Mockito; | ||
|
||
import java.io.IOException; | ||
|
||
public class LocalDateDeserializerTest { | ||
|
||
@Test | ||
public void testDeserializer() throws IOException { | ||
LocalDateDeserializer localDateDeserializer = new LocalDateDeserializer(); | ||
DeserializationContext context = Mockito.mock(DeserializationContext.class); | ||
JsonParser jsonParser = Mockito.mock(JsonParser.class); | ||
Mockito.doReturn(JsonToken.VALUE_STRING).when(jsonParser).getCurrentToken(); | ||
Mockito.doReturn("2021-05-21").when(jsonParser).getText(); | ||
Assert.assertNotNull(localDateDeserializer.deserialize(jsonParser, context)); | ||
Mockito.doReturn(null).when(jsonParser).getCurrentToken(); | ||
Assert.assertNull(localDateDeserializer.deserialize(jsonParser, context)); | ||
|
||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/test/java/org/opensrp/util/LocalDateSerializerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.opensrp.util; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import org.joda.time.LocalDate; | ||
import org.junit.Test; | ||
import org.mockito.ArgumentCaptor; | ||
import org.mockito.Mockito; | ||
|
||
import java.io.IOException; | ||
|
||
public class LocalDateSerializerTest { | ||
|
||
@Test | ||
public void testSerializer() throws IOException { | ||
ArgumentCaptor<String> argumentCaptor = ArgumentCaptor.forClass(String.class); | ||
LocalDate localDate = new LocalDate(); | ||
LocalDateSerializer localDateSerializer = new LocalDateSerializer(); | ||
SerializerProvider provider = Mockito.mock(SerializerProvider.class); | ||
JsonGenerator jsonGen = Mockito.mock(JsonGenerator.class); | ||
localDateSerializer.serialize(localDate, jsonGen, provider); | ||
Mockito.verify(jsonGen, Mockito.atLeastOnce()).writeString(argumentCaptor.capture()); | ||
} | ||
} |