Skip to content

Commit

Permalink
Merge branch 'java21-specifics'
Browse files Browse the repository at this point in the history
  • Loading branch information
jqno committed Dec 14, 2024
2 parents 407cb42 + f73632d commit 6c101b9
Show file tree
Hide file tree
Showing 20 changed files with 138 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Tools like IntelliJ, Spotbugs and ErrorProne now report when you forget to call `.verify()` at the end of an EqualsVerifier invocation (through the `@CheckReturnValue` annotation).
- Adds prefab values for Java 21's `SequencedCollection`, `SequencedSet` and `SequencedMap`.

## [3.17.5] - 2024-12-06

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nl.jqno.equalsverifier.internal.reflection;
package nl.jqno.equalsverifier.internal.versionspecific;

public final class ModuleHelper {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nl.jqno.equalsverifier.internal.reflection;
package nl.jqno.equalsverifier.internal.versionspecific;

public final class RecordsHelper {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

import nl.jqno.equalsverifier.EqualsVerifier;
import nl.jqno.equalsverifier.Warning;
import nl.jqno.equalsverifier.internal.reflection.RecordsHelper;
import nl.jqno.equalsverifier.internal.testhelpers.ExpectedException;
import nl.jqno.equalsverifier.internal.versionspecific.RecordsHelper;
import org.junit.jupiter.api.Test;

public class RecordsTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nl.jqno.equalsverifier.internal.reflection;
package nl.jqno.equalsverifier.internal.versionspecific;

import java.lang.reflect.Modifier;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nl.jqno.equalsverifier.internal.reflection;
package nl.jqno.equalsverifier.internal.versionspecific;

import static org.junit.jupiter.api.Assertions.assertEquals;

Expand Down
2 changes: 0 additions & 2 deletions equalsverifier-21/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@
<groupId>nl.jqno.equalsverifier</groupId>
<artifactId>equalsverifier-16</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>nl.jqno.equalsverifier</groupId>
<artifactId>equalsverifier-core</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package nl.jqno.equalsverifier.internal.versionspecific;

import static nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories.Factories.collection;
import static nl.jqno.equalsverifier.internal.instantiation.vintage.prefabvalues.factories.Factories.map;

import java.util.*;

import nl.jqno.equalsverifier.internal.instantiation.vintage.FactoryCache;

public final class SequencedCollectionsHelper {

private SequencedCollectionsHelper() {}

public static void add(FactoryCache factoryCache) {
factoryCache.put(SequencedCollection.class, collection(ArrayList::new));
factoryCache.put(SequencedSet.class, collection(LinkedHashSet::new));
factoryCache.put(SequencedMap.class, map(LinkedHashMap::new));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package nl.jqno.equalsverifier.integration.extended_contract;

import java.util.*;

import nl.jqno.equalsverifier.EqualsVerifier;
import org.junit.jupiter.api.Test;

public class SequencedCollectionsClassesTest {

@Test
public void succeed_whenClassContainsSequencedCollections() {
EqualsVerifier.forClass(SequencedCollectionContainer.class).verify();
}

static final class SequencedCollectionContainer {

private final SequencedCollection<String> collection;
private final SequencedSet<String> set;
private final SequencedMap<String, String> map;

public SequencedCollectionContainer(
SequencedCollection<String> collection,
SequencedSet<String> set,
SequencedMap<String, String> map) {
this.collection = collection;
this.set = set;
this.map = map;
}

@Override
public boolean equals(Object obj) {
return this == obj
|| (obj instanceof SequencedCollectionContainer other
&& Objects.equals(collection, other.collection)
&& Objects.equals(set, other.set)
&& Objects.equals(map, other.map));
}

@Override
public int hashCode() {
// Trigger behavior that requires prefab values by calling abstract methods
if (collection != null) {
collection.reversed();
}
if (set != null) {
set.reversed();
}
if (map != null) {
map.reversed();
}
return Objects.hash(collection, set, map);
}

protected void callIterator(Iterable<?>... collections) {
for (Iterable<?> c : collections) {
if (c != null) {
c.iterator();
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<component
<component
xmlns="http://maven.apache.org/ASSEMBLY-COMPONENT/2.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY-COMPONENT/2.1.0 http://maven.apache.org/xsd/assembly-component-2.1.0.xsd">
Expand Down Expand Up @@ -67,6 +67,22 @@
</unpackOptions>
</binaries>
</moduleSet>
<moduleSet>
<useAllReactorProjects>true</useAllReactorProjects>
<includes>
<include>nl.jqno.equalsverifier:equalsverifier-21</include>
</includes>
<binaries>
<outputDirectory>META-INF/versions/21</outputDirectory>
<unpack>true</unpack>
<includeDependencies>false</includeDependencies>
<unpackOptions>
<excludes>
<exclude>/META-INF/**</exclude>
</excludes>
</unpackOptions>
</binaries>
</moduleSet>
</moduleSets>
</component>

Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import nl.jqno.equalsverifier.internal.reflection.ConditionalInstantiator;
import nl.jqno.equalsverifier.internal.reflection.Tuple;
import nl.jqno.equalsverifier.internal.reflection.TypeTag;
import nl.jqno.equalsverifier.internal.versionspecific.SequencedCollectionsHelper;

/**
* Creates instances of classes for use in a {@link VintageValueProvider} object.
Expand Down Expand Up @@ -94,6 +95,7 @@ private void addJavaClasses() {
addMaps();
addSets();
addQueues();
SequencedCollectionsHelper.add(factoryCache);
addNioBuffers();
addExceptions();
addReflectionClasses();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import java.util.LinkedHashSet;

import nl.jqno.equalsverifier.internal.instantiation.vintage.VintageValueProvider;
import nl.jqno.equalsverifier.internal.reflection.RecordsHelper;
import nl.jqno.equalsverifier.internal.reflection.TypeTag;
import nl.jqno.equalsverifier.internal.versionspecific.RecordsHelper;
import org.objenesis.Objenesis;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

import java.lang.reflect.Modifier;

import nl.jqno.equalsverifier.internal.versionspecific.RecordsHelper;
import nl.jqno.equalsverifier.internal.versionspecific.SealedTypesHelper;

/**
* Provides read-only reflective access to a class.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import net.bytebuddy.dynamic.DynamicType;
import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
import net.bytebuddy.dynamic.scaffold.TypeValidation;
import nl.jqno.equalsverifier.internal.versionspecific.SealedTypesHelper;
import org.objenesis.Objenesis;
import org.objenesis.instantiator.ObjectInstantiator;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package nl.jqno.equalsverifier.internal.util;

import nl.jqno.equalsverifier.internal.reflection.ModuleHelper;
import nl.jqno.equalsverifier.internal.versionspecific.ModuleHelper;

public final class ErrorMessage {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nl.jqno.equalsverifier.internal.reflection;
package nl.jqno.equalsverifier.internal.versionspecific;

/**
* Note: this is a generic implementation for a multi-release jar class. See equalsverifier-11 submodule.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nl.jqno.equalsverifier.internal.reflection;
package nl.jqno.equalsverifier.internal.versionspecific;

/**
* Note: this is a generic implementation for a multi-release jar class. See equalsverifier-16 submodule.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nl.jqno.equalsverifier.internal.reflection;
package nl.jqno.equalsverifier.internal.versionspecific;

import java.util.Optional;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package nl.jqno.equalsverifier.internal.versionspecific;

import nl.jqno.equalsverifier.internal.instantiation.vintage.FactoryCache;

public final class SequencedCollectionsHelper {

private SequencedCollectionsHelper() {}

public static void add(FactoryCache factoryCache) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ public void assertPresenceOfCoreClasses() {

public void assertPresenceOfMultiReleaseClasses() {
assertPresenceOf(
"/META-INF/versions/11" + EV + "/internal/reflection/ModuleHelper.class",
"/META-INF/versions/16" + EV + "/internal/reflection/RecordsHelper.class",
"/META-INF/versions/17" + EV + "/internal/reflection/SealedTypesHelper.class");
"/META-INF/versions/11" + EV + "/internal/versionspecific/ModuleHelper.class",
"/META-INF/versions/16" + EV + "/internal/versionspecific/RecordsHelper.class",
"/META-INF/versions/17" + EV + "/internal/versionspecific/SealedTypesHelper.class",
"/META-INF/versions/21" + EV + "/internal/versionspecific/SequencedCollectionsHelper.class");
}

public void assertPresenceOfEmbeddedDepedencies() {
Expand Down Expand Up @@ -83,14 +84,21 @@ private void assertContains(String needle, String haystack, String innerFilename
}

public void assertVersionsOfClassFiles() {
// See https://javaalmanac.io/bytecode/versions/
assertAll(
() -> assertVersionOfClassFile(52, EV + "/EqualsVerifier.class"),
() -> assertVersionOfClassFile(
55,
"/META-INF/versions/11" + EV + "/internal/versionspecific/ModuleHelper.class"),
() -> assertVersionOfClassFile(
60,
"/META-INF/versions/16" + EV + "/internal/reflection/RecordsHelper.class"),
"/META-INF/versions/16" + EV + "/internal/versionspecific/RecordsHelper.class"),
() -> assertVersionOfClassFile(
61,
"/META-INF/versions/17" + EV + "/internal/reflection/SealedTypesHelper.class"));
"/META-INF/versions/17" + EV + "/internal/versionspecific/SealedTypesHelper.class"),
() -> assertVersionOfClassFile(
65,
"/META-INF/versions/21" + EV + "/internal/versionspecific/SequencedCollectionsHelper.class"));
}

public void assertVersionsOfEmbeddedClassFiles() {
Expand Down

0 comments on commit 6c101b9

Please sign in to comment.