-
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
62 additions
and
5 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
src/test/java/com/techatpark/sjson/core/parser/ArrayParserTest.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,57 @@ | ||
package com.techatpark.sjson.core.parser; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.google.gson.JsonParser; | ||
import com.techatpark.sjson.core.Json; | ||
import com.techatpark.sjson.core.util.TestUtil; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import java.io.FileReader; | ||
import java.io.IOException; | ||
import java.io.StringReader; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class ArrayParserTest { | ||
final ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
|
||
/** | ||
* Provides paths to JSON files for parameterized tests. | ||
* | ||
* @return Stream of paths to JSON files | ||
* @throws IOException if there is an issue listing files | ||
*/ | ||
private static List<Path> jsonFilePath() throws IOException { | ||
List<Path> jsonFilePath = new ArrayList<>(); | ||
|
||
for (Path path : TestUtil.getJSONFiles()) { | ||
String jsonText = Files.readString(path).trim(); | ||
if (jsonText.startsWith("[")) { | ||
jsonFilePath.add(path); | ||
} | ||
} | ||
|
||
return jsonFilePath; | ||
|
||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("jsonFilePath") | ||
void testValid(final Path path) throws IOException { | ||
Assertions.assertEquals(JsonParser | ||
.parseReader( | ||
new StringReader(objectMapper.writeValueAsString( | ||
new Json().read( | ||
new FileReader(path.toFile()) | ||
)))), | ||
JsonParser.parseReader(new FileReader(path.toFile())), | ||
"Reverse JSON Failed for " + path); | ||
} | ||
} |
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