-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
...st/java/nl/jqno/equalsverifier/internal/reflection/vintage/RecordFallbackFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package nl.jqno.equalsverifier.internal.reflection.vintage; | ||
|
||
import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.values; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotSame; | ||
|
||
import java.util.LinkedHashSet; | ||
import nl.jqno.equalsverifier.internal.reflection.FactoryCache; | ||
import nl.jqno.equalsverifier.internal.reflection.Tuple; | ||
import nl.jqno.equalsverifier.internal.reflection.TypeTag; | ||
import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; | ||
import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.FallbackFactory; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.objenesis.Objenesis; | ||
import org.objenesis.ObjenesisStd; | ||
|
||
public class RecordFallbackFactoryTest { | ||
|
||
private FallbackFactory<?> factory; | ||
private VintageValueProvider valueProvider; | ||
private LinkedHashSet<TypeTag> typeStack; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
Objenesis objenesis = new ObjenesisStd(); | ||
factory = new FallbackFactory<>(objenesis); | ||
FactoryCache factoryCache = new FactoryCache(); | ||
factoryCache.put(int.class, values(42, 1337, 42)); | ||
valueProvider = new VintageValueProvider(factoryCache, objenesis); | ||
typeStack = new LinkedHashSet<>(); | ||
} | ||
|
||
@Test | ||
public void redCopyHasTheSameValuesAsRed_whenSutContainsGenericValueThatNeedsToBeIdenticalInRedAndRedCopy() { | ||
Tuple<?> tuple = factory.createValues( | ||
new TypeTag(GenericRecordContainer.class), | ||
valueProvider, | ||
typeStack | ||
); | ||
|
||
assertEquals(tuple.getRed(), tuple.getRedCopy()); | ||
assertNotSame(tuple.getRed(), tuple.getRedCopy()); | ||
} | ||
|
||
record GenericRecord<T>(T t) {} | ||
|
||
record GenericRecordContainer(GenericRecord<?> bgr) {} | ||
} |
85 changes: 85 additions & 0 deletions
85
...va/nl/jqno/equalsverifier/internal/reflection/vintage/SealedTypesFallbackFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package nl.jqno.equalsverifier.internal.reflection.vintage; | ||
|
||
import static nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.Factories.values; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotSame; | ||
|
||
import java.util.LinkedHashSet; | ||
import java.util.Objects; | ||
import nl.jqno.equalsverifier.internal.reflection.FactoryCache; | ||
import nl.jqno.equalsverifier.internal.reflection.Tuple; | ||
import nl.jqno.equalsverifier.internal.reflection.TypeTag; | ||
import nl.jqno.equalsverifier.internal.reflection.instantiation.VintageValueProvider; | ||
import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.FallbackFactory; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.objenesis.Objenesis; | ||
import org.objenesis.ObjenesisStd; | ||
|
||
public class SealedTypesFallbackFactoryTest { | ||
|
||
private FallbackFactory<?> factory; | ||
private VintageValueProvider valueProvider; | ||
private LinkedHashSet<TypeTag> typeStack; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
Objenesis objenesis = new ObjenesisStd(); | ||
factory = new FallbackFactory<>(objenesis); | ||
FactoryCache factoryCache = new FactoryCache(); | ||
factoryCache.put(int.class, values(42, 1337, 42)); | ||
valueProvider = new VintageValueProvider(factoryCache, objenesis); | ||
typeStack = new LinkedHashSet<>(); | ||
} | ||
|
||
@Test | ||
public void redCopyHasTheSameValuesAsRed_whenSutIsAbstractSealedAndPermittedTypeAddsField() { | ||
Tuple<?> tuple = factory.createValues( | ||
new TypeTag(SealedParentWithFinalChild.class), | ||
valueProvider, | ||
typeStack | ||
); | ||
|
||
assertEquals(tuple.getRed(), tuple.getRedCopy()); | ||
assertNotSame(tuple.getRed(), tuple.getRedCopy()); | ||
} | ||
|
||
public abstract static sealed class SealedParentWithFinalChild permits FinalSealedChild { | ||
|
||
private final int i; | ||
|
||
public SealedParentWithFinalChild(int i) { | ||
this.i = i; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
return obj instanceof SealedParentWithFinalChild other && i == other.i; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(i); | ||
} | ||
} | ||
|
||
public static final class FinalSealedChild extends SealedParentWithFinalChild { | ||
|
||
private final int j; | ||
|
||
public FinalSealedChild(int i, int j) { | ||
super(i); | ||
this.j = j; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
return obj instanceof FinalSealedChild other && super.equals(obj) && j == other.j; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(super.hashCode(), j); | ||
} | ||
} | ||
} |