Skip to content

Commit

Permalink
Clean test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
sathishk committed Mar 4, 2024
1 parent 92ac595 commit ed1d33e
Showing 1 changed file with 29 additions and 30 deletions.
59 changes: 29 additions & 30 deletions src/test/java/com/techatpark/sjson/core/NumberParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,35 @@ void testValid(final Number originalValue) throws IOException {
Assertions.assertEquals(originalValue.toString(), new Json().read(new StringReader(jsonString)).toString());
}

/**
* Tests Where NumberParser completes cursor.
* <p>
* Steps:
* 1) Pass valid number value(validjson) (With following 1).
* 2) Read java object using NumberParser.
* </p>
* Expected Result:
* next Clean Should be at 1
*
* @param originalValue
*/
@ParameterizedTest
@MethodSource("numbers")
void testCursor(final Number originalValue) throws IOException {
String jsonString = objectMapper.writeValueAsString(originalValue);
testCursor(jsonString,",1");
testCursor(jsonString,",\n\t1");
testCursor(jsonString," ,\n\t1");
}

private void testCursor(final String jsonString, final String suffix) throws IOException {
StringReader reader = new StringReader(jsonString + suffix);
char firstChar = nextClean(reader); // Move to First Digit
NumberParser.getNumber(new Json.ContentExtractor(reader),reader, firstChar);
assertEquals('1',
nextClean(reader));
}

/**
* Provides paths to JSON files for parameterized tests.
*
Expand Down Expand Up @@ -80,34 +109,4 @@ private static List<Number> numbers() {
);
}

/**
* Tests Where Reader completes cursor.
* <p>
* Steps:
* 1) Pass valid number value(validjson) (With following 1.
* 2) Read java object using JSON.
* </p>
* Expected Result:
* next Clean Should be at 1
*
* @param validjson
*/
@ParameterizedTest
@ValueSource(strings = {
"2,1",
"2,\n\t1",
"2 ,\n\t1",
"2.5,1",
"2.5\n\t, 1"
})
void testCursor(final String validjson) throws IOException {
StringReader reader = new StringReader(validjson);
char firstChar = nextClean(reader); // Move to First Digit
NumberParser.getNumber(new Json.ContentExtractor(reader),reader, firstChar);
assertEquals('1',
nextClean(reader));
}



}

0 comments on commit ed1d33e

Please sign in to comment.