Skip to content

Commit 5330f07

Browse files
authored
#none: Code formatting via spotless (#119)
1 parent f6a8586 commit 5330f07

File tree

91 files changed

+1150
-1122
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+1150
-1122
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ plugins {
22
id 'net.researchgate.release' version '2.6.0' apply false
33
id 'com.github.johnrengelman.shadow' version '5.2.0' apply false
44
id 'io.codearte.nexus-staging' version '0.22.0'
5+
id "com.diffplug.spotless" version "6.11.0" apply false
56
}
67

78
subprojects { subproject ->
8-
99
// FIXME this plugin is currently not working for multi-module projects even when defined at the top level only
1010
// Will need to release and TAG manually for now
1111
subproject.apply plugin: 'net.researchgate.release'
@@ -38,7 +38,7 @@ subprojects { subproject ->
3838
compileOnly 'org.slf4j:slf4j-api:2.0.0-alpha0'
3939
}
4040

41-
// Adds verbose logging for TravisCI
41+
// Add verbose logging for Github Actions
4242
test {
4343
testLogging {
4444
events "passed", "skipped", "failed"

gradle/spotless-groovy.gradle

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apply plugin: 'com.diffplug.spotless'
2+
3+
// Code formatting
4+
spotless {
5+
groovy {
6+
importOrder()
7+
excludeJava()
8+
greclipse()
9+
}
10+
}

gradle/spotless.gradle

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apply plugin: 'com.diffplug.spotless'
2+
3+
// Code formatting
4+
spotless {
5+
java {
6+
importOrder()
7+
removeUnusedImports()
8+
googleJavaFormat()
9+
formatAnnotations()
10+
}
11+
}

java-snapshot-testing-core/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
apply from: "../gradle/publishing.gradle"
2+
apply from: "../gradle/spotless.gradle"
23

34
dependencies {
45

java-snapshot-testing-core/src/main/java/au/com/origin/snapshots/Expect.java

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
import au.com.origin.snapshots.comparators.SnapshotComparator;
44
import au.com.origin.snapshots.reporters.SnapshotReporter;
55
import au.com.origin.snapshots.serializers.SnapshotSerializer;
6-
import lombok.RequiredArgsConstructor;
7-
import lombok.SneakyThrows;
8-
96
import java.lang.reflect.Method;
107
import java.util.Arrays;
118
import java.util.HashMap;
129
import java.util.List;
1310
import java.util.Map;
11+
import lombok.RequiredArgsConstructor;
12+
import lombok.SneakyThrows;
1413

1514
@RequiredArgsConstructor
1615
public class Expect {
@@ -31,9 +30,9 @@ public static Expect of(SnapshotVerifier snapshotVerifier, Method method) {
3130
/**
3231
* Make an assertion on the given input parameters against what already exists
3332
*
34-
* If you were previously using varargs and see an error - you can fix the error using
35-
* "toMatchSnapshotLegacy", however, a better approach is to use the ".scenario()"
36-
* feature as future versions of this library will most likely remove the legacy implementation completely.
33+
* <p>If you were previously using varargs and see an error - you can fix the error using
34+
* "toMatchSnapshotLegacy", however, a better approach is to use the ".scenario()" feature as
35+
* future versions of this library will most likely remove the legacy implementation completely.
3736
*
3837
* @param object snapshot object
3938
*/
@@ -58,9 +57,9 @@ public void toMatchSnapshot(Object object) {
5857

5958
/**
6059
* Normally a snapshot can be applied only once to a test method.
61-
* <p>
62-
* For Parameterized tests where the same method is executed multiple times you can supply
63-
* the scenario() to overcome this restriction. Ensure each scenario is unique.
60+
*
61+
* <p>For Parameterized tests where the same method is executed multiple times you can supply the
62+
* scenario() to overcome this restriction. Ensure each scenario is unique.
6463
*
6564
* @param scenario - unique scenario description
6665
* @return Snapshot
@@ -115,8 +114,8 @@ public Expect comparator(String name) {
115114
}
116115

117116
/**
118-
* Apply a list of custom reporters for this snapshot
119-
* This will replace the default reporters defined in the config
117+
* Apply a list of custom reporters for this snapshot This will replace the default reporters
118+
* defined in the config
120119
*
121120
* @param reporters your custom reporters
122121
* @return Snapshot
@@ -127,8 +126,8 @@ public Expect reporters(SnapshotReporter... reporters) {
127126
}
128127

129128
/**
130-
* Apply a list of custom reporters for this snapshot
131-
* This will replace the default reporters defined in the config
129+
* Apply a list of custom reporters for this snapshot This will replace the default reporters
130+
* defined in the config
132131
*
133132
* @param name the {name} attribute reporters.{name} from snapshot.properties
134133
* @return Snapshot
@@ -144,8 +143,7 @@ public Expect reporters(String name) {
144143
* @param serializer your custom serializer
145144
* @return this
146145
* @see au.com.origin.snapshots.serializers.SnapshotSerializer
147-
* <p>
148-
* Example implementations
146+
* <p>Example implementations
149147
* @see au.com.origin.snapshots.serializers.ToStringSnapshotSerializer
150148
* @see au.com.origin.snapshots.serializers.Base64SnapshotSerializer
151149
*/
@@ -158,8 +156,8 @@ public Expect serializer(Class<? extends SnapshotSerializer> serializer) {
158156
/**
159157
* Add anything you like to the snapshot header.
160158
*
161-
* These custom headers can be used in serializers, comparators or reporters to change
162-
* how they behave.
159+
* <p>These custom headers can be used in serializers, comparators or reporters to change how they
160+
* behave.
163161
*
164162
* @param key key
165163
* @param value value
@@ -169,5 +167,4 @@ public Expect header(String key, String value) {
169167
headers.put(key, value);
170168
return this;
171169
}
172-
173170
}
Lines changed: 56 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,79 @@
11
package au.com.origin.snapshots;
22

33
import au.com.origin.snapshots.exceptions.LogGithubIssueException;
4+
import java.util.regex.Matcher;
5+
import java.util.regex.Pattern;
46
import lombok.Builder;
57
import lombok.EqualsAndHashCode;
68
import lombok.Getter;
79
import lombok.RequiredArgsConstructor;
810

9-
import java.util.regex.Matcher;
10-
import java.util.regex.Pattern;
11-
1211
@EqualsAndHashCode
1312
@Builder
1413
@Getter
1514
@RequiredArgsConstructor
1615
public class Snapshot implements Comparable<Snapshot> {
1716

18-
private final String name;
19-
private final String scenario;
20-
private final SnapshotHeader header;
21-
private final String body;
22-
23-
@Override
24-
public int compareTo(Snapshot other) {
25-
return (name + scenario).compareTo(other.name + other.scenario);
26-
}
17+
private final String name;
18+
private final String scenario;
19+
private final SnapshotHeader header;
20+
private final String body;
2721

28-
public String getIdentifier() {
29-
return scenario == null ? name : String.format("%s[%s]", name, scenario);
30-
}
22+
@Override
23+
public int compareTo(Snapshot other) {
24+
return (name + scenario).compareTo(other.name + other.scenario);
25+
}
3126

32-
public static Snapshot parse(String rawText) {
33-
String regex = "^(?<name>.*?)(\\[(?<scenario>.*)\\])?=(?<header>\\{.*\\})?(?<snapshot>(.*)$)";
34-
Pattern p = Pattern.compile(regex, Pattern.DOTALL);
35-
Matcher m = p.matcher(rawText);
36-
boolean found = m.find();
37-
if (!found) {
38-
throw new LogGithubIssueException(
39-
"Corrupt Snapshot (REGEX matches = 0): possibly due to manual editing or our REGEX failing\n" +
40-
"Possible Solutions\n" +
41-
"1. Ensure you have not accidentally manually edited the snapshot file!\n" +
42-
"2. Compare the snapshot with GIT history"
43-
);
44-
}
27+
public String getIdentifier() {
28+
return scenario == null ? name : String.format("%s[%s]", name, scenario);
29+
}
4530

46-
String name = m.group("name");
47-
String scenario = m.group("scenario");
48-
String header = m.group("header");
49-
String snapshot = m.group("snapshot");
31+
public static Snapshot parse(String rawText) {
32+
String regex = "^(?<name>.*?)(\\[(?<scenario>.*)\\])?=(?<header>\\{.*\\})?(?<snapshot>(.*)$)";
33+
Pattern p = Pattern.compile(regex, Pattern.DOTALL);
34+
Matcher m = p.matcher(rawText);
35+
boolean found = m.find();
36+
if (!found) {
37+
throw new LogGithubIssueException(
38+
"Corrupt Snapshot (REGEX matches = 0): possibly due to manual editing or our REGEX failing\n"
39+
+ "Possible Solutions\n"
40+
+ "1. Ensure you have not accidentally manually edited the snapshot file!\n"
41+
+ "2. Compare the snapshot with GIT history");
42+
}
5043

51-
if (name == null || snapshot == null) {
52-
throw new LogGithubIssueException(
53-
"Corrupt Snapshot (REGEX name or snapshot group missing): possibly due to manual editing or our REGEX failing\n" +
54-
"Possible Solutions\n" +
55-
"1. Ensure you have not accidentally manually edited the snapshot file\n" +
56-
"2. Compare the snapshot with your version control history"
57-
);
58-
}
44+
String name = m.group("name");
45+
String scenario = m.group("scenario");
46+
String header = m.group("header");
47+
String snapshot = m.group("snapshot");
5948

60-
return Snapshot.builder()
61-
.name(name)
62-
.scenario(scenario)
63-
.header(SnapshotHeader.fromJson(header))
64-
.body(snapshot)
65-
.build();
49+
if (name == null || snapshot == null) {
50+
throw new LogGithubIssueException(
51+
"Corrupt Snapshot (REGEX name or snapshot group missing): possibly due to manual editing or our REGEX failing\n"
52+
+ "Possible Solutions\n"
53+
+ "1. Ensure you have not accidentally manually edited the snapshot file\n"
54+
+ "2. Compare the snapshot with your version control history");
6655
}
6756

68-
/**
69-
* The raw string representation of the snapshot as it would appear in the *.snap file.
70-
*
71-
* @return raw snapshot
72-
*/
73-
public String raw() {
74-
String headerJson = (header == null) || (header.size() == 0) ? "" : header.toJson();
75-
return getIdentifier() + "=" + headerJson + body;
76-
}
57+
return Snapshot.builder()
58+
.name(name)
59+
.scenario(scenario)
60+
.header(SnapshotHeader.fromJson(header))
61+
.body(snapshot)
62+
.build();
63+
}
7764

78-
@Override
79-
public String toString() {
80-
return raw();
81-
}
65+
/**
66+
* The raw string representation of the snapshot as it would appear in the *.snap file.
67+
*
68+
* @return raw snapshot
69+
*/
70+
public String raw() {
71+
String headerJson = (header == null) || (header.size() == 0) ? "" : header.toJson();
72+
return getIdentifier() + "=" + headerJson + body;
73+
}
74+
75+
@Override
76+
public String toString() {
77+
return raw();
78+
}
8279
}

0 commit comments

Comments
 (0)