-
-
Notifications
You must be signed in to change notification settings - Fork 359
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
Allow abstract methods to be used in JaversGetter #549
Changes from all commits
cbe4bf1
1847044
a1bb1fc
088ce63
c11e9af
d1bac47
4b3230b
de4e44a
723b284
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package org.javers.core.cases | ||
|
||
import groovy.transform.PackageScope | ||
import org.javers.core.JaversBuilder | ||
import org.javers.core.MappingStyle | ||
import org.javers.core.metamodel.annotation.Id | ||
import org.javers.core.metamodel.type.EntityType | ||
import spock.lang.Specification | ||
import spock.lang.Unroll | ||
|
||
class AutoValueCase extends Specification { | ||
|
||
abstract class AbstractEntity { | ||
@Id | ||
abstract int getId() | ||
|
||
abstract int getValue() | ||
} | ||
|
||
@PackageScope | ||
final class ConcreteEntity extends AbstractEntity { | ||
private final int id | ||
private final int value | ||
|
||
ConcreteEntity(final int id, final int value) { | ||
this.id = id | ||
this.value = value | ||
} | ||
|
||
@Override | ||
int getId() { | ||
id | ||
} | ||
|
||
@Override | ||
int getValue() { | ||
value | ||
} | ||
} | ||
|
||
@Unroll | ||
def "#label should support abstract idGetter"() { | ||
given: | ||
def a = new ConcreteEntity(1, 1) | ||
def b = new ConcreteEntity(1, 2) | ||
def diff = javers.compare(a, b) | ||
def first = javers.commit('Alice', a) | ||
def second = javers.commit('Bob', b) | ||
|
||
expect: | ||
diff.changes.size() == 1 | ||
diff.changes[0].propertyName == 'value' | ||
diff.changes[0].left == 1 | ||
diff.changes[0].right == 2 | ||
|
||
first.author == 'Alice' | ||
second.author == 'Bob' | ||
second.changes.size() == 1 | ||
second.changes[0].propertyName == 'value' | ||
second.changes[0].left == 1 | ||
second.changes[0].right == 2 | ||
second.snapshots[0].managedType.managedClass.looksLikeId.size() == looksLikeId | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm sure there is a better way to test this? |
||
|
||
where: | ||
label << ['basic javers', 'javers with bean mapping', 'javers with bean mapping and entity registered'] | ||
javers << [ | ||
JaversBuilder.javers().build(), | ||
JaversBuilder.javers().withMappingStyle(MappingStyle.BEAN).build(), | ||
JaversBuilder.javers().withMappingStyle(MappingStyle.BEAN).registerEntity(AbstractEntity.class).build() | ||
] | ||
looksLikeId << [0, 1, 1] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The basic javers case could be removed, it's just here for illustration of why this whole change is necessary. If you annotate line 21 with |
||
} | ||
|
||
@Unroll | ||
def "should map #entity.simpleName with abstract @IdGetter as EntityType"(){ | ||
given: | ||
def javers = JaversBuilder.javers().withMappingStyle(MappingStyle.BEAN).build() | ||
|
||
expect: | ||
javers.getTypeMapping(entity) instanceof EntityType | ||
|
||
where: | ||
entity << [AbstractEntity, ConcreteEntity] | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for taking care about return type covariance