-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from opencredo/feature/near_complete_coverage
Near complete code coverage
- Loading branch information
Showing
11 changed files
with
283 additions
and
29 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
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
97 changes: 97 additions & 0 deletions
97
...st/java/com/opencredo/connect/venafi/tpp/log/Deserializer/DotNetDateDeserializerTest.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,97 @@ | ||
package com.opencredo.connect.venafi.tpp.log.Deserializer; | ||
|
||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonNull; | ||
import com.google.gson.JsonParseException; | ||
import com.google.gson.JsonPrimitive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.function.Executable; | ||
|
||
import java.time.ZoneOffset; | ||
import java.time.ZonedDateTime; | ||
|
||
import static com.opencredo.connect.venafi.tpp.log.TppLogSourceTask.DEFAULT_FROM_TIME; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class DotNetDateDeserializerTest { | ||
|
||
public static final String MILLISECOND_SINCE_EPOCH_UNTIL_1945_MAY_04_Z = "452476800000"; | ||
public static final String SLASH_DATE = "/DATE("; | ||
public static final String CLOSE_BRACKET_SLASH = ")/"; | ||
public static final String NEGATIVE_OFFSET = "-0100"; | ||
public static final String POSITIVE_OFFSET = "+0100"; | ||
public static final ZonedDateTime ZONED_DATE_TIME_1945_05_04_Z = ZonedDateTime.parse(DEFAULT_FROM_TIME); | ||
public static final DotNetDateDeserializer DESERIALIZER = new DotNetDateDeserializer(); | ||
|
||
@Test | ||
void deserialize_empty_string() { | ||
JsonElement jsonElem = given_an_empty_string_json_elem(); | ||
Executable dateTimeExecutable = when_the_date_is_deserialized_which_may_throw_exception(jsonElem); | ||
assertThrows(JsonParseException.class, dateTimeExecutable); | ||
} | ||
|
||
@Test | ||
void deserialize_json_null() { | ||
JsonElement jsonElem = given_a_json_null(); | ||
Executable dateTimeExecutable = when_the_date_is_deserialized_which_may_throw_exception(jsonElem); | ||
assertThrows(JsonParseException.class, dateTimeExecutable); | ||
} | ||
|
||
@Test | ||
void deserialize_invalid_null() { | ||
JsonElement jsonElem = given_json_of_milliseconds(""); | ||
Executable dateTimeExecutable = when_the_date_is_deserialized_which_may_throw_exception(jsonElem); | ||
assertThrows(JsonParseException.class, dateTimeExecutable); | ||
} | ||
|
||
@Test | ||
void deserialize_normal_format() { | ||
JsonElement jsonElem = given_json_of_milliseconds(MILLISECOND_SINCE_EPOCH_UNTIL_1945_MAY_04_Z); | ||
ZonedDateTime dateTime = when_the_date_is_deserialized(jsonElem); | ||
assertNotNull(dateTime); | ||
assertTrue(dateTime.isEqual(ZONED_DATE_TIME_1945_05_04_Z)); | ||
assertEquals(dateTime.getOffset(), ZoneOffset.ofHours(0)); | ||
} | ||
|
||
@Test | ||
void deserialize_positive_timezone() { | ||
JsonElement jsonElem = given_json_of_milliseconds_with_offset(MILLISECOND_SINCE_EPOCH_UNTIL_1945_MAY_04_Z, POSITIVE_OFFSET); | ||
ZonedDateTime dateTime = when_the_date_is_deserialized(jsonElem); | ||
assertNotNull(dateTime); | ||
assertTrue(dateTime.isEqual(ZONED_DATE_TIME_1945_05_04_Z)); | ||
assertEquals(dateTime.getOffset(), ZoneOffset.ofHours(1)); | ||
} | ||
|
||
@Test | ||
void deserialize_negative_timezone() { | ||
JsonElement jsonElem = given_json_of_milliseconds_with_offset(MILLISECOND_SINCE_EPOCH_UNTIL_1945_MAY_04_Z, NEGATIVE_OFFSET); | ||
ZonedDateTime dateTime = when_the_date_is_deserialized(jsonElem); | ||
assertNotNull(dateTime); | ||
assertTrue(dateTime.isEqual(ZONED_DATE_TIME_1945_05_04_Z)); | ||
assertEquals(dateTime.getOffset(), ZoneOffset.ofHours(-1)); | ||
} | ||
|
||
private JsonElement given_an_empty_string_json_elem() { | ||
return new JsonPrimitive(""); | ||
} | ||
|
||
private JsonElement given_a_json_null() { | ||
return JsonNull.INSTANCE; | ||
} | ||
|
||
private JsonElement given_json_of_milliseconds(String milliseconds) { | ||
return new JsonPrimitive(SLASH_DATE + milliseconds + CLOSE_BRACKET_SLASH); | ||
} | ||
|
||
private JsonElement given_json_of_milliseconds_with_offset(String milliseconds, String offset) { | ||
return new JsonPrimitive(SLASH_DATE + milliseconds + offset + CLOSE_BRACKET_SLASH); | ||
} | ||
|
||
private ZonedDateTime when_the_date_is_deserialized(JsonElement jsonElem) { | ||
return DESERIALIZER.deserialize(jsonElem, null, null); | ||
} | ||
|
||
private Executable when_the_date_is_deserialized_which_may_throw_exception(JsonElement jsonElem) { | ||
return () -> DESERIALIZER.deserialize(jsonElem, null, null); | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
...java/com/opencredo/connect/venafi/tpp/log/Deserializer/ZonedDateTimeDeserializerTest.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,80 @@ | ||
package com.opencredo.connect.venafi.tpp.log.Deserializer; | ||
|
||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonNull; | ||
import com.google.gson.JsonParseException; | ||
import com.google.gson.JsonPrimitive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.function.Executable; | ||
|
||
import java.time.ZoneOffset; | ||
import java.time.ZonedDateTime; | ||
|
||
import static com.opencredo.connect.venafi.tpp.log.Deserializer.DotNetDateDeserializerTest.ZONED_DATE_TIME_1945_05_04_Z; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class ZonedDateTimeDeserializerTest { | ||
public static final ZonedDateTimeDeserializer DESERIALIZER = new ZonedDateTimeDeserializer(); | ||
public static final String LOCAL_DATE_TIME = "1984-05-04T00:00:00.0000000"; | ||
public static final String ZONED_DATE_TIME = LOCAL_DATE_TIME + "Z"; | ||
public static final String GIBBERISH = "sadkjalskjdalksjd"; | ||
|
||
@Test | ||
void json_null() { | ||
JsonElement jsonElem = given_a_json_null(); | ||
Executable dateTimeExecutable = when_the_date_is_deserialized_which_may_throw_exception(jsonElem); | ||
assertThrows(JsonParseException.class, dateTimeExecutable); | ||
} | ||
|
||
@Test | ||
void empty_string() { | ||
JsonElement jsonElem = given_an_empty_string_json_elem(); | ||
Executable dateTimeExecutable = when_the_date_is_deserialized_which_may_throw_exception(jsonElem); | ||
assertThrows(JsonParseException.class, dateTimeExecutable); | ||
} | ||
|
||
@Test | ||
void invalid_string() { | ||
JsonElement jsonElem = given_json_of_(GIBBERISH); | ||
Executable dateTimeExecutable = when_the_date_is_deserialized_which_may_throw_exception(jsonElem); | ||
assertThrows(JsonParseException.class, dateTimeExecutable); | ||
} | ||
|
||
@Test | ||
void localDateTime() { | ||
JsonElement jsonElem = given_json_of_(LOCAL_DATE_TIME); | ||
ZonedDateTime dateTime = when_the_date_is_deserialized(jsonElem); | ||
assertNotNull(dateTime); | ||
assertTrue(dateTime.isEqual(ZONED_DATE_TIME_1945_05_04_Z)); | ||
assertEquals(dateTime.getOffset(), ZoneOffset.ofHours(0)); | ||
} | ||
|
||
@Test | ||
void zonedDateTime() { | ||
JsonElement jsonElem = given_json_of_(ZONED_DATE_TIME); | ||
ZonedDateTime dateTime = when_the_date_is_deserialized(jsonElem); | ||
assertNotNull(dateTime); | ||
assertTrue(dateTime.isEqual(ZONED_DATE_TIME_1945_05_04_Z)); | ||
assertEquals(dateTime.getOffset(), ZoneOffset.ofHours(0)); | ||
} | ||
|
||
private JsonElement given_an_empty_string_json_elem() { | ||
return new JsonPrimitive(""); | ||
} | ||
|
||
private JsonElement given_a_json_null() { | ||
return JsonNull.INSTANCE; | ||
} | ||
|
||
private JsonElement given_json_of_(String milliseconds) { | ||
return new JsonPrimitive(milliseconds); | ||
} | ||
|
||
private ZonedDateTime when_the_date_is_deserialized(JsonElement jsonElem) { | ||
return DESERIALIZER.deserialize(jsonElem, null, null); | ||
} | ||
|
||
private Executable when_the_date_is_deserialized_which_may_throw_exception(JsonElement jsonElem) { | ||
return () -> DESERIALIZER.deserialize(jsonElem, null, null); | ||
} | ||
} |
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
Oops, something went wrong.