Skip to content

Commit

Permalink
Perf Imp 2 2
Browse files Browse the repository at this point in the history
  • Loading branch information
sathishk committed Mar 19, 2024
1 parent 710b0d0 commit ebd429f
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 64 deletions.
4 changes: 2 additions & 2 deletions src/test/java/com/techatpark/sjson/core/JsonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.JsonParser;
import com.techatpark.sjson.core.util.TestUtil;
import com.techatpark.sjson.core.util.TestDataProvider;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -65,7 +65,7 @@ void testNullJsonText() {
* @throws IOException if there is an issue listing files
*/
private static Set<Path> jsonFilesProvider() throws IOException {
return TestUtil.getJSONFiles();
return TestDataProvider.getJSONFiles();
}

}
7 changes: 2 additions & 5 deletions src/test/java/com/techatpark/sjson/core/PerformanceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.techatpark.sjson.core.Json;
import com.techatpark.sjson.core.util.TestUtil;
import com.techatpark.sjson.core.util.TestDataProvider;
import org.github.jamm.MemoryMeter;
import org.json.JSONObject;
import org.junit.jupiter.api.Assertions;
Expand All @@ -17,8 +16,6 @@
import java.io.IOException;
import java.io.StringReader;
import java.nio.file.Path;
import java.time.Duration;
import java.time.Instant;
import java.util.Set;


Expand Down Expand Up @@ -94,7 +91,7 @@ void testRead(Path path) throws IOException {
* @throws IOException if there is an issue listing files
*/
private static Set<Path> jsonFilesProvider() throws IOException {
return TestUtil.getJSONFiles();
return TestDataProvider.getJSONFiles();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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 com.techatpark.sjson.core.util.TestDataProvider;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
Expand All @@ -16,8 +16,6 @@
import java.util.ArrayList;
import java.util.List;

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

class ArrayParserTest {
final ObjectMapper objectMapper = new ObjectMapper();

Expand All @@ -31,7 +29,7 @@ class ArrayParserTest {
private static List<Path> jsonFilePath() throws IOException {
List<Path> jsonFilePath = new ArrayList<>();

for (Path path : TestUtil.getJSONFiles()) {
for (Path path : TestDataProvider.getJSONFiles()) {
String jsonText = Files.readString(path).trim();
if (jsonText.startsWith("[")) {
jsonFilePath.add(path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class NumberParserTest {
* @throws IOException
*/
@ParameterizedTest
@MethodSource("numbers")
@MethodSource("com.techatpark.sjson.core.util.TestDataProvider#numbers")
void testValid(final Number originalValue) throws IOException {
String jsonString = objectMapper.writeValueAsString(originalValue);
Assertions.assertEquals(originalValue.toString(), new Json().read(new StringReader(jsonString)).toString());
Expand All @@ -51,7 +51,7 @@ void testValid(final Number originalValue) throws IOException {
* @param originalValue
*/
@ParameterizedTest
@MethodSource("numbers")
@MethodSource("com.techatpark.sjson.core.util.TestDataProvider#numbers")
void testCursor(final Number originalValue) throws IOException {
String jsonString = objectMapper.writeValueAsString(originalValue);
testCursor(jsonString,",1");
Expand All @@ -67,43 +67,6 @@ private void testCursor(final String jsonString, final String suffix) throws IOE
nextClean(reader));
}

/**
* Provides Numbers to Test.
*
* @return Stream of Numbers
* @throws IOException if there is an issue listing files
*/
private static List<Number> numbers() {
return List.of(
Byte.MIN_VALUE,
Byte.MAX_VALUE,
Short.MIN_VALUE,
Short.MAX_VALUE,
Integer.MIN_VALUE,
Integer.MAX_VALUE,
Long.MIN_VALUE,
Long.MAX_VALUE,
BigInteger.valueOf(Long.MIN_VALUE).multiply(BigInteger.TEN),
BigInteger.valueOf(Long.MAX_VALUE).multiply(BigInteger.TEN),
Float.MIN_VALUE,
Float.MAX_VALUE,
Double.MIN_VALUE,
123,
-456,
12.34,
-0.567,
1.23e4,
5.67E-8,
0.456,
1.23e001,
+789,
0.4e006,
0.4e-006,
0.4e+006,
4e006,
4e-006,
4e+006
);
}


}
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
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 com.techatpark.sjson.core.util.TestDataProvider;
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 {

Expand All @@ -37,7 +30,7 @@ class ObjectParserTest {
private static List<Path> jsonFilePath() throws IOException {
List<Path> jsonFilePath = new ArrayList<>();

for (Path path : TestUtil.getJSONFiles()) {
for (Path path : TestDataProvider.getJSONFiles()) {
String jsonText = Files.readString(path).trim();
if (jsonText.startsWith("{")) {
jsonFilePath.add(path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import java.io.File;
import java.io.IOException;
import java.math.BigInteger;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class TestUtil {
public class TestDataProvider {

private static String baseFolder = System.getenv("SJSON_LOCAL_DIR") == null ? "src/test/resources" :
System.getenv("SJSON_LOCAL_DIR");
Expand All @@ -33,12 +35,50 @@ public static Set<Path> getJSONFiles() throws IOException {
* @throws IOException
*/
public static Set<File> getJSONSchemaFiles() throws IOException {

try (Stream<Path> stream = Files.list(new File(baseFolder, "schemas").toPath())) {
return stream
.filter(path -> !Files.isDirectory(path))
.map(Path::toFile)
.collect(Collectors.toSet());
}
}

/**
* Provides Numbers to Test.
*
* @return Stream of Numbers
* @throws IOException if there is an issue listing files
*/
public static List<Number> numbers() {
return List.of(
Byte.MIN_VALUE,
Byte.MAX_VALUE,
Short.MIN_VALUE,
Short.MAX_VALUE,
Integer.MIN_VALUE,
Integer.MAX_VALUE,
Long.MIN_VALUE,
Long.MAX_VALUE,
BigInteger.valueOf(Long.MIN_VALUE).multiply(BigInteger.TEN),
BigInteger.valueOf(Long.MAX_VALUE).multiply(BigInteger.TEN),
Float.MIN_VALUE,
Float.MAX_VALUE,
Double.MIN_VALUE,
123,
-456,
12.34,
-0.567,
1.23e4,
5.67E-8,
0.456,
1.23e001,
+789,
0.4e006,
0.4e-006,
0.4e+006,
4e006,
4e-006,
4e+006
);
}
}
4 changes: 2 additions & 2 deletions src/test/java/com/techatpark/sjson/schema/JsonSchemaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.github.victools.jsonschema.generator.SchemaGeneratorConfig;
import com.github.victools.jsonschema.generator.SchemaGeneratorConfigBuilder;
import com.github.victools.jsonschema.generator.SchemaVersion;
import com.techatpark.sjson.core.util.TestUtil;
import com.techatpark.sjson.core.util.TestDataProvider;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
Expand Down Expand Up @@ -73,7 +73,7 @@ void read(final File schemaFile) throws IOException {
* @throws IOException if there is an issue listing files
*/
private static Set<File> jsonSchemaFilesProvider() throws IOException {
return TestUtil.getJSONSchemaFiles();
return TestDataProvider.getJSONSchemaFiles();
}

}

0 comments on commit ebd429f

Please sign in to comment.