Renamed DiffList to DiffResult as per discussion in LANG-637.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1561225 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ea47f03c4d
commit
8a82d7b79b
|
@ -30,7 +30,7 @@ import org.apache.commons.lang3.tuple.Pair;
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* Typically, {@code Diff}s are retrieved by using a {@link DiffBuilder} to
|
* Typically, {@code Diff}s are retrieved by using a {@link DiffBuilder} to
|
||||||
* produce a {@link DiffList}, containing the differences between two objects.
|
* produce a {@link DiffResult}, containing the differences between two objects.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
|
|
@ -39,7 +39,7 @@ import org.apache.commons.lang3.ArrayUtils;
|
||||||
*
|
*
|
||||||
* ...
|
* ...
|
||||||
*
|
*
|
||||||
* public DiffList diff(Person obj) {
|
* public DiffResult diff(Person obj) {
|
||||||
* // No need for null check, as NullPointerException correct if obj is null
|
* // No need for null check, as NullPointerException correct if obj is null
|
||||||
* return new DiffBuilder(this, obj, ToStringStyle.SHORT_PREFIX_STYLE)
|
* return new DiffBuilder(this, obj, ToStringStyle.SHORT_PREFIX_STYLE)
|
||||||
* .append("name", this.name, obj.name)
|
* .append("name", this.name, obj.name)
|
||||||
|
@ -52,19 +52,19 @@ import org.apache.commons.lang3.ArrayUtils;
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* The {@code ToStringStyle} passed to the constructor is embedded in the
|
* The {@code ToStringStyle} passed to the constructor is embedded in the
|
||||||
* returned {@code DiffList} and influences the style of the
|
* returned {@code DiffResult} and influences the style of the
|
||||||
* {@code DiffList.toString()} method. This style choice can be overridden by
|
* {@code DiffResult.toString()} method. This style choice can be overridden by
|
||||||
* calling {@link DiffList#toString(ToStringStyle)}.
|
* calling {@link DiffResult#toString(ToStringStyle)}.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @since 3.3
|
* @since 3.3
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
* @see Diffable
|
* @see Diffable
|
||||||
* @see Diff
|
* @see Diff
|
||||||
* @see DiffList
|
* @see DiffResult
|
||||||
* @see ToStringStyle
|
* @see ToStringStyle
|
||||||
*/
|
*/
|
||||||
public class DiffBuilder implements Builder<DiffList> {
|
public class DiffBuilder implements Builder<DiffResult> {
|
||||||
|
|
||||||
private final List<Diff<?>> diffs;
|
private final List<Diff<?>> diffs;
|
||||||
private final boolean objectsTriviallyEqual;
|
private final boolean objectsTriviallyEqual;
|
||||||
|
@ -80,7 +80,7 @@ public class DiffBuilder implements Builder<DiffList> {
|
||||||
* <p>
|
* <p>
|
||||||
* If {@code lhs == rhs} or {@code lhs.equals(rhs)} then the builder will
|
* If {@code lhs == rhs} or {@code lhs.equals(rhs)} then the builder will
|
||||||
* not evaluate any calls to {@code append(...)} and will return an empty
|
* not evaluate any calls to {@code append(...)} and will return an empty
|
||||||
* {@link DiffList} when {@link #build()} is executed.
|
* {@link DiffResult} when {@link #build()} is executed.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param lhs
|
* @param lhs
|
||||||
|
@ -899,16 +899,16 @@ public class DiffBuilder implements Builder<DiffList> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* Builds a {@link DiffList} based on the differences appended to this
|
* Builds a {@link DiffResult} based on the differences appended to this
|
||||||
* builder.
|
* builder.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @return a {@code DiffList} containing the differences between the two
|
* @return a {@code DiffResult} containing the differences between the two
|
||||||
* objects.
|
* objects.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public DiffList build() {
|
public DiffResult build() {
|
||||||
return new DiffList(lhs, rhs, diffs, style);
|
return new DiffResult(lhs, rhs, diffs, style);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,19 +22,19 @@ import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* A {@code DiffList} contains a list of the differences between two
|
* A {@code DiffResult} contains a collection of the differences between two
|
||||||
* {@link Diffable} objects. Typically these differences are displayed using
|
* {@link Diffable} objects. Typically these differences are displayed using
|
||||||
* {@link #toString()} method, which returns a string describing the fields that
|
* {@link #toString()} method, which returns a string describing the fields that
|
||||||
* differ between the objects.
|
* differ between the objects.
|
||||||
* </p>
|
* </p>
|
||||||
* <p>
|
* <p>
|
||||||
* Use a {@link DiffBuilder} to build a {@code DiffList} comparing two objects.
|
* Use a {@link DiffBuilder} to build a {@code DiffResult} comparing two objects.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @since 3.3
|
* @since 3.3
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public class DiffList implements Iterable<Diff<?>> {
|
public class DiffResult implements Iterable<Diff<?>> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -53,7 +53,7 @@ public class DiffList implements Iterable<Diff<?>> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* Creates a {@link DiffList} containing the differences between two
|
* Creates a {@link DiffResult} containing the differences between two
|
||||||
* objects.
|
* objects.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
|
@ -70,7 +70,7 @@ public class DiffList implements Iterable<Diff<?>> {
|
||||||
* @throws IllegalArgumentException
|
* @throws IllegalArgumentException
|
||||||
* if {@code lhs}, {@code rhs} or {@code diffs} is {@code null}
|
* if {@code lhs}, {@code rhs} or {@code diffs} is {@code null}
|
||||||
*/
|
*/
|
||||||
DiffList(final Object lhs, final Object rhs, final List<Diff<?>> diffs,
|
DiffResult(final Object lhs, final Object rhs, final List<Diff<?>> diffs,
|
||||||
final ToStringStyle style) {
|
final ToStringStyle style) {
|
||||||
if (lhs == null) {
|
if (lhs == null) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
|
@ -133,7 +133,7 @@ public class DiffList implements Iterable<Diff<?>> {
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* Builds a {@code String} description of the differences contained within
|
* Builds a {@code String} description of the differences contained within
|
||||||
* this {@code DiffList}. A {@link ToStringBuilder} is used for each object
|
* this {@code DiffResult}. A {@link ToStringBuilder} is used for each object
|
||||||
* and the style of the output is governed by the {@code ToStringStyle}
|
* and the style of the output is governed by the {@code ToStringStyle}
|
||||||
* passed to the constructor.
|
* passed to the constructor.
|
||||||
* </p>
|
* </p>
|
||||||
|
@ -169,7 +169,7 @@ public class DiffList implements Iterable<Diff<?>> {
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* Builds a {@code String} description of the differences contained within
|
* Builds a {@code String} description of the differences contained within
|
||||||
* this {@code DiffList}, using the supplied {@code ToStringStyle}.
|
* this {@code DiffResult}, using the supplied {@code ToStringStyle}.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param style
|
* @param style
|
|
@ -18,8 +18,8 @@ package org.apache.commons.lang3.builder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>{@code Diffable} classes can be compared with other objects
|
* <p>{@code Diffable} classes can be compared with other objects
|
||||||
* for differences. The {@link DiffList} object retrieved can be queried
|
* for differences. The {@link DiffResult} object retrieved can be queried
|
||||||
* for a list of differences or printed using the {@link DiffList#toString()}.</p>
|
* for a list of differences or printed using the {@link DiffResult#toString()}.</p>
|
||||||
*
|
*
|
||||||
* <p>The calculation of the differences is <i>consistent with equals</i> if
|
* <p>The calculation of the differences is <i>consistent with equals</i> if
|
||||||
* and only if {@code d1.equals(d2)} implies {@code d1.diff(d2) == ""}.
|
* and only if {@code d1.equals(d2)} implies {@code d1.diff(d2) == ""}.
|
||||||
|
@ -50,5 +50,5 @@ public interface Diffable<T> {
|
||||||
* @return a list of differences
|
* @return a list of differences
|
||||||
* @throws NullPointerException if the specified object is {@code null}
|
* @throws NullPointerException if the specified object is {@code null}
|
||||||
*/
|
*/
|
||||||
DiffList diff(T obj);
|
DiffResult diff(T obj);
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ public class DiffBuilderTest {
|
||||||
private Object[] objectArrayField = {null};
|
private Object[] objectArrayField = {null};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DiffList diff(TypeTestClass obj) {
|
public DiffResult diff(TypeTestClass obj) {
|
||||||
return new DiffBuilder(this, obj, style)
|
return new DiffBuilder(this, obj, style)
|
||||||
.append("boolean", booleanField, obj.booleanField)
|
.append("boolean", booleanField, obj.booleanField)
|
||||||
.append("booleanArray", booleanArrayField, obj.booleanArrayField)
|
.append("booleanArray", booleanArrayField, obj.booleanArrayField)
|
||||||
|
@ -94,7 +94,7 @@ public class DiffBuilderTest {
|
||||||
TypeTestClass class1 = new TypeTestClass();
|
TypeTestClass class1 = new TypeTestClass();
|
||||||
TypeTestClass class2 = new TypeTestClass();
|
TypeTestClass class2 = new TypeTestClass();
|
||||||
class2.booleanField = false;
|
class2.booleanField = false;
|
||||||
DiffList list = class1.diff(class2);
|
DiffResult list = class1.diff(class2);
|
||||||
assertEquals(1, list.getNumberOfDiffs());
|
assertEquals(1, list.getNumberOfDiffs());
|
||||||
Diff<?> diff = list.getDiffs().get(0);
|
Diff<?> diff = list.getDiffs().get(0);
|
||||||
assertEquals(Boolean.class, diff.getType());
|
assertEquals(Boolean.class, diff.getType());
|
||||||
|
@ -107,7 +107,7 @@ public class DiffBuilderTest {
|
||||||
TypeTestClass class1 = new TypeTestClass();
|
TypeTestClass class1 = new TypeTestClass();
|
||||||
TypeTestClass class2 = new TypeTestClass();
|
TypeTestClass class2 = new TypeTestClass();
|
||||||
class2.booleanArrayField = new boolean[] {false, false};
|
class2.booleanArrayField = new boolean[] {false, false};
|
||||||
DiffList list = class1.diff(class2);
|
DiffResult list = class1.diff(class2);
|
||||||
assertEquals(1, list.getNumberOfDiffs());
|
assertEquals(1, list.getNumberOfDiffs());
|
||||||
Diff<?> diff = list.getDiffs().get(0);
|
Diff<?> diff = list.getDiffs().get(0);
|
||||||
assertArrayEquals(ArrayUtils.toObject(class1.booleanArrayField),
|
assertArrayEquals(ArrayUtils.toObject(class1.booleanArrayField),
|
||||||
|
@ -122,7 +122,7 @@ public class DiffBuilderTest {
|
||||||
TypeTestClass class1 = new TypeTestClass();
|
TypeTestClass class1 = new TypeTestClass();
|
||||||
TypeTestClass class2 = new TypeTestClass();
|
TypeTestClass class2 = new TypeTestClass();
|
||||||
class2.byteField = 0x01;
|
class2.byteField = 0x01;
|
||||||
DiffList list = class1.diff(class2);
|
DiffResult list = class1.diff(class2);
|
||||||
assertEquals(1, list.getNumberOfDiffs());
|
assertEquals(1, list.getNumberOfDiffs());
|
||||||
Diff<?> diff = list.getDiffs().get(0);
|
Diff<?> diff = list.getDiffs().get(0);
|
||||||
assertEquals(Byte.valueOf(class1.byteField), diff.getLeft());
|
assertEquals(Byte.valueOf(class1.byteField), diff.getLeft());
|
||||||
|
@ -134,7 +134,7 @@ public class DiffBuilderTest {
|
||||||
TypeTestClass class1 = new TypeTestClass();
|
TypeTestClass class1 = new TypeTestClass();
|
||||||
TypeTestClass class2 = new TypeTestClass();
|
TypeTestClass class2 = new TypeTestClass();
|
||||||
class2.byteArrayField= new byte[] {0x01, 0x02};
|
class2.byteArrayField= new byte[] {0x01, 0x02};
|
||||||
DiffList list = class1.diff(class2);
|
DiffResult list = class1.diff(class2);
|
||||||
assertEquals(1, list.getNumberOfDiffs());
|
assertEquals(1, list.getNumberOfDiffs());
|
||||||
Diff<?> diff = list.getDiffs().get(0);
|
Diff<?> diff = list.getDiffs().get(0);
|
||||||
assertArrayEquals(ArrayUtils.toObject(class1.byteArrayField),
|
assertArrayEquals(ArrayUtils.toObject(class1.byteArrayField),
|
||||||
|
@ -148,7 +148,7 @@ public class DiffBuilderTest {
|
||||||
TypeTestClass class1 = new TypeTestClass();
|
TypeTestClass class1 = new TypeTestClass();
|
||||||
TypeTestClass class2 = new TypeTestClass();
|
TypeTestClass class2 = new TypeTestClass();
|
||||||
class2.charField = 'z';
|
class2.charField = 'z';
|
||||||
DiffList list = class1.diff(class2);
|
DiffResult list = class1.diff(class2);
|
||||||
assertEquals(1, list.getNumberOfDiffs());
|
assertEquals(1, list.getNumberOfDiffs());
|
||||||
Diff<?> diff = list.getDiffs().get(0);
|
Diff<?> diff = list.getDiffs().get(0);
|
||||||
assertEquals(Character.valueOf(class1.charField), diff.getLeft());
|
assertEquals(Character.valueOf(class1.charField), diff.getLeft());
|
||||||
|
@ -161,7 +161,7 @@ public class DiffBuilderTest {
|
||||||
TypeTestClass class1 = new TypeTestClass();
|
TypeTestClass class1 = new TypeTestClass();
|
||||||
TypeTestClass class2 = new TypeTestClass();
|
TypeTestClass class2 = new TypeTestClass();
|
||||||
class2.charArrayField = new char[] {'f', 'o', 'o'};
|
class2.charArrayField = new char[] {'f', 'o', 'o'};
|
||||||
DiffList list = class1.diff(class2);
|
DiffResult list = class1.diff(class2);
|
||||||
assertEquals(1, list.getNumberOfDiffs());
|
assertEquals(1, list.getNumberOfDiffs());
|
||||||
Diff<?> diff = list.getDiffs().get(0);
|
Diff<?> diff = list.getDiffs().get(0);
|
||||||
assertArrayEquals(ArrayUtils.toObject(class1.charArrayField),
|
assertArrayEquals(ArrayUtils.toObject(class1.charArrayField),
|
||||||
|
@ -176,7 +176,7 @@ public class DiffBuilderTest {
|
||||||
TypeTestClass class1 = new TypeTestClass();
|
TypeTestClass class1 = new TypeTestClass();
|
||||||
TypeTestClass class2 = new TypeTestClass();
|
TypeTestClass class2 = new TypeTestClass();
|
||||||
class2.doubleField = 99.99;
|
class2.doubleField = 99.99;
|
||||||
DiffList list = class1.diff(class2);
|
DiffResult list = class1.diff(class2);
|
||||||
assertEquals(1, list.getNumberOfDiffs());
|
assertEquals(1, list.getNumberOfDiffs());
|
||||||
Diff<?> diff = list.getDiffs().get(0);
|
Diff<?> diff = list.getDiffs().get(0);
|
||||||
assertEquals(Double.valueOf(class1.doubleField), diff.getLeft());
|
assertEquals(Double.valueOf(class1.doubleField), diff.getLeft());
|
||||||
|
@ -189,7 +189,7 @@ public class DiffBuilderTest {
|
||||||
TypeTestClass class1 = new TypeTestClass();
|
TypeTestClass class1 = new TypeTestClass();
|
||||||
TypeTestClass class2 = new TypeTestClass();
|
TypeTestClass class2 = new TypeTestClass();
|
||||||
class2.doubleArrayField = new double[] {3.0, 2.9, 2.8};
|
class2.doubleArrayField = new double[] {3.0, 2.9, 2.8};
|
||||||
DiffList list = class1.diff(class2);
|
DiffResult list = class1.diff(class2);
|
||||||
assertEquals(1, list.getNumberOfDiffs());
|
assertEquals(1, list.getNumberOfDiffs());
|
||||||
Diff<?> diff = list.getDiffs().get(0);
|
Diff<?> diff = list.getDiffs().get(0);
|
||||||
assertArrayEquals(ArrayUtils.toObject(class1.doubleArrayField),
|
assertArrayEquals(ArrayUtils.toObject(class1.doubleArrayField),
|
||||||
|
@ -203,7 +203,7 @@ public class DiffBuilderTest {
|
||||||
TypeTestClass class1 = new TypeTestClass();
|
TypeTestClass class1 = new TypeTestClass();
|
||||||
TypeTestClass class2 = new TypeTestClass();
|
TypeTestClass class2 = new TypeTestClass();
|
||||||
class2.floatField = 99.99F;
|
class2.floatField = 99.99F;
|
||||||
DiffList list = class1.diff(class2);
|
DiffResult list = class1.diff(class2);
|
||||||
assertEquals(1, list.getNumberOfDiffs());
|
assertEquals(1, list.getNumberOfDiffs());
|
||||||
Diff<?> diff = list.getDiffs().get(0);
|
Diff<?> diff = list.getDiffs().get(0);
|
||||||
assertEquals(Float.valueOf(class1.floatField), diff.getLeft());
|
assertEquals(Float.valueOf(class1.floatField), diff.getLeft());
|
||||||
|
@ -216,7 +216,7 @@ public class DiffBuilderTest {
|
||||||
TypeTestClass class1 = new TypeTestClass();
|
TypeTestClass class1 = new TypeTestClass();
|
||||||
TypeTestClass class2 = new TypeTestClass();
|
TypeTestClass class2 = new TypeTestClass();
|
||||||
class2.floatArrayField = new float[] {3.0F, 2.9F, 2.8F};
|
class2.floatArrayField = new float[] {3.0F, 2.9F, 2.8F};
|
||||||
DiffList list = class1.diff(class2);
|
DiffResult list = class1.diff(class2);
|
||||||
assertEquals(1, list.getNumberOfDiffs());
|
assertEquals(1, list.getNumberOfDiffs());
|
||||||
Diff<?> diff = list.getDiffs().get(0);
|
Diff<?> diff = list.getDiffs().get(0);
|
||||||
assertArrayEquals(ArrayUtils.toObject(class1.floatArrayField),
|
assertArrayEquals(ArrayUtils.toObject(class1.floatArrayField),
|
||||||
|
@ -231,7 +231,7 @@ public class DiffBuilderTest {
|
||||||
TypeTestClass class1 = new TypeTestClass();
|
TypeTestClass class1 = new TypeTestClass();
|
||||||
TypeTestClass class2 = new TypeTestClass();
|
TypeTestClass class2 = new TypeTestClass();
|
||||||
class2.intField = 42;
|
class2.intField = 42;
|
||||||
DiffList list = class1.diff(class2);
|
DiffResult list = class1.diff(class2);
|
||||||
assertEquals(1, list.getNumberOfDiffs());
|
assertEquals(1, list.getNumberOfDiffs());
|
||||||
Diff<?> diff = list.getDiffs().get(0);
|
Diff<?> diff = list.getDiffs().get(0);
|
||||||
assertEquals(Integer.valueOf(class1.intField), diff.getLeft());
|
assertEquals(Integer.valueOf(class1.intField), diff.getLeft());
|
||||||
|
@ -244,7 +244,7 @@ public class DiffBuilderTest {
|
||||||
TypeTestClass class1 = new TypeTestClass();
|
TypeTestClass class1 = new TypeTestClass();
|
||||||
TypeTestClass class2 = new TypeTestClass();
|
TypeTestClass class2 = new TypeTestClass();
|
||||||
class2.intArrayField = new int[] {3, 2, 1};
|
class2.intArrayField = new int[] {3, 2, 1};
|
||||||
DiffList list = class1.diff(class2);
|
DiffResult list = class1.diff(class2);
|
||||||
assertEquals(1, list.getNumberOfDiffs());
|
assertEquals(1, list.getNumberOfDiffs());
|
||||||
Diff<?> diff = list.getDiffs().get(0);
|
Diff<?> diff = list.getDiffs().get(0);
|
||||||
assertArrayEquals(ArrayUtils.toObject(class1.intArrayField),
|
assertArrayEquals(ArrayUtils.toObject(class1.intArrayField),
|
||||||
|
@ -258,7 +258,7 @@ public class DiffBuilderTest {
|
||||||
TypeTestClass class1 = new TypeTestClass();
|
TypeTestClass class1 = new TypeTestClass();
|
||||||
TypeTestClass class2 = new TypeTestClass();
|
TypeTestClass class2 = new TypeTestClass();
|
||||||
class2.longField = 42L;
|
class2.longField = 42L;
|
||||||
DiffList list = class1.diff(class2);
|
DiffResult list = class1.diff(class2);
|
||||||
assertEquals(1, list.getNumberOfDiffs());
|
assertEquals(1, list.getNumberOfDiffs());
|
||||||
Diff<?> diff = list.getDiffs().get(0);
|
Diff<?> diff = list.getDiffs().get(0);
|
||||||
assertEquals(Long.valueOf(class1.longField), diff.getLeft());
|
assertEquals(Long.valueOf(class1.longField), diff.getLeft());
|
||||||
|
@ -271,7 +271,7 @@ public class DiffBuilderTest {
|
||||||
TypeTestClass class1 = new TypeTestClass();
|
TypeTestClass class1 = new TypeTestClass();
|
||||||
TypeTestClass class2 = new TypeTestClass();
|
TypeTestClass class2 = new TypeTestClass();
|
||||||
class2.longArrayField = new long[] {3L, 2L, 1L};
|
class2.longArrayField = new long[] {3L, 2L, 1L};
|
||||||
DiffList list = class1.diff(class2);
|
DiffResult list = class1.diff(class2);
|
||||||
assertEquals(1, list.getNumberOfDiffs());
|
assertEquals(1, list.getNumberOfDiffs());
|
||||||
Diff<?> diff = list.getDiffs().get(0);
|
Diff<?> diff = list.getDiffs().get(0);
|
||||||
assertArrayEquals(ArrayUtils.toObject(class1.longArrayField),
|
assertArrayEquals(ArrayUtils.toObject(class1.longArrayField),
|
||||||
|
@ -285,7 +285,7 @@ public class DiffBuilderTest {
|
||||||
TypeTestClass class1 = new TypeTestClass();
|
TypeTestClass class1 = new TypeTestClass();
|
||||||
TypeTestClass class2 = new TypeTestClass();
|
TypeTestClass class2 = new TypeTestClass();
|
||||||
class2.shortField = 42;
|
class2.shortField = 42;
|
||||||
DiffList list = class1.diff(class2);
|
DiffResult list = class1.diff(class2);
|
||||||
assertEquals(1, list.getNumberOfDiffs());
|
assertEquals(1, list.getNumberOfDiffs());
|
||||||
Diff<?> diff = list.getDiffs().get(0);
|
Diff<?> diff = list.getDiffs().get(0);
|
||||||
assertEquals(Short.valueOf(class1.shortField), diff.getLeft());
|
assertEquals(Short.valueOf(class1.shortField), diff.getLeft());
|
||||||
|
@ -298,7 +298,7 @@ public class DiffBuilderTest {
|
||||||
TypeTestClass class1 = new TypeTestClass();
|
TypeTestClass class1 = new TypeTestClass();
|
||||||
TypeTestClass class2 = new TypeTestClass();
|
TypeTestClass class2 = new TypeTestClass();
|
||||||
class2.shortArrayField = new short[] {3, 2, 1};
|
class2.shortArrayField = new short[] {3, 2, 1};
|
||||||
DiffList list = class1.diff(class2);
|
DiffResult list = class1.diff(class2);
|
||||||
assertEquals(1, list.getNumberOfDiffs());
|
assertEquals(1, list.getNumberOfDiffs());
|
||||||
Diff<?> diff = list.getDiffs().get(0);
|
Diff<?> diff = list.getDiffs().get(0);
|
||||||
assertArrayEquals(ArrayUtils.toObject(class1.shortArrayField),
|
assertArrayEquals(ArrayUtils.toObject(class1.shortArrayField),
|
||||||
|
@ -312,7 +312,7 @@ public class DiffBuilderTest {
|
||||||
TypeTestClass class1 = new TypeTestClass();
|
TypeTestClass class1 = new TypeTestClass();
|
||||||
TypeTestClass class2 = new TypeTestClass();
|
TypeTestClass class2 = new TypeTestClass();
|
||||||
class2.objectField = "Some string";
|
class2.objectField = "Some string";
|
||||||
DiffList list = class1.diff(class2);
|
DiffResult list = class1.diff(class2);
|
||||||
assertEquals(1, list.getNumberOfDiffs());
|
assertEquals(1, list.getNumberOfDiffs());
|
||||||
Diff<?> diff = list.getDiffs().get(0);
|
Diff<?> diff = list.getDiffs().get(0);
|
||||||
assertEquals(class1.objectField, diff.getLeft());
|
assertEquals(class1.objectField, diff.getLeft());
|
||||||
|
@ -325,7 +325,7 @@ public class DiffBuilderTest {
|
||||||
TypeTestClass class2 = new TypeTestClass();
|
TypeTestClass class2 = new TypeTestClass();
|
||||||
class1.objectField = "Some string";
|
class1.objectField = "Some string";
|
||||||
class2.objectField = "Some string";
|
class2.objectField = "Some string";
|
||||||
DiffList list = class1.diff(class2);
|
DiffResult list = class1.diff(class2);
|
||||||
assertEquals(0, list.getNumberOfDiffs());
|
assertEquals(0, list.getNumberOfDiffs());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -335,7 +335,7 @@ public class DiffBuilderTest {
|
||||||
TypeTestClass class1 = new TypeTestClass();
|
TypeTestClass class1 = new TypeTestClass();
|
||||||
TypeTestClass class2 = new TypeTestClass();
|
TypeTestClass class2 = new TypeTestClass();
|
||||||
class2.objectArrayField = new Object[] {"string", 1, 2};
|
class2.objectArrayField = new Object[] {"string", 1, 2};
|
||||||
DiffList list = class1.diff(class2);
|
DiffResult list = class1.diff(class2);
|
||||||
assertEquals(1, list.getNumberOfDiffs());
|
assertEquals(1, list.getNumberOfDiffs());
|
||||||
Diff<?> diff = list.getDiffs().get(0);
|
Diff<?> diff = list.getDiffs().get(0);
|
||||||
assertArrayEquals(class1.objectArrayField, (Object[]) diff.getLeft());
|
assertArrayEquals(class1.objectArrayField, (Object[]) diff.getLeft());
|
||||||
|
@ -348,14 +348,14 @@ public class DiffBuilderTest {
|
||||||
TypeTestClass class2 = new TypeTestClass();
|
TypeTestClass class2 = new TypeTestClass();
|
||||||
class1.objectArrayField = new Object[] {"string", 1, 2};
|
class1.objectArrayField = new Object[] {"string", 1, 2};
|
||||||
class2.objectArrayField = new Object[] {"string", 1, 2};
|
class2.objectArrayField = new Object[] {"string", 1, 2};
|
||||||
DiffList list = class1.diff(class2);
|
DiffResult list = class1.diff(class2);
|
||||||
assertEquals(0, list.getNumberOfDiffs());
|
assertEquals(0, list.getNumberOfDiffs());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testByteArrayEqualAsObject() throws Exception {
|
public void testByteArrayEqualAsObject() throws Exception {
|
||||||
DiffList list = new DiffBuilder("String1", "String2", SHORT_STYLE)
|
DiffResult list = new DiffBuilder("String1", "String2", SHORT_STYLE)
|
||||||
.append("foo", (Object) new boolean[] {false}, (Object) new boolean[] {false})
|
.append("foo", (Object) new boolean[] {false}, (Object) new boolean[] {false})
|
||||||
.append("foo", (Object) new byte[] {0x01}, (Object) new byte[] {0x01})
|
.append("foo", (Object) new byte[] {0x01}, (Object) new byte[] {0x01})
|
||||||
.append("foo", (Object) new char[] {'a'}, (Object) new char[] {'a'})
|
.append("foo", (Object) new char[] {'a'}, (Object) new char[] {'a'})
|
||||||
|
@ -385,7 +385,7 @@ public class DiffBuilderTest {
|
||||||
@Test
|
@Test
|
||||||
public void testSameObjectIgnoresAppends() {
|
public void testSameObjectIgnoresAppends() {
|
||||||
TypeTestClass testClass = new TypeTestClass();
|
TypeTestClass testClass = new TypeTestClass();
|
||||||
DiffList list = new DiffBuilder(testClass, testClass, SHORT_STYLE)
|
DiffResult list = new DiffBuilder(testClass, testClass, SHORT_STYLE)
|
||||||
.append("ignored", false, true)
|
.append("ignored", false, true)
|
||||||
.build();
|
.build();
|
||||||
assertEquals(0, list.getNumberOfDiffs());
|
assertEquals(0, list.getNumberOfDiffs());
|
||||||
|
@ -395,7 +395,7 @@ public class DiffBuilderTest {
|
||||||
public void testSimilarObjectIgnoresAppends() {
|
public void testSimilarObjectIgnoresAppends() {
|
||||||
TypeTestClass testClass1 = new TypeTestClass();
|
TypeTestClass testClass1 = new TypeTestClass();
|
||||||
TypeTestClass testClass2 = new TypeTestClass();
|
TypeTestClass testClass2 = new TypeTestClass();
|
||||||
DiffList list = new DiffBuilder(testClass1, testClass2, SHORT_STYLE)
|
DiffResult list = new DiffBuilder(testClass1, testClass2, SHORT_STYLE)
|
||||||
.append("ignored", false, true)
|
.append("ignored", false, true)
|
||||||
.build();
|
.build();
|
||||||
assertEquals(0, list.getNumberOfDiffs());
|
assertEquals(0, list.getNumberOfDiffs());
|
||||||
|
@ -403,9 +403,9 @@ public class DiffBuilderTest {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStylePassedToDiffList() {
|
public void testStylePassedToDiffResult() {
|
||||||
TypeTestClass class1 = new TypeTestClass();
|
TypeTestClass class1 = new TypeTestClass();
|
||||||
DiffList list = class1.diff(class1);
|
DiffResult list = class1.diff(class1);
|
||||||
assertEquals(SHORT_STYLE, list.getToStringStyle());
|
assertEquals(SHORT_STYLE, list.getToStringStyle());
|
||||||
|
|
||||||
class1.style = ToStringStyle.MULTI_LINE_STYLE;
|
class1.style = ToStringStyle.MULTI_LINE_STYLE;
|
||||||
|
|
|
@ -25,11 +25,11 @@ import java.util.List;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests {@link DiffList}.
|
* Unit tests {@link DiffResult}.
|
||||||
*
|
*
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public class DiffListTest {
|
public class DiffResultTest {
|
||||||
|
|
||||||
private static final SimpleClass SIMPLE_FALSE = new SimpleClass(false);
|
private static final SimpleClass SIMPLE_FALSE = new SimpleClass(false);
|
||||||
private static final SimpleClass SIMPLE_TRUE = new SimpleClass(true);
|
private static final SimpleClass SIMPLE_TRUE = new SimpleClass(true);
|
||||||
|
@ -47,7 +47,7 @@ public class DiffListTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DiffList diff(SimpleClass obj) {
|
public DiffResult diff(SimpleClass obj) {
|
||||||
return new DiffBuilder(this, obj, ToStringStyle.SHORT_PREFIX_STYLE)
|
return new DiffBuilder(this, obj, ToStringStyle.SHORT_PREFIX_STYLE)
|
||||||
.append(getFieldName(), booleanField, obj.booleanField)
|
.append(getFieldName(), booleanField, obj.booleanField)
|
||||||
.build();
|
.build();
|
||||||
|
@ -64,7 +64,7 @@ public class DiffListTest {
|
||||||
|
|
||||||
List<Diff<?>> diffs = lhs.diff(rhs).getDiffs();
|
List<Diff<?>> diffs = lhs.diff(rhs).getDiffs();
|
||||||
|
|
||||||
DiffList list = new DiffList(lhs, rhs, diffs, SHORT_STYLE);
|
DiffResult list = new DiffResult(lhs, rhs, diffs, SHORT_STYLE);
|
||||||
assertEquals(diffs, list.getDiffs());
|
assertEquals(diffs, list.getDiffs());
|
||||||
assertEquals(1, list.getNumberOfDiffs());
|
assertEquals(1, list.getNumberOfDiffs());
|
||||||
list.getDiffs().remove(0);
|
list.getDiffs().remove(0);
|
||||||
|
@ -78,7 +78,7 @@ public class DiffListTest {
|
||||||
List<Diff<?>> diffs = lhs.diff(rhs).getDiffs();
|
List<Diff<?>> diffs = lhs.diff(rhs).getDiffs();
|
||||||
Iterator<Diff<?>> expectedIterator = diffs.iterator();
|
Iterator<Diff<?>> expectedIterator = diffs.iterator();
|
||||||
|
|
||||||
DiffList list = new DiffList(lhs, rhs, diffs, SHORT_STYLE);
|
DiffResult list = new DiffResult(lhs, rhs, diffs, SHORT_STYLE);
|
||||||
Iterator<Diff<?>> iterator = list.iterator();
|
Iterator<Diff<?>> iterator = list.iterator();
|
||||||
|
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
|
@ -89,17 +89,17 @@ public class DiffListTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToStringOutput() {
|
public void testToStringOutput() {
|
||||||
DiffList list = new DiffBuilder(new EmptyClass(), new EmptyClass(),
|
DiffResult list = new DiffBuilder(new EmptyClass(), new EmptyClass(),
|
||||||
ToStringStyle.SHORT_PREFIX_STYLE).append("test", false, true)
|
ToStringStyle.SHORT_PREFIX_STYLE).append("test", false, true)
|
||||||
.build();
|
.build();
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"DiffListTest.EmptyClass[test=false] differs from DiffListTest.EmptyClass[test=true]",
|
"DiffResultTest.EmptyClass[test=false] differs from DiffResultTest.EmptyClass[test=true]",
|
||||||
list.toString());
|
list.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToStringSpecifyStyleOutput() {
|
public void testToStringSpecifyStyleOutput() {
|
||||||
DiffList list = SIMPLE_FALSE.diff(SIMPLE_TRUE);
|
DiffResult list = SIMPLE_FALSE.diff(SIMPLE_TRUE);
|
||||||
assertTrue(list.getToStringStyle().equals(SHORT_STYLE));
|
assertTrue(list.getToStringStyle().equals(SHORT_STYLE));
|
||||||
|
|
||||||
String lhsString = new ToStringBuilder(SIMPLE_FALSE,
|
String lhsString = new ToStringBuilder(SIMPLE_FALSE,
|
||||||
|
@ -118,32 +118,32 @@ public class DiffListTest {
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void testNullLhs() {
|
public void testNullLhs() {
|
||||||
new DiffList(null, SIMPLE_FALSE, SIMPLE_TRUE.diff(SIMPLE_FALSE)
|
new DiffResult(null, SIMPLE_FALSE, SIMPLE_TRUE.diff(SIMPLE_FALSE)
|
||||||
.getDiffs(), SHORT_STYLE);
|
.getDiffs(), SHORT_STYLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void testNullRhs() {
|
public void testNullRhs() {
|
||||||
new DiffList(SIMPLE_TRUE, null, SIMPLE_TRUE.diff(SIMPLE_FALSE)
|
new DiffResult(SIMPLE_TRUE, null, SIMPLE_TRUE.diff(SIMPLE_FALSE)
|
||||||
.getDiffs(), SHORT_STYLE);
|
.getDiffs(), SHORT_STYLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void testNullList() {
|
public void testNullList() {
|
||||||
new DiffList(SIMPLE_TRUE, SIMPLE_FALSE, null, SHORT_STYLE);
|
new DiffResult(SIMPLE_TRUE, SIMPLE_FALSE, null, SHORT_STYLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNullStyle() {
|
public void testNullStyle() {
|
||||||
DiffList diffList = new DiffList(SIMPLE_TRUE, SIMPLE_FALSE, SIMPLE_TRUE
|
DiffResult diffResult = new DiffResult(SIMPLE_TRUE, SIMPLE_FALSE, SIMPLE_TRUE
|
||||||
.diff(SIMPLE_FALSE).getDiffs(), null);
|
.diff(SIMPLE_FALSE).getDiffs(), null);
|
||||||
assertEquals(ToStringStyle.DEFAULT_STYLE, diffList.getToStringStyle());
|
assertEquals(ToStringStyle.DEFAULT_STYLE, diffResult.getToStringStyle());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoDifferencesString() {
|
public void testNoDifferencesString() {
|
||||||
DiffList diffList = new DiffBuilder(SIMPLE_TRUE, SIMPLE_TRUE,
|
DiffResult diffResult = new DiffBuilder(SIMPLE_TRUE, SIMPLE_TRUE,
|
||||||
SHORT_STYLE).build();
|
SHORT_STYLE).build();
|
||||||
assertEquals(DiffList.OBJECTS_SAME_STRING, diffList.toString());
|
assertEquals(DiffResult.OBJECTS_SAME_STRING, diffResult.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue