Skip to content

Commit

Permalink
Reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
orangain committed Jul 21, 2024
1 parent e710882 commit bc5281a
Show file tree
Hide file tree
Showing 25 changed files with 84 additions and 31 deletions.
7 changes: 5 additions & 2 deletions src/main/java/io/github/orangain/jsonmatch/JsonMatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.github.orangain.jsonmatch.json.JsonUtil;
import io.github.orangain.jsonmatch.parser.JsonMatchPatternParser;
import io.github.orangain.jsonmatch.pattern.JsonPatternNode;
import org.jetbrains.annotations.NotNull;

import java.util.Optional;

Expand All @@ -16,7 +17,8 @@
public class JsonMatch {
/**
* Asserts that the actual JSON matches the pattern JSON.
* @param actualJson The actual JSON string.
*
* @param actualJson The actual JSON string.
* @param patternJson The pattern JSON string.
*/
public static void assertJsonMatches(String actualJson, String patternJson) {
Expand All @@ -28,7 +30,8 @@ public static void assertJsonMatches(String actualJson, String patternJson) {

/**
* Checks if the actual JSON matches the pattern JSON.
* @param actualJson The actual JSON string.
*
* @param actualJson The actual JSON string.
* @param patternJson The pattern JSON string.
* @return An {@link Optional} of {@link JsonMatchError} if the actual JSON does not match the pattern JSON.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ public class JsonMatchError {

/**
* Constructor of the JSON match error.
* @param message The error message.
* @param actual The actual JSON string.
*
* @param message The error message.
* @param actual The actual JSON string.
* @param expected The expected JSON string.
*/
public JsonMatchError(@NotNull String message, @NotNull String actual, @NotNull String expected) {
Expand All @@ -25,6 +26,7 @@ public JsonMatchError(@NotNull String message, @NotNull String actual, @NotNull

/**
* Get the error message.
*
* @return The error message.
*/
public @NotNull String getMessage() {
Expand All @@ -33,6 +35,7 @@ public JsonMatchError(@NotNull String message, @NotNull String actual, @NotNull

/**
* Get the actual JSON string.
*
* @return The actual JSON string.
*/
public @NotNull String getActual() {
Expand All @@ -41,6 +44,7 @@ public JsonMatchError(@NotNull String message, @NotNull String actual, @NotNull

/**
* Get the expected JSON string.
*
* @return The expected JSON string.
*/
public @NotNull String getExpected() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.orangain.jsonmatch;

import org.assertj.core.api.AbstractAssert;
import org.jetbrains.annotations.NotNull;

/**
* AssertJ assertion for JSON strings.
Expand All @@ -9,7 +10,8 @@ public class JsonStringAssert extends AbstractAssert<JsonStringAssert, String> {

/**
* Constructor of the JSON string assertion.
* @param s The JSON string to make assertions on.
*
* @param s The JSON string to make assertions on.
* @param selfType The class of the assertion.
*/
public JsonStringAssert(String s, Class<?> selfType) {
Expand All @@ -18,6 +20,7 @@ public JsonStringAssert(String s, Class<?> selfType) {

/**
* Creates a new instance of JsonStringAssert allowing to perform assertions on the provided JSON string.
*
* @param actual The JSON string to make assertions on.
* @return A new instance of JsonStringAssert.
*/
Expand All @@ -27,6 +30,7 @@ public JsonStringAssert(String s, Class<?> selfType) {

/**
* Asserts that the JSON string matches the pattern JSON string.
*
* @param patternJson The pattern JSON string.
* @return This assertion object.
*/
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/io/github/orangain/jsonmatch/json/JsonPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class JsonPath {

/**
* Constructor of the JSON path.
*
* @param path The JSON path string.
*/
public JsonPath(@NotNull String path) {
Expand All @@ -23,6 +24,7 @@ public JsonPath(@NotNull String path) {

/**
* Get the JSON path for the array item.
*
* @param index The index of the array item.
* @return The JSON path for the array item.
*/
Expand All @@ -32,6 +34,7 @@ public JsonPath(@NotNull String path) {

/**
* Get the JSON path for the object field.
*
* @param fieldName The name of the object field.
* @return The JSON path for the object field.
*/
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/io/github/orangain/jsonmatch/json/JsonUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* JSON utility class.
Expand All @@ -11,6 +13,7 @@ public class JsonUtil {

/**
* Get the singleton instance of the Jackson {@link ObjectMapper}.
*
* @return The singleton instance of the Jackson {@link ObjectMapper}.
*/
public static @NotNull ObjectMapper getObjectMapper() {
Expand All @@ -22,6 +25,7 @@ public class JsonUtil {

/**
* Convert an object to a JSON string. This method is unchecked exception version of {@link ObjectMapper#writeValueAsString(Object)}.
*
* @param value The object to convert to a JSON string.
* @return The JSON string.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class JsonMatchPatternParser {

/**
* Parse a JSON match pattern from a JSON node.
*
* @param jsonNode The JSON node to parse.
* @return The parsed JSON match pattern node.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public class ArrayLiteralPatternNode extends ArrayPatternNode {

/**
* Constructor of the JSON array pattern node.
* @param expected The string representation of the expected JSON array pattern.
*
* @param expected The string representation of the expected JSON array pattern.
* @param expectedChildren The expected patterns for each element of the array.
*/
public ArrayLiteralPatternNode(@NotNull String expected, @NotNull List<JsonPatternNode> expectedChildren) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class ArrayMarkerPatternNode extends ArrayPatternNode {

/**
* Constructor of the JSON array pattern node with no expected size or child pattern.
*
* @param expected The string representation of the expected JSON array pattern.
*/
public ArrayMarkerPatternNode(@NotNull String expected) {
Expand All @@ -30,7 +31,8 @@ public ArrayMarkerPatternNode(@NotNull String expected) {

/**
* Constructor of the JSON array pattern node with child pattern but no expected size.
* @param expected The string representation of the expected JSON array pattern.
*
* @param expected The string representation of the expected JSON array pattern.
* @param expectedChildPattern The expected pattern for each element of the array.
*/
public ArrayMarkerPatternNode(@NotNull String expected, @Nullable JsonPatternNode expectedChildPattern) {
Expand All @@ -39,8 +41,9 @@ public ArrayMarkerPatternNode(@NotNull String expected, @Nullable JsonPatternNod

/**
* Constructor of the JSON array pattern node with expected size and child pattern.
* @param expected The string representation of the expected JSON array pattern.
* @param expectedSize The expected size of the array.
*
* @param expected The string representation of the expected JSON array pattern.
* @param expectedSize The expected size of the array.
* @param expectedChildPattern The expected pattern for each element of the array.
*/
public ArrayMarkerPatternNode(@NotNull String expected, int expectedSize, @Nullable JsonPatternNode expectedChildPattern) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
public abstract class ArrayPatternNode extends JsonPatternNode {
/**
* Constructor of the JSON array pattern node.
*
* @param expected The string representation of the expected JSON array pattern.
*/
protected ArrayPatternNode(@NotNull String expected) {
Expand All @@ -34,15 +35,17 @@ protected ArrayPatternNode(@NotNull String expected) {

/**
* Checks if the size of the actual JSON array node matches the pattern node.
* @param jsonPath The JSON path to the actual JSON node.
*
* @param jsonPath The JSON path to the actual JSON node.
* @param actualNode The actual JSON node.
* @return An empty optional if the size matches, or an error detail if it does not match.
*/
protected abstract @NotNull Optional<JsonMatchErrorDetail> sizeMatches(@NotNull JsonPath jsonPath, @NotNull JsonNode actualNode);

/**
* Checks if the children of the actual JSON array node matches the pattern node.
* @param jsonPath The JSON path to the actual JSON node.
*
* @param jsonPath The JSON path to the actual JSON node.
* @param actualNode The actual JSON node.
* @return An empty optional if the children matches, or an error detail if they do not match.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ public class JsonMatchErrorDetail {

/**
* Constructor of the JSON match error detail.
* @param path The JSON path where the error occurred.
* @param actual The actual JSON string.
*
* @param path The JSON path where the error occurred.
* @param actual The actual JSON string.
* @param expected The expected JSON string.
* @param reason The reason for the error.
* @param reason The reason for the error.
*/
public JsonMatchErrorDetail(@NotNull JsonPath path, @NotNull String actual, @NotNull String expected, @NotNull String reason) {
this.path = path;
Expand All @@ -36,6 +37,7 @@ public JsonMatchErrorDetail(@NotNull JsonPath path, @NotNull String actual, @Not

/**
* Creates a new JSON match error detail with the expected JSON string.
*
* @param expected The expected JSON string.
* @return A new JSON match error detail.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public abstract class JsonPatternNode {

/**
* Constructor of the JSON pattern node.
*
* @param expected The string representation of the expected JSON pattern.
*/
protected JsonPatternNode(@NotNull String expected) {
Expand All @@ -25,17 +26,19 @@ protected JsonPatternNode(@NotNull String expected) {

/**
* Matches the JSON pattern node against the actual JSON node.
* @param path The JSON path to the actual JSON node.
*
* @param path The JSON path to the actual JSON node.
* @param actualNode The actual JSON node.
* @return An empty optional if the actual JSON node matches the pattern node, or an error detail if it does not match.
*/
public abstract @NotNull Optional<JsonMatchErrorDetail> matches(@NotNull JsonPath path, @NotNull JsonNode actualNode);

/**
* Creates an error detail.
* @param path The JSON path to the actual JSON node.
*
* @param path The JSON path to the actual JSON node.
* @param actualNode The actual JSON node.
* @param reason The reason why the actual JSON node does not match the pattern node.
* @param reason The reason why the actual JSON node does not match the pattern node.
* @return An error detail.
*/
protected @NotNull JsonMatchErrorDetail error(@NotNull JsonPath path, @NotNull JsonNode actualNode, @NotNull String reason) {
Expand All @@ -44,6 +47,7 @@ protected JsonPatternNode(@NotNull String expected) {

/**
* Returns if the pattern node can be missing.
*
* @return True if the pattern node can be missing, false otherwise.
*/
protected boolean canBeMissing() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public class ObjectLiteralPatternNode extends ObjectPatternNode {

/**
* Constructor of the JSON object pattern node.
* @param expected The string representation of the expected JSON object pattern.
*
* @param expected The string representation of the expected JSON object pattern.
* @param expectedChildren The expected pairs of key and value pattern node.
*/
public ObjectLiteralPatternNode(@NotNull String expected, @NotNull Map<String, JsonPatternNode> expectedChildren) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
public class ObjectMarkerPatternNode extends ObjectPatternNode {
/**
* Constructor of the JSON object pattern node.
*
* @param expected The string representation of the expected JSON object pattern.
*/
public ObjectMarkerPatternNode(@NotNull String expected) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
public abstract class ObjectPatternNode extends JsonPatternNode {
/**
* Constructor of the JSON object pattern node.
*
* @param expected The string representation of the expected JSON object pattern.
*/
protected ObjectPatternNode(@NotNull String expected) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class ValueLiteralPatternNode extends ValuePatternNode {

/**
* Constructor of the JSON simple value pattern node.
*
* @param expectedJsonNode The expected JSON value node.
*/
public ValueLiteralPatternNode(@NotNull JsonNode expectedJsonNode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
public abstract class ValuePatternNode extends JsonPatternNode {
/**
* Constructor of the JSON simple pattern node.
*
* @param expected The string representation of the expected JSON simple pattern.
*/
protected ValuePatternNode(@NotNull String expected) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.github.orangain.jsonmatch.pattern.valuemarker;

import com.fasterxml.jackson.databind.JsonNode;
import io.github.orangain.jsonmatch.pattern.JsonMatchErrorDetail;
import io.github.orangain.jsonmatch.json.JsonPath;
import io.github.orangain.jsonmatch.json.JsonUtil;
import io.github.orangain.jsonmatch.pattern.JsonMatchErrorDetail;
import io.github.orangain.jsonmatch.pattern.ValuePatternNode;
import org.jetbrains.annotations.NotNull;

Expand All @@ -20,6 +20,7 @@ public class DateMarkerPatternNode extends ValuePatternNode {

/**
* Constructor of the JSON date pattern node.
*
* @param expected The string representation of the expected JSON date pattern.
*/
public DateMarkerPatternNode(@NotNull String expected) {
Expand All @@ -28,6 +29,7 @@ public DateMarkerPatternNode(@NotNull String expected) {

/**
* Get the singleton instance of the JSON date pattern node.
*
* @return The singleton instance of the JSON date pattern node.
*/
public static DateMarkerPatternNode getInstance() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.github.orangain.jsonmatch.pattern.valuemarker;

import com.fasterxml.jackson.databind.JsonNode;
import io.github.orangain.jsonmatch.pattern.JsonMatchErrorDetail;
import io.github.orangain.jsonmatch.json.JsonPath;
import io.github.orangain.jsonmatch.json.JsonUtil;
import io.github.orangain.jsonmatch.pattern.JsonMatchErrorDetail;
import io.github.orangain.jsonmatch.pattern.ValuePatternNode;
import org.jetbrains.annotations.NotNull;

Expand All @@ -20,6 +20,7 @@ public class DateTimeMarkerPatternNode extends ValuePatternNode {

/**
* Constructor of the JSON date-time pattern node.
*
* @param expected The string representation of the expected JSON date-time pattern.
*/
public DateTimeMarkerPatternNode(@NotNull String expected) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.github.orangain.jsonmatch.pattern.valuemarker;

import com.fasterxml.jackson.databind.JsonNode;
import io.github.orangain.jsonmatch.pattern.JsonMatchErrorDetail;
import io.github.orangain.jsonmatch.json.JsonPath;
import io.github.orangain.jsonmatch.json.JsonUtil;
import io.github.orangain.jsonmatch.pattern.JsonMatchErrorDetail;
import io.github.orangain.jsonmatch.pattern.JsonPatternNode;
import io.github.orangain.jsonmatch.pattern.ValuePatternNode;
import org.jetbrains.annotations.NotNull;
Expand All @@ -18,6 +18,7 @@ public class IgnoreMarkerPatternNode extends ValuePatternNode {

/**
* Constructor of the JSON ignore marker pattern node.
*
* @param expected The string representation of the expected JSON ignore marker pattern.
*/
public IgnoreMarkerPatternNode(@NotNull String expected) {
Expand All @@ -26,6 +27,7 @@ public IgnoreMarkerPatternNode(@NotNull String expected) {

/**
* Get the singleton instance of the JSON ignore marker pattern node.
*
* @return The singleton instance of the JSON ignore marker pattern node.
*/
public static JsonPatternNode getInstance() {
Expand Down
Loading

0 comments on commit bc5281a

Please sign in to comment.