Skip to content

Instantly share code, notes, and snippets.

Last active February 25, 2019 21:46
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Demonstrates issue with comparing objects with set properties whose elements are > 1 level deep value objects
import groovy.transform.TupleConstructor
import org.javers.core.JaversBuilder
import org.javers.core.diff.changetype.container.SetChange
import org.javers.core.diff.changetype.container.ValueAdded
import org.javers.core.metamodel.annotation.Id
import spock.lang.Specification
import static java.util.UUID.randomUUID
class SetPropertySpec extends Specification {
def javers = JaversBuilder
def "can detect new element added to set property"() {
def a = new Firewall(
new IngressRule("bar", new Port(80)),
new IngressRule("baz", new Port(80))
def b = new Firewall(,,
a.ingressRules + new IngressRule("bar", new Port(443))
def diff =, b)
diff.changes.any { change ->
change instanceof SetChange && change.changes.any { elementChange ->
elementChange instanceof ValueAdded
class Firewall {
@Id final UUID id
final String name
final Set<IngressRule> ingressRules
class IngressRule {
final String name
final Port port
class Port {
final int number
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment