Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrites instantiation #999

Merged
merged 74 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
80374c5
Introduces new instantiation interfaces
jqno Mar 8, 2024
876d6d4
Introduces SubjectCreator in several FieldChecks
jqno Mar 8, 2024
732ba8b
Introduces SubjectCreator in several FieldChecks
jqno Mar 8, 2024
2072248
Introduces SubjectCreator in several FieldChecks
jqno Mar 9, 2024
de369be
Introduces SubjectCreator in more FieldChecks
jqno Mar 13, 2024
a1e4205
Introduces SubjectCreator in last FieldChecks, refactors FieldCheck i…
jqno Mar 13, 2024
fe96162
Introduces InstanceCreator in several FieldChecks and Checkers
jqno Aug 30, 2024
8839661
Refactors SubjectCreator into Configuration
jqno Aug 30, 2024
8d41696
Introduces SubjectCreator in several Checkers
jqno Aug 30, 2024
3b8462c
Introduces ClassProbe
jqno Aug 30, 2024
dbf8bd8
Introduces InstanceCreator in several FieldChecks and Checkers
jqno Aug 30, 2024
01bf705
Adds ArchUnit test to enforce non-usage of vintage instantiation methods
jqno Aug 31, 2024
7402fe9
Makes SubjectCreator an interface
jqno Aug 31, 2024
df86c85
Introduces an incomplete ModernSubjectCreator
jqno Aug 31, 2024
1cc7790
Partially implements ModernSubjectCreator
jqno Sep 6, 2024
66f3f80
Separates Context out from Configuration
jqno Sep 6, 2024
2090d65
Removes Configuration from SubjectCreator method signature
jqno Sep 6, 2024
37b26c1
Lets ModernSubjectCreator check nullability
jqno Sep 6, 2024
acb235f
Fixes remaining non-record issues with ModernSubjectCreator
jqno Sep 6, 2024
9021ec2
Partially implements records in ModernSubjectCreator
jqno Sep 6, 2024
ac63686
Accounts for primitive values in records
jqno Sep 6, 2024
bd66a10
Tidies up RecordObjectAccessor
jqno Sep 6, 2024
f822584
Makes a field final
jqno Sep 9, 2024
7504f6d
Adds tests and javadoc for ClassProbe and FieldProbe
jqno Sep 11, 2024
a046ce4
Folds NonnullAnnotationVerifier into FieldProbe
jqno Sep 11, 2024
4382c19
Cleans up ClassAccessor
jqno Sep 11, 2024
b0c34ae
Removes PrefabValues from HierarchyChecker
jqno Sep 11, 2024
a0f2abf
Removes PrefabValues and ClassAccessor from Configuration
jqno Sep 11, 2024
86d173e
Uses SubjectCreator for unequal examples
jqno Sep 12, 2024
f0fc5bc
Removes FieldAccessor from checkers
jqno Sep 12, 2024
5f24804
Cleans up ModernSubjectCreator
jqno Sep 13, 2024
65f50bf
Adds copy() and copyIntoSuperclass() methods to SubjectCreator
jqno Sep 13, 2024
e9901eb
Renames InstanceCreator to ValueProvider
jqno Sep 13, 2024
61304f6
Adds copyIntoSubclass() method to SubjectCreator
jqno Sep 13, 2024
52722be
Replaces call to copyIntoAnonymousSubclass() with call to SubjectCrea…
jqno Sep 13, 2024
7fea41c
Replaces last calls to ObjectAccessor with FieldProbes
jqno Sep 13, 2024
be4c600
Simplifies InstanceCreator
jqno Sep 13, 2024
5791fd0
Removes Configuration from FieldProbe constructor and puts it in the …
jqno Sep 13, 2024
3656541
Replaces ObjectAccessor with new FieldMutator in InstanceCreator
jqno Sep 13, 2024
9a83734
Replaces FieldModifier with FieldMutator
jqno Sep 14, 2024
5a3ee1f
Introduces vintage package for old-style reflection code
jqno Sep 14, 2024
011e1b4
Moves instantiation package into reflection package
jqno Sep 14, 2024
a4b4cf0
Picks a different file to check in the jar verifier
jqno Sep 16, 2024
6efc37f
Moves PrefabValues class to vintage package
jqno Sep 16, 2024
e7fc34e
Restricts access to vintage reflection classes
jqno Sep 16, 2024
8c5fbcb
Removes FieldAccessor
jqno Sep 16, 2024
1c7847a
Removes unused code
jqno Sep 16, 2024
8b09485
Uses FieldProbe in more places
jqno Sep 16, 2024
eba0904
Moves PrefabValues classes to vintage package
jqno Sep 16, 2024
67142f8
Folds PrefabValues class into VintageValueProvider
jqno Sep 16, 2024
3f9a541
Restores coverage threshold
jqno Sep 16, 2024
256f77f
Adds fieldCache to SubjectCreator
jqno Sep 16, 2024
6b76d72
Replaces Cache class with HashMap
jqno Sep 17, 2024
27b9b43
Moves FactoryCacheTest to correct package
jqno Sep 17, 2024
cf8d151
Introduces proper FieldCache
jqno Sep 17, 2024
531324d
Uses SubjectCreator where ValueProvider was inappropriate; fixes exce…
jqno Sep 17, 2024
edce7d3
Adds #withPrefabValuesForField
jqno Sep 17, 2024
d724033
Automatically suppresses Warning.ZERO_FIELDS when using #withPrefabVa…
jqno Sep 17, 2024
2f11153
Refines #withPrefabValuesForField
jqno Sep 19, 2024
f515c7c
Don't automatically suppresses Warning.ZERO_FIELDS when using #withPr…
jqno Sep 19, 2024
bba1817
Deprecates Warning.ZERO_FIELDS
jqno Sep 19, 2024
bd4eadd
Adds Javadoc
jqno Sep 19, 2024
2ce2a56
Adds tests for FieldMutator
jqno Sep 19, 2024
acbc52e
Adds tests for InstanceCreator
jqno Sep 19, 2024
ca286c6
Adds tests for SubjectCreator
jqno Sep 19, 2024
e4ae447
Mentions withPrefabValuesForField, ZERO_FIELDS deprecation, and inter…
jqno Sep 19, 2024
adee6ea
Enables verbose logging for PITest troubleshooting
jqno Sep 20, 2024
f02dd32
Moves dependencies to main pom for the benefit of PITest
jqno Sep 20, 2024
673c82f
Disables verbose logging for PITest troubleshooting
jqno Sep 20, 2024
d526128
Makes improvements suggested by PITest
jqno Sep 21, 2024
0ff8a8e
Adds tests for FieldProbe
jqno Sep 22, 2024
60cb1e6
Removes NonnullAnnotationVerifier
jqno Sep 22, 2024
000d5fb
Makes Objenesis dependency explicit
jqno Sep 23, 2024
2efc52a
Makes more improvements suggested by PITest
jqno Sep 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- #withPrefabValuesForField method, where you can assign prefab values to a field instead of to a class. The values will then be used for that field only. ([Issue 747](https://github.com/jqno/equalsverifier/issues/747))

