-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
src/test/java/com/techatpark/sjson/core/NullParserTest.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,56 @@ | ||
package com.techatpark.sjson.core; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
import java.io.IOException; | ||
import java.io.StringReader; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class NullParserTest { | ||
|
||
final ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
/** | ||
* Tests Valid Null value. | ||
* <p> | ||
* Steps: | ||
* 1) Pass a null value. | ||
* 2) Get JSON String from Jackson . (jsonString) | ||
* 3) With this JSON String read java object using JSON. | ||
* </p> | ||
* Expected Result: | ||
* This value should be null. | ||
* @throws IOException | ||
*/ | ||
@Test | ||
void testValid() throws IOException { | ||
String jsonString = objectMapper.writeValueAsString(null); | ||
Assertions.assertNull(new Json().read(new StringReader(jsonString))); | ||
} | ||
|
||
/** | ||
* Tests Invalid Null value. | ||
* <p> | ||
* Steps: | ||
* 1) Pass a invalid null value(invalidjson). | ||
* 2) Read java object using JSON. | ||
* </p> | ||
* Expected Result: | ||
* IllegalArguementException should be thrown. | ||
* @param invalidjson | ||
*/ | ||
@ParameterizedTest | ||
@ValueSource(strings = { | ||
"nu" | ||
}) | ||
void testInvalid(final String invalidjson) throws IOException { | ||
assertThrows(IllegalArgumentException.class, | ||
() -> new Json().read(new StringReader(invalidjson))); | ||
} | ||
|
||
} |
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