Skip to content

Commit 8ccdd0e

Browse files
chore: fix and suppresss codequality warnings
1 parent 597e174 commit 8ccdd0e

88 files changed

Lines changed: 1787 additions & 1646 deletions

File tree

Some content is hidden

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

‎pom.xml‎

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@
3838

3939
<!-- <spring-boot.version>3.5.9</spring-boot.version>-->
4040

41-
<code-quality.feature.enabled>false</code-quality.feature.enabled>
42-
<!-- <code-quality.configuration.checkstyle.suppression-location>checkstyle/checkstyle-suppressions.xml-->
43-
<!-- </code-quality.configuration.checkstyle.suppression-location>-->
41+
<codequality-maven-plugin.version>0.12.8</codequality-maven-plugin.version>
42+
<code-quality.feature.enabled>true</code-quality.feature.enabled>
4443
</properties>
4544

4645
<modules>
@@ -180,6 +179,52 @@
180179
<build>
181180
<plugins>
182181

182+
<plugin>
183+
<groupId>io.github.finoid</groupId>
184+
<artifactId>codequality-maven-plugin</artifactId>
185+
<version>${codequality-maven-plugin.version}</version>
186+
<!-- The plugin must be registered as an extension for the error-prone static analyzer to function properly -->
187+
<extensions>true</extensions>
188+
<executions>
189+
<execution>
190+
<id>maven-code-quality</id>
191+
<phase>verify</phase>
192+
<goals>
193+
<goal>code-quality</goal>
194+
</goals>
195+
</execution>
196+
</executions>
197+
<configuration>
198+
<codeQuality>
199+
<enabled>${code-quality.feature.enabled}</enabled>
200+
<stepLogLevel>DEBUG</stepLogLevel>
201+
<violationFilters>DIFF_COVERAGE</violationFilters>
202+
<checkstyle>
203+
<enabled>${code-quality.feature.checkstyle}</enabled>
204+
<permissive>${code-quality.feature.checkstyle.permissive}</permissive>
205+
<executionMain>
206+
<suppressionLocation>${code-quality.configuration.checkstyle.suppression-location}
207+
</suppressionLocation>
208+
</executionMain>
209+
<executionTest>
210+
<suppressionLocation>${code-quality.configuration.checkstyle.suppression-location}
211+
</suppressionLocation>
212+
</executionTest>
213+
</checkstyle>
214+
<errorProne>
215+
<enabled>${code-quality.feature.error-prone}</enabled>
216+
<permissive>${code-quality.feature.error-prone.permissive}</permissive>
217+
<nullAwayEnabled>${code-quality.feature.null-away}</nullAwayEnabled>
218+
</errorProne>
219+
<checkerFramework>
220+
<enabled>${code-quality.feature.checker-framework}</enabled>
221+
<permissive>${code-quality.feature.checker-framework.permissive}</permissive>
222+
</checkerFramework>
223+
</codeQuality>
224+
</configuration>
225+
</plugin>
226+
227+
183228
<plugin>
184229
<groupId>org.apache.maven.plugins</groupId>
185230
<artifactId>maven-enforcer-plugin</artifactId>

‎snapshot-testing-core/pom.xml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0"
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns="http://maven.apache.org/POM/4.0.0"
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
66
<parent>
@@ -66,7 +66,7 @@
6666
<dependency>
6767
<groupId>org.opentest4j</groupId>
6868
<artifactId>opentest4j</artifactId>
69-
<version>1.2.0</version>
69+
<version>1.3.0</version>
7070
</dependency>
7171

