MapWithAIInfoTest: Add equals check

Signed-off-by: Taylor Smock <tsmock@fb.com>
pull/1/head
Taylor Smock 2022-05-31 16:12:00 -06:00
rodzic 7acae1ca7f
commit b350286a36
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 625F6A74A3E4311A
2 zmienionych plików z 21 dodań i 9 usunięć

Wyświetl plik

@ -8,9 +8,9 @@ import java.nio.file.Paths
import java.util.stream.Collectors import java.util.stream.Collectors
plugins { plugins {
id "com.diffplug.spotless" version "6.6.0" id "com.diffplug.spotless" version "6.6.1"
id "com.github.ben-manes.versions" version "0.42.0" id "com.github.ben-manes.versions" version "0.42.0"
id "com.github.spotbugs" version "5.0.6" id "com.github.spotbugs" version "5.0.7"
// id "de.aaschmid.cpd" version "3.3" // id "de.aaschmid.cpd" version "3.3"
id "eclipse" id "eclipse"
id "jacoco" id "jacoco"
@ -112,16 +112,17 @@ sourceSets {
def versions = [ def versions = [
awaitility: "4.2.0", awaitility: "4.2.0",
equalsverifier: "3.10",
// Errorprone 2.11 requires Java 11+ // Errorprone 2.11 requires Java 11+
errorprone: (JavaVersion.toVersion(getJavaVersion()) >= JavaVersion.VERSION_11) ? "2.13.1" : "2.10.0", errorprone: (JavaVersion.toVersion(getJavaVersion()) >= JavaVersion.VERSION_11) ? "2.14.0" : "2.10.0",
findsecbugs: "1.12.0",
jacoco: "0.8.7", jacoco: "0.8.7",
jmockit: "1.49.a", jmockit: "1.49.a",
josm: properties.get("plugin.compile.version"),
junit: "5.8.2", junit: "5.8.2",
pmd: "6.20.0", pmd: "6.20.0",
spotbugs: "4.7.0", spotbugs: "4.7.0",
wiremock: "2.33.2", wiremock: "2.33.2",
findsecbugs: "1.12.0",
josm: properties.get("plugin.compile.version"),
] ]
dependencies { dependencies {
@ -141,6 +142,7 @@ dependencies {
testFixturesImplementation("org.openstreetmap.josm:josm-unittest:"){changing=true} testFixturesImplementation("org.openstreetmap.josm:josm-unittest:"){changing=true}
testFixturesImplementation("com.github.tomakehurst:wiremock-jre8:${versions.wiremock}") testFixturesImplementation("com.github.tomakehurst:wiremock-jre8:${versions.wiremock}")
testFixturesImplementation("org.awaitility:awaitility:${versions.awaitility}") testFixturesImplementation("org.awaitility:awaitility:${versions.awaitility}")
testImplementation("nl.jqno.equalsverifier:equalsverifier:${versions.equalsverifier}")
} }
configurations { configurations {

Wyświetl plik

@ -5,7 +5,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import javax.json.Json; import javax.json.Json;
import javax.json.JsonArray; import javax.json.JsonArray;
import javax.management.ReflectionException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
@ -22,8 +21,13 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource; import org.junit.jupiter.params.provider.MethodSource;
import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
import org.openstreetmap.josm.tools.Logging; import org.openstreetmap.josm.tools.Logging;
import nl.jqno.equalsverifier.EqualsVerifier;
import nl.jqno.equalsverifier.Warning;
@BasicPreferences
class MapWithAIInfoTest { class MapWithAIInfoTest {
@ParameterizedTest @ParameterizedTest
@ -60,13 +64,13 @@ class MapWithAIInfoTest {
} }
@Test @Test
void testCloneInitializer() throws ReflectionException, IllegalArgumentException, IllegalAccessException { void testCloneInitializer() throws IllegalArgumentException, IllegalAccessException {
final List<String> ignoredFields = Collections final List<String> ignoredFields = Collections
.singletonList("replacementTagsSupplier" /* The supplier shouldn't be copied */); .singletonList("replacementTagsSupplier" /* The supplier shouldn't be copied */);
MapWithAIInfo orig = new MapWithAIInfo("Test info"); MapWithAIInfo orig = new MapWithAIInfo("Test info");
// Use random to ensure that I do not accidentally introduce a dependency // Use random to ensure that I do not accidentally introduce a dependency
Random random = new Random(); Random random = new Random();
Long seed = random.nextLong(); long seed = random.nextLong();
random.setSeed(seed); random.setSeed(seed);
Logging.debug("Random seed for testCloneInitializer is {0}", seed); Logging.debug("Random seed for testCloneInitializer is {0}", seed);
for (Field f : MapWithAIInfo.class.getDeclaredFields()) { for (Field f : MapWithAIInfo.class.getDeclaredFields()) {
@ -82,7 +86,7 @@ class MapWithAIInfoTest {
} else if (f.getType().isAssignableFrom(Boolean.TYPE)) { } else if (f.getType().isAssignableFrom(Boolean.TYPE)) {
f.setBoolean(orig, !f.getBoolean(orig)); // just set to non-default f.setBoolean(orig, !f.getBoolean(orig)); // just set to non-default
} else if (f.getType().isAssignableFrom(String.class)) { } else if (f.getType().isAssignableFrom(String.class)) {
f.set(orig, "Random String Value " + Double.toString(random.nextDouble())); f.set(orig, "Random String Value " + random.nextDouble());
} else if (f.getType().isAssignableFrom(List.class)) { } else if (f.getType().isAssignableFrom(List.class)) {
List<?> list = new ArrayList<>(); List<?> list = new ArrayList<>();
list.add(null); list.add(null);
@ -107,4 +111,10 @@ class MapWithAIInfoTest {
assertEquals(f.get(orig), f.get(copy), MessageFormat.format("{0} should be the same", f.getName())); assertEquals(f.get(orig), f.get(copy), MessageFormat.format("{0} should be the same", f.getName()));
} }
} }
@Test
void testEquals() {
EqualsVerifier.forClass(MapWithAIInfo.class).suppress(Warning.NONFINAL_FIELDS)
.withOnlyTheseFields("url", "sourceType").usingGetClass().verify();
}
} }