Skip to content

Commit

Permalink
NullParserTest added
Browse files Browse the repository at this point in the history
  • Loading branch information
rmhari committed Feb 29, 2024
1 parent 453cf86 commit 3626f0a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
56 changes: 56 additions & 0 deletions src/test/java/com/techatpark/sjson/core/NullParserTest.java
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)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void testValid(final String originalValue) throws IOException {
* Tests Invalid String values.
* <p>
* Steps:
* 1) Pass valid string value(original value).
* 1) Pass invalid string value(invalidjson).
* 2) Read java object using JSON.
* </p>
* Expected Result:
Expand Down

0 comments on commit 3626f0a

Please sign in to comment.