Skip to content

Commit

Permalink
Update for checkstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
trickl committed Dec 5, 2022
1 parent d18278c commit deb6826
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 40 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
Expand Down Expand Up @@ -132,7 +132,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.1</version>
<version>3.2.0</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.trickl.assertj.core.api.json;

import static org.skyscreamer.jsonassert.JSONCompareMode.NON_EXTENSIBLE;

import com.trickl.assertj.core.internal.Json;
import com.trickl.assertj.core.util.diff.PostComparisonAction;
import com.trickl.assertj.core.util.diff.WriteOnFailureAction;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
Expand All @@ -27,17 +25,17 @@ public abstract class AbstractJsonAssert<S extends AbstractJsonAssert<S>>
extends AbstractAssert<S, JsonContainer> {

@VisibleForTesting Json json = Json.instance();

private boolean extensible = false;

private boolean strictOrder = true;

private boolean writeActualOnFailure = false;

private Path actualPathOnFailure = null;

private boolean writeExpectedOnFailure = false;

private Path expectedPathOnFailure = null;

public AbstractJsonAssert(JsonContainer actual, Class<?> selfType) {
Expand All @@ -59,25 +57,26 @@ public S isSameJsonAs(String expected) {

/**
* Check if the supplied JSON is the same as expected.
*
* @param expected The expected JSON
* @return the assertion
*/
public S isSameJsonAs(JsonContainer expected) {
JSONComparator comparator = new DefaultComparator(
JSONCompareMode.STRICT
.withExtensible(extensible)
.withStrictOrdering(strictOrder));

JSONComparator comparator =
new DefaultComparator(
JSONCompareMode.STRICT.withExtensible(extensible).withStrictOrdering(strictOrder));

PostComparisonAction postComparisonAction = null;
if (writeActualOnFailure || writeExpectedOnFailure) {
postComparisonAction = new WriteOnFailureAction(
info,
writeActualOnFailure,
actualPathOnFailure,
writeExpectedOnFailure,
expectedPathOnFailure);
postComparisonAction =
new WriteOnFailureAction(
info,
writeActualOnFailure,
actualPathOnFailure,
writeExpectedOnFailure,
expectedPathOnFailure);
}

json.assertSameJsonAs(info, actual, expected, comparator, postComparisonAction);
return myself;
}
Expand All @@ -91,17 +90,19 @@ public S allowingAnyArrayOrdering() {
strictOrder = false;
return myself;
}

/**
* Write the actual output to a temporary file on failure.
*
* @return Updated assertion object
*/
public S writeActualToFileOnFailure() {
return writeActualToFileOnFailure(null);
}

/**
* Write the actual output to a file on failure.
*
* @param path The file path, if null, a temporary file is used
* @return Updated assertion object
*/
Expand All @@ -110,23 +111,25 @@ public S writeActualToFileOnFailure(Path path) {
actualPathOnFailure = path;
return myself;
}

/**
* Write the expected output to a temporary file on failure.
*
* @return Updated assertion object
*/
public S writeExpectedToFileOnFailure() {
return writeExpectedToFileOnFailure(null);
}

/**
* Write the expected output to a file on failure.
*
* @param path The file path, if null, a temporary file is used
* @return Updated assertion object
*/
public S writeExpectedToFileOnFailure(Path path) {
writeExpectedOnFailure = true;
expectedPathOnFailure = path;
return myself;
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/trickl/assertj/core/internal/Json.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.trickl.assertj.core.api.json.JsonContainer;
import com.trickl.assertj.core.util.diff.PostComparisonAction;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -34,7 +33,8 @@ public static Json instance() {
@VisibleForTesting Failures failures = Failures.instance();

@VisibleForTesting
Json() {}
Json() {
}

/**
* Asserts that the given JSON structures have same content.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.trickl.assertj.core.util.diff;

import java.util.List;

import org.assertj.core.util.diff.Delta;

@FunctionalInterface
public interface PostComparisonAction {
void apply(List<Delta<String>> diffs, String actual, String expected);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ public JsonFieldDelta(FieldComparisonFailure failure, TYPE type) {
}

@Override
public void applyTo(List<T> target) throws IllegalStateException {}
public void applyTo(List<T> target) throws IllegalStateException {
}

@Override
public void verify(List<T> target) throws IllegalStateException {}
public void verify(List<T> target) throws IllegalStateException {
}

@Override
public String toString() {
Expand Down
17 changes: 10 additions & 7 deletions src/main/java/com/trickl/assertj/util/diff/JsonRootDelta.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ public class JsonRootDelta<T> extends Delta<T> {
@Getter private final TYPE type = TYPE.CHANGE;

/**
* Create a delta for a JSON document.
* @param expected the expected element
* @param actual the actual element
* @param message the optional descriptive message
*/
* Create a delta for a JSON document.
*
* @param expected the expected element
* @param actual the actual element
* @param message the optional descriptive message
*/
public JsonRootDelta(String expected, String actual, String message) {
super(new Chunk(0, Collections.EMPTY_LIST), new Chunk(0, Collections.EMPTY_LIST));
this.expected = expected;
Expand All @@ -38,10 +39,12 @@ public JsonRootDelta(String expected, String actual, String message) {
}

@Override
public void applyTo(List<T> target) throws IllegalStateException {}
public void applyTo(List<T> target) throws IllegalStateException {
}

@Override
public void verify(List<T> target) throws IllegalStateException {}
public void verify(List<T> target) throws IllegalStateException {
}

@Override
public String toString() {
Expand Down

0 comments on commit deb6826

Please sign in to comment.