7272
<!-- testImplementation -->

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

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,18 @@
1616
public class Expect {
1717
private final SnapshotVerifier snapshotVerifier;
1818
private final Method testMethod;
19-
19+
private final Map<String, String> headers = new HashMap<>();
2020
private SnapshotSerializer snapshotSerializer;
2121
private SnapshotComparator snapshotComparator;
2222
private List<SnapshotReporter> snapshotReporters;
2323
private String scenario;
2424

25-
private final Map<String, String> headers = new HashMap<>();
26-
2725
public static Expect of(SnapshotVerifier snapshotVerifier, Method method) {
2826
return new Expect(snapshotVerifier, method);
2927
}
3028

3129
/**
32-
* Make an assertion on the given input parameters against what already exists
30+
* Make an assertion on the given input parameters against what already exists.
3331
*
3432
* <p>If you were previously using varargs and see an error - you can fix the error using
3533
* "toMatchSnapshotLegacy", however, a better approach is to use the ".scenario()" feature as
@@ -51,7 +49,7 @@ public void toMatchSnapshot(Object object) {
5149
if (scenario != null) {
5250
snapshotContext.setScenario(scenario);
5351
}
54-
snapshotContext.header.putAll(headers);
52+
snapshotContext.getHeader().putAll(headers);
5553

5654
snapshotContext.checkValidContext();
5755

@@ -73,7 +71,7 @@ public Expect scenario(String scenario) {
7371
}
7472

7573
/**
76-
* Apply a custom serializer for this snapshot
74+
* Apply a custom serializer for this snapshot.
7775
*
7876
* @param serializer your custom serializer
7977
* @return Snapshot
@@ -84,7 +82,7 @@ public Expect serializer(SnapshotSerializer serializer) {
8482
}
8583

8684
/**
87-
* Apply a custom serializer for this snapshot
85+
* Apply a custom serializer for this snapshot.
8886
*
8987
* @param name - the {name} attribute serializer.{name} from snapshot.properties
9088
* @return Snapshot
@@ -95,7 +93,22 @@ public Expect serializer(String name) {
9593
}
9694

9795
/**
98-
* Apply a custom comparator for this snapshot
96+
* Apply a custom serializer for this snapshot.
97+
*
98+
* @param serializer your custom serializer
99+
* @return this
100+
* @see au.com.origin.snapshots.serializers.SnapshotSerializer
101+
* @see au.com.origin.snapshots.serializers.ToStringSnapshotSerializer
102+
* @see au.com.origin.snapshots.serializers.Base64SnapshotSerializer
103+
*/
104+
@SneakyThrows
105+
public Expect serializer(Class<? extends SnapshotSerializer> serializer) {
106+
this.snapshotSerializer = serializer.getConstructor().newInstance();
107+
return this;
108+
}
109+
110+
/**
111+
* Apply a custom comparator for this snapshot.
99112
*
100113
* @param comparator your custom comparator
101114
* @return Snapshot
@@ -106,7 +119,7 @@ public Expect comparator(SnapshotComparator comparator) {
106119
}
107120

108121
/**
109-
* Apply a custom comparator for this snapshot
122+
* Apply a custom comparator for this snapshot.
110123
*
111124
* @param name the {name} attribute comparator.{name} from snapshot.properties
112125
* @return Snapshot
@@ -118,7 +131,7 @@ public Expect comparator(String name) {
118131

119132
/**
120133
* Apply a list of custom reporters for this snapshot This will replace the default reporters
121-
* defined in the config
134+
* defined in the config.
122135
*
123136
* @param reporters your custom reporters
124137
* @return Snapshot
@@ -130,7 +143,7 @@ public Expect reporters(SnapshotReporter... reporters) {
130143

131144
/**
132145
* Apply a list of custom reporters for this snapshot This will replace the default reporters
133-
* defined in the config
146+
* defined in the config.
134147
*
135148
* @param name the {name} attribute reporters.{name} from snapshot.properties
136149
* @return Snapshot
@@ -140,22 +153,6 @@ public Expect reporters(String name) {
140153
return this;
141154
}
142155

143-
/**
144-
* Apply a custom serializer for this snapshot.
145-
*
146-
* @param serializer your custom serializer
147-
* @return this
148-
* @see au.com.origin.snapshots.serializers.SnapshotSerializer
149-
* <p>Example implementations
150-
* @see au.com.origin.snapshots.serializers.ToStringSnapshotSerializer
151-
* @see au.com.origin.snapshots.serializers.Base64SnapshotSerializer
152-
*/
153-
@SneakyThrows
154-
public Expect serializer(Class<? extends SnapshotSerializer> serializer) {
155-
this.snapshotSerializer = serializer.getConstructor().newInstance();
156-
return this;
157-
}
158-
159156
/**
160157
* Add anything you like to the snapshot header.
161158
*

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,6 @@ public class Snapshot implements Comparable<Snapshot> {
2020
private final SnapshotHeader header;
2121
private final String body;
2222

23-
@Override
24-
public int compareTo(Snapshot other) {
25-
return (name + scenario).compareTo(other.name + other.scenario);
26-
}
27-
28-
public String getIdentifier() {
29-
return scenario == null ? name : String.format("%s[%s]", name, scenario);
30-
}
31-
3223
public static Snapshot parse(String rawText) {
3324
String regex =
3425
"^(?<name>.*?)(\\[(?<scenario>[^]]*)])?=(?<header>\\{[^}]*?})?(?<snapshot>(.*)$)";
@@ -64,6 +55,15 @@ public static Snapshot parse(String rawText) {
6455
.build();
6556
}
6657

58+
@Override
59+
public int compareTo(Snapshot other) {
60+
return (name + scenario).compareTo(other.name + other.scenario);
61+
}
62+
63+
public String getIdentifier() {
64+
return scenario == null ? name : String.format("%s[%s]", name, scenario);
65+
}
66+
6767
/**
6868
* The raw string representation of the snapshot as it would appear in the *.snap file.
6969
*

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

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,26 @@ public class SnapshotContext {
2727

2828
private final SnapshotConfig snapshotConfig;
2929
private final SnapshotFile snapshotFile;
30+
private final boolean isCI;
3031

3132
@Getter
32-
final Class<?> testClass;
33-
33+
private final Class<?> testClass;
3434
@Getter
35-
final Method testMethod;
36-
37-
final Object current;
38-
private final boolean isCI;
35+
private final Method testMethod;
36+
private final Object current;
3937

38+
@Setter
39+
@Getter
40+
private String scenario;
41+
@Getter
42+
private SnapshotHeader header = new SnapshotHeader();
4043
@Setter
4144
private SnapshotSerializer snapshotSerializer;
4245
@Setter
4346
private SnapshotComparator snapshotComparator;
4447
@Setter
4548
private List<SnapshotReporter> snapshotReporters;
4649

47-
@Setter
48-
@Getter
49-
String scenario;
50-
51-
@Getter
52-
SnapshotHeader header = new SnapshotHeader();
53-
5450
SnapshotContext(
5551
SnapshotConfig snapshotConfig,
5652
SnapshotFile snapshotFile,

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.stream.Stream;
2525

2626
@Slf4j
27+
@SuppressWarnings("checkstyle:all") // TODO (nw) rewrite
2728
public class SnapshotFile {
2829

2930
public static final String SPLIT_STRING = "\n\n\n";
@@ -45,10 +46,10 @@ public SnapshotFile(String srcDirPath, String fileName, Class<?> testClass) thro
4546
new BufferedReader(
4647
new InputStreamReader(new FileInputStream(this.fileName), StandardCharsets.UTF_8))) {
4748

48-
String sCurrentLine;
49+
String currentLine;
4950

50-
while ((sCurrentLine = br.readLine()) != null) {
51-
fileContent.append(sCurrentLine + "\n");
51+
while ((currentLine = br.readLine()) != null) {
52+
fileContent.append(currentLine + "\n");
5253
}
5354

5455
String fileText = fileContent.toString();
@@ -81,10 +82,10 @@ public File createDebugFile(Snapshot snapshot) {
8182
try (FileOutputStream fileStream = new FileOutputStream(file, false)) {
8283
fileStream.write(snapshot.raw().getBytes(StandardCharsets.UTF_8));
8384
} catch (IOException e) {
84-
e.printStackTrace();
85+
throw new RuntimeException("Unable to create debug file ", e);
8586
}
8687
} catch (IOException e) {
87-
e.printStackTrace();
88+
throw new RuntimeException("Unable to create debug file ", e);
8889
}
8990

9091
return file;
@@ -101,27 +102,28 @@ public void delete() {
101102
}
102103

103104
@SneakyThrows
104-
public synchronized File createFileIfNotExists(String filename) {
105-
Path path = Paths.get(filename);
105+
public synchronized File createFileIfNotExists(String fileName) {
106+
Path path = Paths.get(fileName);
106107
if (!Files.exists(path)) {
107108
Files.createDirectories(path.getParent());
108109
Files.createFile(path);
109110
}
110111
return path.toFile();
111112
}
112113

114+
@SuppressWarnings("SynchronizeOnNonFinalField") // TODO (nw) rewrite
113115
public void pushSnapshot(Snapshot snapshot) {
114116
synchronized (snapshots) {
115117
snapshots.add(snapshot);
116-
TreeSet<String> rawSnapshots =
118+
Set<String> rawSnapshots =
117119
snapshots.stream().map(Snapshot::raw).collect(Collectors.toCollection(TreeSet::new));
118120
updateFile(this.fileName, rawSnapshots);
119121
}
120122
}
121123

122124
public synchronized void pushDebugSnapshot(Snapshot snapshot) {
123125
debugSnapshots.add(snapshot);
124-
TreeSet<String> rawDebugSnapshots =
126+
Set<String> rawDebugSnapshots =
125127
debugSnapshots.stream().map(Snapshot::raw).collect(Collectors.toCollection(TreeSet::new));
126128
updateFile(getDebugFilename(), rawDebugSnapshots);
127129
}
@@ -132,7 +134,7 @@ private void updateFile(String fileName, Set<String> rawSnapshots) {
132134
byte[] myBytes = String.join(SPLIT_STRING, rawSnapshots).getBytes(StandardCharsets.UTF_8);
133135
fileStream.write(myBytes);
134136
} catch (IOException e) {
135-
e.printStackTrace();
137+
throw new RuntimeException("Unable to write debug file ", e);
136138
}
137139
}
138140

0 commit comments

Comments
 (0)