Port to JUnit 4.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1185708 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ccc01ec371
commit
cfc3d1fb1e
|
@ -16,20 +16,21 @@
|
|||
*/
|
||||
package org.apache.commons.lang3.builder;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit tests {@link org.apache.commons.lang3.builder.EqualsBuilder}.
|
||||
*
|
||||
* @version $Id$
|
||||
*/
|
||||
public class EqualsBuilderTest extends TestCase {
|
||||
|
||||
public EqualsBuilderTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
public class EqualsBuilderTest {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
|
@ -137,6 +138,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReflectionEquals() {
|
||||
TestObject o1 = new TestObject(4);
|
||||
TestObject o2 = new TestObject(5);
|
||||
|
@ -152,6 +154,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
assertTrue(EqualsBuilder.reflectionEquals((Object) null, (Object) null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReflectionHierarchyEquals() {
|
||||
testReflectionHierarchyEquals(false);
|
||||
testReflectionHierarchyEquals(true);
|
||||
|
@ -163,7 +166,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
assertTrue(!EqualsBuilder.reflectionEquals(new TestTTLeafObject(0, 2, 3, 4), new TestTTLeafObject(1, 2, 3, 4), true));
|
||||
}
|
||||
|
||||
public void testReflectionHierarchyEquals(boolean testTransients) {
|
||||
private void testReflectionHierarchyEquals(boolean testTransients) {
|
||||
TestObject to1 = new TestObject(4);
|
||||
TestObject to1Bis = new TestObject(4);
|
||||
TestObject to1Ter = new TestObject(4);
|
||||
|
@ -235,7 +238,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
* @param oToChange a TestObject that will be changed
|
||||
* @param testTransients whether to test transient instance variables
|
||||
*/
|
||||
public void testReflectionEqualsEquivalenceRelationship(
|
||||
private void testReflectionEqualsEquivalenceRelationship(
|
||||
TestObject to,
|
||||
TestObject toBis,
|
||||
TestObject toTer,
|
||||
|
@ -278,6 +281,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
assertTrue(EqualsBuilder.reflectionEquals((Object) null, (Object) null, testTransients));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuper() {
|
||||
TestObject o1 = new TestObject(4);
|
||||
TestObject o2 = new TestObject(5);
|
||||
|
@ -287,6 +291,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
assertEquals(false, new EqualsBuilder().appendSuper(false).append(o1, o2).isEquals());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObject() {
|
||||
TestObject o1 = new TestObject(4);
|
||||
TestObject o2 = new TestObject(5);
|
||||
|
@ -302,6 +307,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
assertTrue(new EqualsBuilder().append((Object) null, (Object) null).isEquals());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectBuild() {
|
||||
TestObject o1 = new TestObject(4);
|
||||
TestObject o2 = new TestObject(5);
|
||||
|
@ -317,6 +323,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
assertTrue(new EqualsBuilder().append((Object) null, (Object) null).build());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLong() {
|
||||
long o1 = 1L;
|
||||
long o2 = 2L;
|
||||
|
@ -324,6 +331,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
assertTrue(!new EqualsBuilder().append(o1, o2).isEquals());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInt() {
|
||||
int o1 = 1;
|
||||
int o2 = 2;
|
||||
|
@ -331,6 +339,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
assertTrue(!new EqualsBuilder().append(o1, o2).isEquals());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShort() {
|
||||
short o1 = 1;
|
||||
short o2 = 2;
|
||||
|
@ -338,6 +347,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
assertTrue(!new EqualsBuilder().append(o1, o2).isEquals());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testChar() {
|
||||
char o1 = 1;
|
||||
char o2 = 2;
|
||||
|
@ -345,6 +355,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
assertTrue(!new EqualsBuilder().append(o1, o2).isEquals());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testByte() {
|
||||
byte o1 = 1;
|
||||
byte o2 = 2;
|
||||
|
@ -352,6 +363,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
assertTrue(!new EqualsBuilder().append(o1, o2).isEquals());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDouble() {
|
||||
double o1 = 1;
|
||||
double o2 = 2;
|
||||
|
@ -362,6 +374,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
assertTrue(new EqualsBuilder().append(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY).isEquals());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFloat() {
|
||||
float o1 = 1;
|
||||
float o2 = 2;
|
||||
|
@ -372,6 +385,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
assertTrue(new EqualsBuilder().append(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY).isEquals());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAccessors() {
|
||||
EqualsBuilder equalsBuilder = new EqualsBuilder();
|
||||
assertTrue(equalsBuilder.isEquals());
|
||||
|
@ -381,6 +395,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
assertFalse(equalsBuilder.isEquals());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReset() {
|
||||
EqualsBuilder equalsBuilder = new EqualsBuilder();
|
||||
assertTrue(equalsBuilder.isEquals());
|
||||
|
@ -390,6 +405,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
assertTrue(equalsBuilder.isEquals());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBoolean() {
|
||||
boolean o1 = true;
|
||||
boolean o2 = false;
|
||||
|
@ -397,6 +413,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
assertTrue(!new EqualsBuilder().append(o1, o2).isEquals());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectArray() {
|
||||
TestObject[] obj1 = new TestObject[3];
|
||||
obj1[0] = new TestObject(4);
|
||||
|
@ -425,6 +442,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongArray() {
|
||||
long[] obj1 = new long[2];
|
||||
obj1[0] = 5L;
|
||||
|
@ -443,6 +461,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntArray() {
|
||||
int[] obj1 = new int[2];
|
||||
obj1[0] = 5;
|
||||
|
@ -461,6 +480,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShortArray() {
|
||||
short[] obj1 = new short[2];
|
||||
obj1[0] = 5;
|
||||
|
@ -479,6 +499,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCharArray() {
|
||||
char[] obj1 = new char[2];
|
||||
obj1[0] = 5;
|
||||
|
@ -497,6 +518,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testByteArray() {
|
||||
byte[] obj1 = new byte[2];
|
||||
obj1[0] = 5;
|
||||
|
@ -515,6 +537,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoubleArray() {
|
||||
double[] obj1 = new double[2];
|
||||
obj1[0] = 5;
|
||||
|
@ -533,6 +556,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFloatArray() {
|
||||
float[] obj1 = new float[2];
|
||||
obj1[0] = 5;
|
||||
|
@ -551,6 +575,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBooleanArray() {
|
||||
boolean[] obj1 = new boolean[2];
|
||||
obj1[0] = true;
|
||||
|
@ -569,6 +594,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiLongArray() {
|
||||
long[][] array1 = new long[2][2];
|
||||
long[][] array2 = new long[2][2];
|
||||
|
@ -584,6 +610,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
assertTrue(!new EqualsBuilder().append(array1, array2).isEquals());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiIntArray() {
|
||||
int[][] array1 = new int[2][2];
|
||||
int[][] array2 = new int[2][2];
|
||||
|
@ -599,6 +626,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
assertTrue(!new EqualsBuilder().append(array1, array2).isEquals());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiShortArray() {
|
||||
short[][] array1 = new short[2][2];
|
||||
short[][] array2 = new short[2][2];
|
||||
|
@ -614,6 +642,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
assertTrue(!new EqualsBuilder().append(array1, array2).isEquals());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiCharArray() {
|
||||
char[][] array1 = new char[2][2];
|
||||
char[][] array2 = new char[2][2];
|
||||
|
@ -629,6 +658,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
assertTrue(!new EqualsBuilder().append(array1, array2).isEquals());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiByteArray() {
|
||||
byte[][] array1 = new byte[2][2];
|
||||
byte[][] array2 = new byte[2][2];
|
||||
|
@ -643,6 +673,8 @@ public class EqualsBuilderTest extends TestCase {
|
|||
array1[1][1] = 0;
|
||||
assertTrue(!new EqualsBuilder().append(array1, array2).isEquals());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiFloatArray() {
|
||||
float[][] array1 = new float[2][2];
|
||||
float[][] array2 = new float[2][2];
|
||||
|
@ -658,6 +690,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
assertTrue(!new EqualsBuilder().append(array1, array2).isEquals());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiDoubleArray() {
|
||||
double[][] array1 = new double[2][2];
|
||||
double[][] array2 = new double[2][2];
|
||||
|
@ -673,6 +706,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
assertTrue(!new EqualsBuilder().append(array1, array2).isEquals());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiBooleanArray() {
|
||||
boolean[][] array1 = new boolean[2][2];
|
||||
boolean[][] array2 = new boolean[2][2];
|
||||
|
@ -695,6 +729,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
assertFalse(new EqualsBuilder().append(array3, array2).isEquals());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRaggedArray() {
|
||||
long array1[][] = new long[2][];
|
||||
long array2[][] = new long[2][];
|
||||
|
@ -712,6 +747,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
assertTrue(!new EqualsBuilder().append(array1, array2).isEquals());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMixedArray() {
|
||||
Object array1[] = new Object[2];
|
||||
Object array2[] = new Object[2];
|
||||
|
@ -729,6 +765,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
assertTrue(!new EqualsBuilder().append(array1, array2).isEquals());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectArrayHiddenByObject() {
|
||||
TestObject[] array1 = new TestObject[2];
|
||||
array1[0] = new TestObject(4);
|
||||
|
@ -746,6 +783,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
assertTrue(!new EqualsBuilder().append(obj1, obj2).isEquals());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongArrayHiddenByObject() {
|
||||
long[] array1 = new long[2];
|
||||
array1[0] = 5L;
|
||||
|
@ -763,6 +801,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
assertTrue(!new EqualsBuilder().append(obj1, obj2).isEquals());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntArrayHiddenByObject() {
|
||||
int[] array1 = new int[2];
|
||||
array1[0] = 5;
|
||||
|
@ -780,6 +819,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
assertTrue(!new EqualsBuilder().append(obj1, obj2).isEquals());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShortArrayHiddenByObject() {
|
||||
short[] array1 = new short[2];
|
||||
array1[0] = 5;
|
||||
|
@ -797,6 +837,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
assertTrue(!new EqualsBuilder().append(obj1, obj2).isEquals());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCharArrayHiddenByObject() {
|
||||
char[] array1 = new char[2];
|
||||
array1[0] = 5;
|
||||
|
@ -814,6 +855,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
assertTrue(!new EqualsBuilder().append(obj1, obj2).isEquals());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testByteArrayHiddenByObject() {
|
||||
byte[] array1 = new byte[2];
|
||||
array1[0] = 5;
|
||||
|
@ -831,6 +873,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
assertTrue(!new EqualsBuilder().append(obj1, obj2).isEquals());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoubleArrayHiddenByObject() {
|
||||
double[] array1 = new double[2];
|
||||
array1[0] = 5;
|
||||
|
@ -848,6 +891,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
assertTrue(!new EqualsBuilder().append(obj1, obj2).isEquals());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFloatArrayHiddenByObject() {
|
||||
float[] array1 = new float[2];
|
||||
array1[0] = 5;
|
||||
|
@ -865,6 +909,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
assertTrue(!new EqualsBuilder().append(obj1, obj2).isEquals());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBooleanArrayHiddenByObject() {
|
||||
boolean[] array1 = new boolean[2];
|
||||
array1[0] = true;
|
||||
|
@ -933,6 +978,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
* of each other and do not share a parent aside from Object.
|
||||
* See http://issues.apache.org/bugzilla/show_bug.cgi?id=33069
|
||||
*/
|
||||
@Test
|
||||
public void testUnrelatedClasses() {
|
||||
Object[] x = new Object[]{new TestACanEqualB(1)};
|
||||
Object[] y = new Object[]{new TestBCanEqualA(1)};
|
||||
|
@ -956,6 +1002,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
/**
|
||||
* Test from http://issues.apache.org/bugzilla/show_bug.cgi?id=33067
|
||||
*/
|
||||
@Test
|
||||
public void testNpeForNullElement() {
|
||||
Object[] x1 = new Object[] { Integer.valueOf(1), null, Integer.valueOf(3) };
|
||||
Object[] x2 = new Object[] { Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3) };
|
||||
|
@ -965,6 +1012,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
new EqualsBuilder().append(x1, x2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReflectionEqualsExcludeFields() throws Exception {
|
||||
TestObjectWithMultipleFields x1 = new TestObjectWithMultipleFields(1, 2, 3);
|
||||
TestObjectWithMultipleFields x2 = new TestObjectWithMultipleFields(1, 3, 4);
|
||||
|
@ -1008,6 +1056,7 @@ public class EqualsBuilderTest extends TestCase {
|
|||
* Test cyclical object references which cause a StackOverflowException if
|
||||
* not handled properly. s. LANG-606
|
||||
*/
|
||||
@Test
|
||||
public void testCyclicalObjectReferences() {
|
||||
TestObjectReference refX1 = new TestObjectReference(1);
|
||||
TestObjectReference x1 = new TestObjectReference(1);
|
||||
|
|
Loading…
Reference in New Issue