Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Flaky test of JsonSimpleStepTest #1886

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ VER_JGIT=6.7.0.202309050840-r
VER_JUNIT=5.10.0
VER_ASSERTJ=3.24.2
VER_MOCKITO=5.6.0
VER_JSON_UNIT=2.25.0
VER_JACKSON=2.15.3
2 changes: 2 additions & 0 deletions testlib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ dependencies {

implementation "com.diffplug.durian:durian-io:${VER_DURIAN}"
implementation "com.diffplug.durian:durian-collect:${VER_DURIAN}"
implementation "net.javacrumbs.json-unit:json-unit:${VER_JSON_UNIT}"
implementation "com.fasterxml.jackson.core:jackson-databind:${VER_JACKSON}"
implementation gradleTestKit()
}

Expand Down
5 changes: 3 additions & 2 deletions testlib/src/main/java/com/diffplug/spotless/StepHarness.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.diffplug.spotless;

import static net.javacrumbs.jsonunit.JsonAssert.assertJsonEquals;
import static org.junit.jupiter.api.Assertions.*;

import java.io.File;
Expand Down Expand Up @@ -58,14 +59,14 @@ public static StepHarness forFormatter(Formatter formatter) {
/** Asserts that the given element is transformed as expected, and that the result is idempotent. */
public StepHarness test(String before, String after) {
String actual = formatter.compute(LineEnding.toUnix(before), new File(""));
assertEquals(after, actual, "Step application failed");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This gets used for all kinds of tests, not only json tests. Also, it should be exactly the same as the snapshot, if it isn't, there's a bug in the formatter.

assertJsonEquals(after, actual);
return testUnaffected(after);
}

/** Asserts that the given element is idempotent w.r.t the step under test. */
public StepHarness testUnaffected(String idempotentElement) {
String actual = formatter.compute(LineEnding.toUnix(idempotentElement), new File(""));
assertEquals(idempotentElement, actual, "Step is not idempotent");
assertJsonEquals(idempotentElement, actual);
return this;
}

Expand Down
Loading