Skip to content

Commit

Permalink
Merge pull request #59 from sebastian-toepfer/improve_error_prone_con…
Browse files Browse the repository at this point in the history
…figuration

change severity of some error prone check from warn to error
  • Loading branch information
sebastian-toepfer authored Nov 18, 2023
2 parents 05a572d + baaae83 commit 8e69834
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 28 deletions.
5 changes: 5 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
<artifactId>hamcrest-optional</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_annotations</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>jakarta.json</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public boolean hasName(final String name) {
}

@Override
@SuppressWarnings("BigDecimalEquals")
public boolean isValidFor(final JsonValue instance) {
return (
!InstanceType.NUMBER.isInstance(instance) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,12 @@ public int hashCode() {
@Override
public boolean equals(final Object obj) {
return (
this == obj || (obj != null && getClass() == obj.getClass() && equals((JsonValueNumberEqualsFix) obj))
this == obj || (obj != null && getClass() == obj.getClass() && isEquals((JsonValueNumberEqualsFix) obj))
);
}

private boolean equals(final JsonValueNumberEqualsFix other) {
@SuppressWarnings("BigDecimalEquals")
private boolean isEquals(final JsonValueNumberEqualsFix other) {
final boolean result;
if (isNumber() && other.isNumber()) {
result = normalizeValue().equals(other.normalizeValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
class JsonTestSuiteTestCaseProvider implements ArgumentsProvider {

@Override
@SuppressWarnings("MustBeClosedChecker")
public Stream<? extends Arguments> provideArguments(final ExtensionContext context) throws Exception {
return new Resources()
.all()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public Resources(final String baseDir) {
this.baseDir = baseDir;
}

@com.google.errorprone.annotations.MustBeClosed
Stream<Resource> all() {
try {
return StreamSupport
Expand Down Expand Up @@ -83,6 +84,7 @@ public PathResources(final Path path) {
this.path = Objects.requireNonNull(path);
}

@SuppressWarnings("StreamResourceLeak")
Stream<Resource> toResources() {
final Stream<Resource> result;
try {
Expand Down
1 change: 1 addition & 0 deletions core/src/test/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
requires io.github.sebastiantoepfer.jsonschema.vocabulary.spi;
requires jakarta.json;

requires com.google.errorprone.annotations;
requires org.junit.jupiter.api;
requires org.junit.jupiter.params;
requires org.junit.jupiter.engine;
Expand Down
21 changes: 20 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@
<artifactId>spotbugs-annotations</artifactId>
<version>4.8.1</version>
</dependency>
<dependency>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_annotations</artifactId>
<version>2.23.0</version>
</dependency>

<dependency>
<groupId>org.junit</groupId>
Expand Down Expand Up @@ -121,7 +126,21 @@
<configuration>
<compilerArgs>
<arg>-XDcompilePolicy=simple</arg>
<arg>-Xplugin:ErrorProne</arg>
<arg>
-Xplugin:ErrorProne \
-XepExcludedPaths:.*/target/generated-sources/.* \
-Xep:EqualsGetClass:OFF \
-Xep:MissingOverride:ERROR \
-Xep:DefaultCharset:ERROR \
-Xep:BadImport:ERROR \
-Xep:TypeParameterShadowing:ERROR \
-Xep:NonCanonicalType:ERROR \
-Xep:EqualsIncompatibleType:ERROR \
-Xep:BigDecimalEquals:ERROR \
-Xep:UndefinedEquals:ERROR \
-Xep:StreamResourceLeak:ERROR \
-Xep:NonOverridingEquals:ERROR
</arg>
</compilerArgs>
<annotationProcessorPaths>
<path>
Expand Down
4 changes: 4 additions & 0 deletions testsuite-junit-platform-engine/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-annotations</artifactId>
</dependency>
<dependency>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_annotations</artifactId>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ public String getId() {
@Override
public TestDescriptor discover(final EngineDiscoveryRequest discoveryRequest, final UniqueId uniqueId) {
final TestDescriptor result = new EngineDescriptor(uniqueId, "Json Schema Test");
new Resources()
.all()
.filter(resource -> resource.hasExtension("json"))
.map(JsonSchemaSuitesTestDescriptor::new)
.forEach(result::addChild);
try (final Stream<Resource> res = new Resources().all()) {
res
.filter(resource -> resource.hasExtension("json"))
.map(JsonSchemaSuitesTestDescriptor::new)
.forEach(result::addChild);
}
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public Resources(final String baseDir) {
this.baseDir = baseDir;
}

@com.google.errorprone.annotations.MustBeClosed
Stream<Resource> all() {
try {
return StreamSupport
Expand Down Expand Up @@ -83,6 +84,7 @@ public PathResources(final Path path) {
this.path = Objects.requireNonNull(path);
}

@SuppressWarnings("StreamResourceLeak")
Stream<Resource> toResources() {
final Stream<Resource> result;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@
requires org.junit.platform.engine;
requires org.junit.platform.commons;
requires com.github.spotbugs.annotations;
requires com.google.errorprone.annotations;
requires jakarta.json;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

import io.github.sebastiantoepfer.jsonschema.testsuite.junit.engine.Resource;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import nl.jqno.equalsverifier.EqualsVerifier;
import org.junit.jupiter.api.Test;

Expand All @@ -45,16 +46,18 @@ void should_determine_name() {

@Test
void should_return_content() throws Exception {
assertThat(
new String(new Resource("tests/test_resource.json").content().readAllBytes()),
is(
"""
{
"name": "sebastian"
}
"""
)
);
try (final InputStream content = new Resource("tests/test_resource.json").content()) {
assertThat(
new String(content.readAllBytes(), StandardCharsets.UTF_8),
is(
"""
{
"name": "sebastian"
}
"""
)
);
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,30 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasItems;

import io.github.sebastiantoepfer.jsonschema.testsuite.junit.engine.Resource;
import io.github.sebastiantoepfer.jsonschema.testsuite.junit.engine.Resources;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;

class ResourcesTest {

@Test
void should_find_resources_from_classpath() {
assertThat(new Resources().all().toList(), hasItems(new Resource("tests/test_resource.json")));
try (final Stream<Resource> res = new Resources().all()) {
assertThat(res.toList(), hasItems(new Resource("tests/test_resource.json")));
}
}

@Test
void should_find_resources_in_subdir_from_classpath() {
assertThat(new Resources("tests").all().toList(), hasItems(new Resource("tests/test_resource.json")));
try (final Stream<Resource> res = new Resources("tests").all()) {
assertThat(res.toList(), hasItems(new Resource("tests/test_resource.json")));
}
}

@Test
void should_find_resources_in_metainf() {
//to kill all mutants, we need a resource from non-test classpath
assertThat(
new Resources("META-INF").all().toList(),
hasItems(new Resource("META-INF/services/org.junit.platform.engine.TestEngine"))
);
try (final Stream<Resource> res = new Resources("META-INF").all()) {
//to kill all mutants, we need a resource from non-test classpath
assertThat(res.toList(), hasItems(new Resource("META-INF/services/org.junit.platform.engine.TestEngine")));
}
}
}

0 comments on commit 8e69834

Please sign in to comment.