Skip to content

Commit

Permalink
Refactoring 2
Browse files Browse the repository at this point in the history
  • Loading branch information
sathishk committed Mar 16, 2024
1 parent 5c4ecc9 commit 8f4b7b9
Showing 1 changed file with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.techatpark.sjson.core.parser;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.JsonObject;
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.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

import java.io.BufferedReader;
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 java.util.Set;
import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.*;

class ObjectParserTest {

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> jsonObjectStrings() throws IOException {
List<Path> jsonObjectStrings = new ArrayList<>();

for (Path path : TestUtil.getJSONFiles()) {
String jsonText = Files.readString(path).trim();
if (jsonText.startsWith("{")) {
jsonObjectStrings.add(path);
}
}

return jsonObjectStrings;

}

@ParameterizedTest
@MethodSource("jsonObjectStrings")
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);
}

}

0 comments on commit 8f4b7b9

Please sign in to comment.