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

Primitives gets wrong status #164

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@

package de.danielbechler.diff

import de.danielbechler.diff.comparison.PrimitiveDefaultValueMode;
import de.danielbechler.diff.mock.*
import de.danielbechler.diff.node.DiffNode
import de.danielbechler.diff.node.DiffNode.State
import de.danielbechler.diff.node.Visit
import de.danielbechler.diff.node.DiffNode.Visitor
import de.danielbechler.diff.path.NodePath
import de.danielbechler.diff.selector.CollectionItemElementSelector
import de.danielbechler.diff.selector.MapKeyElementSelector
Expand Down Expand Up @@ -362,4 +366,33 @@ public class ObjectDifferIT extends Specification {
node.changed
node.getChild('map').changed
}

def "node should resolve State.REMOVED instead of State.ADDED"() {
given:
def differ = ObjectDifferBuilder.startBuilding().build()
def working = new ObjectWithCollectionOfComplexTypes()
def base = new ObjectWithCollectionOfComplexTypes()
def o = new ObjectWithPrimitivePropertyAndHashCodeAndEquals()
def visitor = new Visitor(){
def List<DiffNode> nodes = new ArrayList<>();
public void node(DiffNode node, Visit visit) {
if(node.hasChanges()){
nodes.add(node);
}
}
}
base.getList().add(o)
when:
def node = differ.compare(working,base)
node.visit(visitor)
def list = visitor.getNodes();
then:
node.hasChanges()
!list.empty
list.size() == 4
list[0].state == State.CHANGED
list[1].state == State.CHANGED
list[2].state == State.REMOVED
list[3].state == State.REMOVED
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package de.danielbechler.diff.mock;

import java.util.ArrayList;
import java.util.List;

public class ObjectWithCollectionOfComplexTypes {

private List<ObjectWithPrimitivePropertyAndHashCodeAndEquals> list = new ArrayList<ObjectWithPrimitivePropertyAndHashCodeAndEquals>();

public List<ObjectWithPrimitivePropertyAndHashCodeAndEquals> getList() {
return list;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package de.danielbechler.diff.mock;

public class ObjectWithPrimitivePropertyAndHashCodeAndEquals {

private int primitive;

public int getPrimitive() {
return primitive;
}

public void setPrimitive(int primitive) {
this.primitive = primitive;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + primitive;
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ObjectWithPrimitivePropertyAndHashCodeAndEquals other = (ObjectWithPrimitivePropertyAndHashCodeAndEquals) obj;
if (primitive != other.primitive)
return false;
return true;
}


}