-
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.
Merge pull request #1021 from jqno/add-cached-valueprovider
Add cached valueprovider
- Loading branch information
Showing
63 changed files
with
906 additions
and
628 deletions.
There are no files selected for viewing
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
51 changes: 51 additions & 0 deletions
51
...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,51 @@ | ||
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 nl.jqno.equalsverifier.internal.reflection.Tuple; | ||
import nl.jqno.equalsverifier.internal.reflection.TypeTag; | ||
import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; | ||
import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; | ||
import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.FallbackFactory; | ||
import nl.jqno.equalsverifier.internal.testhelpers.TestValueProviders; | ||
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 Attributes attributes; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
Objenesis objenesis = new ObjenesisStd(); | ||
factory = new FallbackFactory<>(objenesis); | ||
CachedValueProvider cache = new CachedValueProvider(); | ||
FactoryCache factoryCache = new FactoryCache(); | ||
factoryCache.put(int.class, values(42, 1337, 42)); | ||
valueProvider = | ||
new VintageValueProvider(TestValueProviders.empty(), cache, factoryCache, objenesis); | ||
attributes = Attributes.unlabeled(); | ||
} | ||
|
||
@Test | ||
public void redCopyHasTheSameValuesAsRed_whenSutContainsGenericValueThatNeedsToBeIdenticalInRedAndRedCopy() { | ||
Tuple<?> tuple = factory.createValues( | ||
new TypeTag(GenericRecordContainer.class), | ||
valueProvider, | ||
attributes | ||
); | ||
|
||
assertEquals(tuple.getRed(), tuple.getRedCopy()); | ||
assertNotSame(tuple.getRed(), tuple.getRedCopy()); | ||
} | ||
|
||
record GenericRecord<T>(T t) {} | ||
|
||
record GenericRecordContainer(GenericRecord<?> bgr) {} | ||
} |
2 changes: 1 addition & 1 deletion
2
...tage/RecordObjectAccessorCopyingTest.java → ...tion/RecordObjectAccessorCopyingTest.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
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
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
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
87 changes: 87 additions & 0 deletions
87
...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,87 @@ | ||
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.Objects; | ||
import nl.jqno.equalsverifier.internal.reflection.Tuple; | ||
import nl.jqno.equalsverifier.internal.reflection.TypeTag; | ||
import nl.jqno.equalsverifier.internal.reflection.instantiation.CachedValueProvider; | ||
import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; | ||
import nl.jqno.equalsverifier.internal.reflection.vintage.prefabvalues.factories.FallbackFactory; | ||
import nl.jqno.equalsverifier.internal.testhelpers.TestValueProviders; | ||
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 Attributes attributes; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
Objenesis objenesis = new ObjenesisStd(); | ||
factory = new FallbackFactory<>(objenesis); | ||
CachedValueProvider cache = new CachedValueProvider(); | ||
FactoryCache factoryCache = new FactoryCache(); | ||
factoryCache.put(int.class, values(42, 1337, 42)); | ||
valueProvider = | ||
new VintageValueProvider(TestValueProviders.empty(), cache, factoryCache, objenesis); | ||
attributes = Attributes.unlabeled(); | ||
} | ||
|
||
@Test | ||
public void redCopyHasTheSameValuesAsRed_whenSutIsAbstractSealedAndPermittedTypeAddsField() { | ||
Tuple<?> tuple = factory.createValues( | ||
new TypeTag(SealedParentWithFinalChild.class), | ||
valueProvider, | ||
attributes | ||
); | ||
|
||
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); | ||
} | ||
} | ||
} |
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
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
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
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
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
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
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
Oops, something went wrong.