LANG-1485 : Add getters for lhs and rhs objects in DiffResult (#451)

* LANG-1485 : Add getters for lhs and rhs objects in DiffResult

* add @since and rename getters to getLeft and getRight

* fix typo on @since tag
This commit is contained in:
Nicolas 2019-09-05 19:20:04 +02:00 committed by Gary Gregory
parent 3c44319a17
commit 9feaf9d7ff
2 changed files with 32 additions and 0 deletions

View File

@ -88,6 +88,26 @@ public class DiffResult implements Iterable<Diff<?>> {
} }
} }
/**
* <p>Returns the object the right object has been compared to.</p>
*
* @return the left object of the diff
* @since 3.10
*/
public Object getLeft() {
return this.lhs;
}
/**
* <p>Returns the object the left object has been compared to.</p>
*
* @return the right object of the diff
* @since 3.10
*/
public Object getRight() {
return this.rhs;
}
/** /**
* <p> * <p>
* Returns an unmodifiable list of {@code Diff}s. The list may be empty if * Returns an unmodifiable list of {@code Diff}s. The list may be empty if

View File

@ -146,4 +146,16 @@ public void testNoDifferencesString() {
SHORT_STYLE).build(); SHORT_STYLE).build();
assertEquals(DiffResult.OBJECTS_SAME_STRING, diffResult.toString()); assertEquals(DiffResult.OBJECTS_SAME_STRING, diffResult.toString());
} }
@Test
public void testLeftAndRightGetters() {
final SimpleClass left = new SimpleClass(true);
final SimpleClass right = new SimpleClass(false);
final List<Diff<?>> diffs = left.diff(right).getDiffs();
final DiffResult diffResult = new DiffResult(left, right, diffs, SHORT_STYLE);
assertEquals(left, diffResult.getLeft());
assertEquals(right, diffResult.getRight());
}
} }