Skip to content

Commit b70c1eb

Browse files
committed
Merge pull request #72 from j1ee/master
fixing bug whereby for an added element or removed element, the method w...
2 parents 19ace48 + 50aa915 commit b70c1eb

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/main/java/de/danielbechler/diff/Instances.java

+6
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,12 @@ public boolean areEqual()
175175

176176
public boolean areMethodResultsEqual(String method) {
177177
try {
178+
if(base == null && working == null){
179+
return true;
180+
}
181+
if(base == null && working != null || base != null && working == null){
182+
return false;
183+
}
178184
Object baseMethodResult = base.getClass().getMethod(method).invoke(base);
179185
Object workingMethodResult = working.getClass().getMethod(method).invoke(working);
180186
if(baseMethodResult == null){

src/test/java/de/danielbechler/diff/InstancesTest.java

+13
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,19 @@ public void testMethodResultEqualIsEqual() throws Exception
148148
assertThat(instances.areMethodResultsEqual("getValue")).isTrue();
149149
}
150150

151+
@Test
152+
public void testMethodResultEqualOneNull() throws Exception
153+
{
154+
final Method readMethod = getClass().getDeclaredMethod("getTestValue");
155+
final PropertyAccessor accessor = new PropertyAccessor("testValue", readMethod, null);
156+
157+
ObjectWithString working = new ObjectWithString("string");
158+
ObjectWithString base = null;
159+
160+
final Instances instances = new Instances(accessor, working, base, null);
161+
assertThat(instances.areMethodResultsEqual("getValue")).isFalse();
162+
}
163+
151164
@Test
152165
public void testMethodResultEqualInvalidMethod() throws Exception
153166
{

0 commit comments

Comments
 (0)