### Changed

- The internal instantiation logic has been heavily refactored.

### Deprecated

- `Warning.ZERO_FIELDS`: the use case for this Warning is better handled by the new `#withPrefabValuesForField` method.

## [3.16.2] - 2024-08-23

### Changed
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package nl.jqno.equalsverifier.integration.extended_contract;

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

public class PrefabValuesForFieldInRecordTest {

@Test
public void fail_whenRecordHasSinglePrecondition() {
ExpectedException
.when(() -> EqualsVerifier.forClass(SinglePrecondition.class).verify())
.assertFailure()
.assertMessageContains("Record:", "failed to run constructor", "[1]");
}

@Test
public void succeed_whenRecordHasSinglePrecondition_givenPrefabValuesForField() {
EqualsVerifier
.forClass(SinglePrecondition.class)
.withPrefabValuesForField("i", 111, 142)
.verify();
}

@Test
public void fail_whenRecordHasDualPrecondition() {
ExpectedException
.when(() -> EqualsVerifier.forClass(DualPrecondition.class).verify())
.assertFailure()
.assertMessageContains("Record:", "failed to run constructor", "[1, 1]");
}

@Test
public void fail_whenRecordHasDualPrecondition_givenPrefabValuesForOnlyOneField() {
ExpectedException
.when(() ->
EqualsVerifier
.forClass(DualPrecondition.class)
.withPrefabValuesForField("x", 111, 142)
.verify()
)
.assertFailure()
.assertMessageContains("Record:", "failed to run constructor", "[111, 1]");
}

@Test
public void succeed_whenRecordHasDualPrecondition_givenPrefabValueForBothFields() {
EqualsVerifier
.forClass(DualPrecondition.class)
.withPrefabValuesForField("x", 111, 142)
.withPrefabValuesForField("y", 505, 555)
.verify();
}

record SinglePrecondition(int i) {
public SinglePrecondition {
if (i < 100 || i > 200) {
throw new IllegalArgumentException("i must be between 100 and 200! But was " + i);
}
}
}

record DualPrecondition(int x, int y) {
public DualPrecondition {
if (x < 100 || x > 200) {
throw new IllegalArgumentException("x must be between 100 and 200! But was " + x);
}
if (y < 500 || y > 600) {
throw new IllegalArgumentException("y must be between 500 and 600! But was " + y);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,6 @@ public void fail_whenConstructorChecksValue() {
.assertMessageContains("Record:", "failed to run constructor", "prefab values");
}

@Test
public void succeed_whenConstructorChecksValue_givenPrefabValues() {
EqualsVerifier
.forClass(ValueCheckingRecord.class)
.withPrefabValues(int.class, 10, 11)
.suppress(Warning.ZERO_FIELDS)
.verify();
}

@Test
public void fail_whenRecordInvariantIsViolated_givenIntFieldIsModifiedInConstructor() {
ExpectedException
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package nl.jqno.equalsverifier.internal.reflection;

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

import org.junit.jupiter.api.Test;

public class ClassProbeRecordTest {

@Test
public void isRecord() {
var probe = new ClassProbe<>(SimpleRecord.class);
assertTrue(probe.isRecord());
}

record SimpleRecord(int i) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.Test;
import org.objenesis.ObjenesisStd;

public class RecordInstantiatorTest {

@Test
public void instantiateRecord() {
Instantiator<?> instantiator = Instantiator.of(SimpleRecord.class);
Instantiator<?> instantiator = Instantiator.of(SimpleRecord.class, new ObjenesisStd());
Object simpleRecord = instantiator.instantiate();
assertEquals(SimpleRecord.class, simpleRecord.getClass());
}
Expand Down

This file was deleted.

This file was deleted.

Loading
Loading