Skip to content

Commit

Permalink
Refactoring 4
Browse files Browse the repository at this point in the history
  • Loading branch information
sathishk committed Mar 16, 2024
1 parent 8f4b7b9 commit 710b0d0
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 5 deletions.
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,22 @@ class ObjectParserTest {
* @return Stream of paths to JSON files
* @throws IOException if there is an issue listing files
*/
private static List<Path> jsonObjectStrings() throws IOException {
List<Path> jsonObjectStrings = new ArrayList<>();
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("{")) {
jsonObjectStrings.add(path);
jsonFilePath.add(path);
}
}

return jsonObjectStrings;
return jsonFilePath;

}

@ParameterizedTest
@MethodSource("jsonObjectStrings")
@MethodSource("jsonFilePath")
void testValid(final Path path) throws IOException {
Assertions.assertEquals(JsonParser
.parseReader(
Expand Down

0 comments on commit 710b0d0

Please sign in to comment.