Sort members.
This commit is contained in:
parent
3ea8244287
commit
26ed080b46
|
@ -35,8 +35,6 @@ import org.junit.jupiter.api.Test;
|
||||||
*/
|
*/
|
||||||
public class DiffBuilderTest {
|
public class DiffBuilderTest {
|
||||||
|
|
||||||
private static final ToStringStyle SHORT_STYLE = ToStringStyle.SHORT_PREFIX_STYLE;
|
|
||||||
|
|
||||||
private static class TypeTestClass implements Diffable<TypeTestClass> {
|
private static class TypeTestClass implements Diffable<TypeTestClass> {
|
||||||
private ToStringStyle style = SHORT_STYLE;
|
private ToStringStyle style = SHORT_STYLE;
|
||||||
private boolean booleanField = true;
|
private boolean booleanField = true;
|
||||||
|
@ -82,16 +80,18 @@ public class DiffBuilderTest {
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return HashCodeBuilder.reflectionHashCode(this, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(final Object obj) {
|
public boolean equals(final Object obj) {
|
||||||
return EqualsBuilder.reflectionEquals(this, obj, false);
|
return EqualsBuilder.reflectionEquals(this, obj, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return HashCodeBuilder.reflectionHashCode(this, false);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final ToStringStyle SHORT_STYLE = ToStringStyle.SHORT_PREFIX_STYLE;
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -148,6 +148,24 @@ public class DiffBuilderTest {
|
||||||
(Object[]) diff.getRight());
|
(Object[]) diff.getRight());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testByteArrayEqualAsObject() {
|
||||||
|
final DiffResult<String> list = new DiffBuilder<>("String1", "String2", SHORT_STYLE)
|
||||||
|
.append("foo", new boolean[] {false}, new boolean[] {false})
|
||||||
|
.append("foo", new byte[] {0x01}, new byte[] {0x01})
|
||||||
|
.append("foo", new char[] {'a'}, new char[] {'a'})
|
||||||
|
.append("foo", new double[] {1.0}, new double[] {1.0})
|
||||||
|
.append("foo", new float[] {1.0F}, new float[] {1.0F})
|
||||||
|
.append("foo", new int[] {1}, new int[] {1})
|
||||||
|
.append("foo", new long[] {1L}, new long[] {1L})
|
||||||
|
.append("foo", new short[] {1}, new short[] {1})
|
||||||
|
.append("foo", new Object[] {1, "two"}, new Object[] {1, "two"})
|
||||||
|
.build();
|
||||||
|
|
||||||
|
assertEquals(0, list.getNumberOfDiffs());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testChar() {
|
public void testChar() {
|
||||||
final TypeTestClass class1 = new TypeTestClass();
|
final TypeTestClass class1 = new TypeTestClass();
|
||||||
|
@ -176,6 +194,19 @@ public class DiffBuilderTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDiffResult() {
|
||||||
|
final TypeTestClass class1 = new TypeTestClass();
|
||||||
|
final TypeTestClass class2 = new TypeTestClass();
|
||||||
|
class2.intField = 2;
|
||||||
|
|
||||||
|
final DiffResult<TypeTestClass> list = new DiffBuilder<>(class1, class2, SHORT_STYLE)
|
||||||
|
.append("prop1", class1.diff(class2))
|
||||||
|
.build();
|
||||||
|
assertEquals(1, list.getNumberOfDiffs());
|
||||||
|
assertEquals("prop1.int", list.getDiffs().get(0).getFieldName());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDouble() {
|
public void testDouble() {
|
||||||
final TypeTestClass class1 = new TypeTestClass();
|
final TypeTestClass class1 = new TypeTestClass();
|
||||||
|
@ -203,6 +234,7 @@ public class DiffBuilderTest {
|
||||||
(Object[]) diff.getRight());
|
(Object[]) diff.getRight());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFloat() {
|
public void testFloat() {
|
||||||
final TypeTestClass class1 = new TypeTestClass();
|
final TypeTestClass class1 = new TypeTestClass();
|
||||||
|
@ -230,7 +262,6 @@ public class DiffBuilderTest {
|
||||||
(Object[]) diff.getRight());
|
(Object[]) diff.getRight());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInt() {
|
public void testInt() {
|
||||||
final TypeTestClass class1 = new TypeTestClass();
|
final TypeTestClass class1 = new TypeTestClass();
|
||||||
|
@ -286,30 +317,13 @@ public class DiffBuilderTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testShort() {
|
public void testNullLhs() {
|
||||||
final TypeTestClass class1 = new TypeTestClass();
|
assertThrows(IllegalArgumentException.class, () -> new DiffBuilder<>(null, this, ToStringStyle.DEFAULT_STYLE));
|
||||||
final TypeTestClass class2 = new TypeTestClass();
|
|
||||||
class2.shortField = 42;
|
|
||||||
final DiffResult<TypeTestClass> list = class1.diff(class2);
|
|
||||||
assertEquals(1, list.getNumberOfDiffs());
|
|
||||||
final Diff<?> diff = list.getDiffs().get(0);
|
|
||||||
assertEquals(Short.valueOf(class1.shortField), diff.getLeft());
|
|
||||||
assertEquals(Short.valueOf(class2.shortField), diff.getRight());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testShortArray() {
|
public void testNullRhs() {
|
||||||
final TypeTestClass class1 = new TypeTestClass();
|
assertThrows(IllegalArgumentException.class, () -> new DiffBuilder<>(this, null, ToStringStyle.DEFAULT_STYLE));
|
||||||
final TypeTestClass class2 = new TypeTestClass();
|
|
||||||
class2.shortArrayField = new short[] {3, 2, 1};
|
|
||||||
final DiffResult<TypeTestClass> list = class1.diff(class2);
|
|
||||||
assertEquals(1, list.getNumberOfDiffs());
|
|
||||||
final Diff<?> diff = list.getDiffs().get(0);
|
|
||||||
assertArrayEquals(ArrayUtils.toObject(class1.shortArrayField),
|
|
||||||
(Object[]) diff.getLeft());
|
|
||||||
assertArrayEquals(ArrayUtils.toObject(class2.shortArrayField),
|
|
||||||
(Object[]) diff.getRight());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -324,20 +338,25 @@ public class DiffBuilderTest {
|
||||||
assertEquals(class2.objectField, diff.getRight());
|
assertEquals(class2.objectField, diff.getRight());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Test that "left" and "right" are the same instance and are equal.
|
|
||||||
*/
|
|
||||||
@Test
|
@Test
|
||||||
public void testObjectsSameAndEqual() {
|
public void testObjectArray() {
|
||||||
final Integer sameObject = 1;
|
final TypeTestClass class1 = new TypeTestClass();
|
||||||
final TypeTestClass left = new TypeTestClass();
|
final TypeTestClass class2 = new TypeTestClass();
|
||||||
left.objectField = sameObject;
|
class2.objectArrayField = new Object[] {"string", 1, 2};
|
||||||
final TypeTestClass right = new TypeTestClass();
|
final DiffResult<TypeTestClass> list = class1.diff(class2);
|
||||||
right.objectField = sameObject;
|
assertEquals(1, list.getNumberOfDiffs());
|
||||||
assertSame(left.objectField, right.objectField);
|
final Diff<?> diff = list.getDiffs().get(0);
|
||||||
assertEquals(left.objectField, right.objectField);
|
assertArrayEquals(class1.objectArrayField, (Object[]) diff.getLeft());
|
||||||
|
assertArrayEquals(class2.objectArrayField, (Object[]) diff.getRight());
|
||||||
|
}
|
||||||
|
|
||||||
final DiffResult<TypeTestClass> list = left.diff(right);
|
@Test
|
||||||
|
public void testObjectArrayEqual() {
|
||||||
|
final TypeTestClass class1 = new TypeTestClass();
|
||||||
|
final TypeTestClass class2 = new TypeTestClass();
|
||||||
|
class1.objectArrayField = new Object[] {"string", 1, 2};
|
||||||
|
class2.objectArrayField = new Object[] {"string", 1, 2};
|
||||||
|
final DiffResult<TypeTestClass> list = class1.diff(class2);
|
||||||
assertEquals(0, list.getNumberOfDiffs());
|
assertEquals(0, list.getNumberOfDiffs());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -373,70 +392,23 @@ public class DiffBuilderTest {
|
||||||
assertEquals(1, list.getNumberOfDiffs());
|
assertEquals(1, list.getNumberOfDiffs());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that "left" and "right" are the same instance and are equal.
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testObjectArray() {
|
public void testObjectsSameAndEqual() {
|
||||||
final TypeTestClass class1 = new TypeTestClass();
|
final Integer sameObject = 1;
|
||||||
final TypeTestClass class2 = new TypeTestClass();
|
final TypeTestClass left = new TypeTestClass();
|
||||||
class2.objectArrayField = new Object[] {"string", 1, 2};
|
left.objectField = sameObject;
|
||||||
final DiffResult<TypeTestClass> list = class1.diff(class2);
|
final TypeTestClass right = new TypeTestClass();
|
||||||
assertEquals(1, list.getNumberOfDiffs());
|
right.objectField = sameObject;
|
||||||
final Diff<?> diff = list.getDiffs().get(0);
|
assertSame(left.objectField, right.objectField);
|
||||||
assertArrayEquals(class1.objectArrayField, (Object[]) diff.getLeft());
|
assertEquals(left.objectField, right.objectField);
|
||||||
assertArrayEquals(class2.objectArrayField, (Object[]) diff.getRight());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
final DiffResult<TypeTestClass> list = left.diff(right);
|
||||||
public void testObjectArrayEqual() {
|
|
||||||
final TypeTestClass class1 = new TypeTestClass();
|
|
||||||
final TypeTestClass class2 = new TypeTestClass();
|
|
||||||
class1.objectArrayField = new Object[] {"string", 1, 2};
|
|
||||||
class2.objectArrayField = new Object[] {"string", 1, 2};
|
|
||||||
final DiffResult<TypeTestClass> list = class1.diff(class2);
|
|
||||||
assertEquals(0, list.getNumberOfDiffs());
|
assertEquals(0, list.getNumberOfDiffs());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testByteArrayEqualAsObject() {
|
|
||||||
final DiffResult<String> list = new DiffBuilder<>("String1", "String2", SHORT_STYLE)
|
|
||||||
.append("foo", new boolean[] {false}, new boolean[] {false})
|
|
||||||
.append("foo", new byte[] {0x01}, new byte[] {0x01})
|
|
||||||
.append("foo", new char[] {'a'}, new char[] {'a'})
|
|
||||||
.append("foo", new double[] {1.0}, new double[] {1.0})
|
|
||||||
.append("foo", new float[] {1.0F}, new float[] {1.0F})
|
|
||||||
.append("foo", new int[] {1}, new int[] {1})
|
|
||||||
.append("foo", new long[] {1L}, new long[] {1L})
|
|
||||||
.append("foo", new short[] {1}, new short[] {1})
|
|
||||||
.append("foo", new Object[] {1, "two"}, new Object[] {1, "two"})
|
|
||||||
.build();
|
|
||||||
|
|
||||||
assertEquals(0, list.getNumberOfDiffs());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testDiffResult() {
|
|
||||||
final TypeTestClass class1 = new TypeTestClass();
|
|
||||||
final TypeTestClass class2 = new TypeTestClass();
|
|
||||||
class2.intField = 2;
|
|
||||||
|
|
||||||
final DiffResult<TypeTestClass> list = new DiffBuilder<>(class1, class2, SHORT_STYLE)
|
|
||||||
.append("prop1", class1.diff(class2))
|
|
||||||
.build();
|
|
||||||
assertEquals(1, list.getNumberOfDiffs());
|
|
||||||
assertEquals("prop1.int", list.getDiffs().get(0).getFieldName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testNullLhs() {
|
|
||||||
assertThrows(IllegalArgumentException.class, () -> new DiffBuilder<>(null, this, ToStringStyle.DEFAULT_STYLE));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testNullRhs() {
|
|
||||||
assertThrows(IllegalArgumentException.class, () -> new DiffBuilder<>(this, null, ToStringStyle.DEFAULT_STYLE));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSameObjectIgnoresAppends() {
|
public void testSameObjectIgnoresAppends() {
|
||||||
final TypeTestClass testClass = new TypeTestClass();
|
final TypeTestClass testClass = new TypeTestClass();
|
||||||
|
@ -446,6 +418,33 @@ public class DiffBuilderTest {
|
||||||
assertEquals(0, list.getNumberOfDiffs());
|
assertEquals(0, list.getNumberOfDiffs());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testShort() {
|
||||||
|
final TypeTestClass class1 = new TypeTestClass();
|
||||||
|
final TypeTestClass class2 = new TypeTestClass();
|
||||||
|
class2.shortField = 42;
|
||||||
|
final DiffResult<TypeTestClass> list = class1.diff(class2);
|
||||||
|
assertEquals(1, list.getNumberOfDiffs());
|
||||||
|
final Diff<?> diff = list.getDiffs().get(0);
|
||||||
|
assertEquals(Short.valueOf(class1.shortField), diff.getLeft());
|
||||||
|
assertEquals(Short.valueOf(class2.shortField), diff.getRight());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testShortArray() {
|
||||||
|
final TypeTestClass class1 = new TypeTestClass();
|
||||||
|
final TypeTestClass class2 = new TypeTestClass();
|
||||||
|
class2.shortArrayField = new short[] {3, 2, 1};
|
||||||
|
final DiffResult<TypeTestClass> list = class1.diff(class2);
|
||||||
|
assertEquals(1, list.getNumberOfDiffs());
|
||||||
|
final Diff<?> diff = list.getDiffs().get(0);
|
||||||
|
assertArrayEquals(ArrayUtils.toObject(class1.shortArrayField),
|
||||||
|
(Object[]) diff.getLeft());
|
||||||
|
assertArrayEquals(ArrayUtils.toObject(class2.shortArrayField),
|
||||||
|
(Object[]) diff.getRight());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSimilarObjectIgnoresAppends() {
|
public void testSimilarObjectIgnoresAppends() {
|
||||||
final TypeTestClass testClass1 = new TypeTestClass();
|
final TypeTestClass testClass1 = new TypeTestClass();
|
||||||
|
|
Loading…
Reference in New Issue