-
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
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
src/test/java/com/techatpark/sjson/core/StringParserTest.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,68 @@ | ||
package com.techatpark.sjson.core; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.junit.jupiter.api.Assertions; | ||
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.assertThrows; | ||
|
||
class StringParserTest { | ||
|
||
final ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
/** | ||
* Tests Valid String values. | ||
* <p> | ||
* Steps: | ||
* 1) Pass valid string value(original 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 equal to originalvalue. | ||
* @param originalValue | ||
* @throws IOException | ||
*/ | ||
@ParameterizedTest | ||
@ValueSource(strings = { | ||
"Hari", | ||
"Escapes \" \\", | ||
"Tabnext \n \b \t \f \r", | ||
"Emoji \uD83D\uDE00 \u0000" | ||
}) | ||
void testValid(final String originalValue) throws IOException { | ||
|
||
String jsonString = objectMapper.writeValueAsString(originalValue); | ||
Assertions.assertEquals(originalValue, new Json().read(new StringReader(jsonString))); | ||
} | ||
|
||
/** | ||
* Tests Invalid String values. | ||
* <p> | ||
* Steps: | ||
* 1) Pass valid string value(original value). | ||
* 2) Read java object using JSON. | ||
* </p> | ||
* Expected Result: | ||
* IllegalArguementException should be thrown. | ||
* @param invalidjson | ||
*/ | ||
@ParameterizedTest | ||
@ValueSource(strings = { | ||
"\"\\s\"", | ||
"\"dddd", | ||
"\"\n", | ||
"\"20\\r\n\"" | ||
}) | ||
void testInvalid(final String invalidjson) throws IOException { | ||
assertThrows(IllegalArgumentException.class, | ||
() -> new Json().read(new StringReader(invalidjson))); | ||
} | ||
|
||
|
||
|
||
} |