kopia lustrzana https://github.com/JOSM/MapWithAI
MapWithAIInfoTest: Add equals check
Signed-off-by: Taylor Smock <tsmock@fb.com>pull/1/head
rodzic
7acae1ca7f
commit
b350286a36
12
build.gradle
12
build.gradle
|
@ -8,9 +8,9 @@ import java.nio.file.Paths
|
|||
import java.util.stream.Collectors
|
||||
|
||||
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.spotbugs" version "5.0.6"
|
||||
id "com.github.spotbugs" version "5.0.7"
|
||||
// id "de.aaschmid.cpd" version "3.3"
|
||||
id "eclipse"
|
||||
id "jacoco"
|
||||
|
@ -112,16 +112,17 @@ sourceSets {
|
|||
|
||||
def versions = [
|
||||
awaitility: "4.2.0",
|
||||
equalsverifier: "3.10",
|
||||
// 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",
|
||||
jmockit: "1.49.a",
|
||||
josm: properties.get("plugin.compile.version"),
|
||||
junit: "5.8.2",
|
||||
pmd: "6.20.0",
|
||||
spotbugs: "4.7.0",
|
||||
wiremock: "2.33.2",
|
||||
findsecbugs: "1.12.0",
|
||||
josm: properties.get("plugin.compile.version"),
|
||||
]
|
||||
|
||||
dependencies {
|
||||
|
@ -141,6 +142,7 @@ dependencies {
|
|||
testFixturesImplementation("org.openstreetmap.josm:josm-unittest:"){changing=true}
|
||||
testFixturesImplementation("com.github.tomakehurst:wiremock-jre8:${versions.wiremock}")
|
||||
testFixturesImplementation("org.awaitility:awaitility:${versions.awaitility}")
|
||||
testImplementation("nl.jqno.equalsverifier:equalsverifier:${versions.equalsverifier}")
|
||||
}
|
||||
|
||||
configurations {
|
||||
|
|
|
@ -5,7 +5,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonArray;
|
||||
import javax.management.ReflectionException;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
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.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
|
||||
import org.openstreetmap.josm.tools.Logging;
|
||||
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import nl.jqno.equalsverifier.Warning;
|
||||
|
||||
@BasicPreferences
|
||||
class MapWithAIInfoTest {
|
||||
|
||||
@ParameterizedTest
|
||||
|
@ -60,13 +64,13 @@ class MapWithAIInfoTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
void testCloneInitializer() throws ReflectionException, IllegalArgumentException, IllegalAccessException {
|
||||
void testCloneInitializer() throws IllegalArgumentException, IllegalAccessException {
|
||||
final List<String> ignoredFields = Collections
|
||||
.singletonList("replacementTagsSupplier" /* The supplier shouldn't be copied */);
|
||||
MapWithAIInfo orig = new MapWithAIInfo("Test info");
|
||||
// Use random to ensure that I do not accidentally introduce a dependency
|
||||
Random random = new Random();
|
||||
Long seed = random.nextLong();
|
||||
long seed = random.nextLong();
|
||||
random.setSeed(seed);
|
||||
Logging.debug("Random seed for testCloneInitializer is {0}", seed);
|
||||
for (Field f : MapWithAIInfo.class.getDeclaredFields()) {
|
||||
|
@ -82,7 +86,7 @@ class MapWithAIInfoTest {
|
|||
} else if (f.getType().isAssignableFrom(Boolean.TYPE)) {
|
||||
f.setBoolean(orig, !f.getBoolean(orig)); // just set to non-default
|
||||
} 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)) {
|
||||
List<?> list = new ArrayList<>();
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEquals() {
|
||||
EqualsVerifier.forClass(MapWithAIInfo.class).suppress(Warning.NONFINAL_FIELDS)
|
||||
.withOnlyTheseFields("url", "sourceType").usingGetClass().verify();
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue