Best Mockito code snippet using org.mockito.internal.matchers.apachecommons.EqualsBuilderTest
Source:EqualsBuilderTest.java
...17 * @author <a href="mailto:sdowney@panix.com">Steve Downey</a>18 * @author <a href="mailto:scolebourne@joda.org">Stephen Colebourne</a>19 * @author <a href="mailto:ggregory@seagullsw.com">Gary Gregory</a>20 * @author Maarten Coene21 * @version $Id: EqualsBuilderTest.java 611543 2008-01-13 07:00:22Z bayard $22 */23public class EqualsBuilderTest extends TestBase {24 static class TestObject {25 private int a;26 public TestObject() {27 }28 public TestObject(int a) {29 this.a = a;30 }31 public boolean equals(Object o) {32 if (o == null) {33 return false;34 }35 if (o == (this)) {36 return true;37 }38 if ((o.getClass()) != (getClass())) {39 return false;40 }41 EqualsBuilderTest.TestObject rhs = ((EqualsBuilderTest.TestObject) (o));42 return (a) == (rhs.a);43 }44 public int hashCode() {45 return super.hashCode();46 }47 public void setA(int a) {48 this.a = a;49 }50 public int getA() {51 return a;52 }53 }54 static class TestSubObject extends EqualsBuilderTest.TestObject {55 private int b;56 public TestSubObject() {57 super(0);58 }59 public TestSubObject(int a, int b) {60 super(a);61 this.b = b;62 }63 public boolean equals(Object o) {64 if (o == null) {65 return false;66 }67 if (o == (this)) {68 return true;69 }70 if ((o.getClass()) != (getClass())) {71 return false;72 }73 EqualsBuilderTest.TestSubObject rhs = ((EqualsBuilderTest.TestSubObject) (o));74 return (super.equals(o)) && ((b) == (rhs.b));75 }76 public int hashCode() {77 return 1;78 }79 public void setB(int b) {80 this.b = b;81 }82 public int getB() {83 return b;84 }85 }86 static class TestEmptySubObject extends EqualsBuilderTest.TestObject {87 public TestEmptySubObject(int a) {88 super(a);89 }90 }91 @SuppressWarnings("unused")92 static class TestTSubObject extends EqualsBuilderTest.TestObject {93 private transient int t;94 public TestTSubObject(int a, int t) {95 super(a);96 this.t = t;97 }98 }99 @SuppressWarnings("unused")100 static class TestTTSubObject extends EqualsBuilderTest.TestTSubObject {101 private transient int tt;102 public TestTTSubObject(int a, int t, int tt) {103 super(a, t);104 this.tt = tt;105 }106 }107 @SuppressWarnings("unused")108 static class TestTTLeafObject extends EqualsBuilderTest.TestTTSubObject {109 private int leafValue;110 public TestTTLeafObject(int a, int t, int tt, int leafValue) {111 super(a, t, tt);112 this.leafValue = leafValue;113 }114 }115 static class TestTSubObject2 extends EqualsBuilderTest.TestObject {116 private transient int t;117 public TestTSubObject2(int a, int t) {118 super(a);119 }120 public int getT() {121 return t;122 }123 public void setT(int t) {124 this.t = t;125 }126 }127 @Test128 public void testReflectionEquals() {129 EqualsBuilderTest.TestObject o1 = new EqualsBuilderTest.TestObject(4);130 EqualsBuilderTest.TestObject o2 = new EqualsBuilderTest.TestObject(5);131 Assert.assertTrue(EqualsBuilder.reflectionEquals(o1, o1));132 Assert.assertTrue((!(EqualsBuilder.reflectionEquals(o1, o2))));133 o2.setA(4);134 Assert.assertTrue(EqualsBuilder.reflectionEquals(o1, o2));135 Assert.assertTrue((!(EqualsBuilder.reflectionEquals(o1, this))));136 Assert.assertTrue((!(EqualsBuilder.reflectionEquals(o1, null))));137 Assert.assertTrue((!(EqualsBuilder.reflectionEquals(null, o2))));138 Assert.assertTrue(EqualsBuilder.reflectionEquals(((Object) (null)), ((Object) (null))));139 }140 @Test141 public void testReflectionHierarchyEquals() {142 testReflectionHierarchyEquals(false);143 testReflectionHierarchyEquals(true);144 // Transients145 Assert.assertTrue(EqualsBuilder.reflectionEquals(new EqualsBuilderTest.TestTTLeafObject(1, 2, 3, 4), new EqualsBuilderTest.TestTTLeafObject(1, 2, 3, 4), true));146 Assert.assertTrue(EqualsBuilder.reflectionEquals(new EqualsBuilderTest.TestTTLeafObject(1, 2, 3, 4), new EqualsBuilderTest.TestTTLeafObject(1, 2, 3, 4), false));147 Assert.assertTrue((!(EqualsBuilder.reflectionEquals(new EqualsBuilderTest.TestTTLeafObject(1, 0, 0, 4), new EqualsBuilderTest.TestTTLeafObject(1, 2, 3, 4), true))));148 Assert.assertTrue((!(EqualsBuilder.reflectionEquals(new EqualsBuilderTest.TestTTLeafObject(1, 2, 3, 4), new EqualsBuilderTest.TestTTLeafObject(1, 2, 3, 0), true))));149 Assert.assertTrue((!(EqualsBuilder.reflectionEquals(new EqualsBuilderTest.TestTTLeafObject(0, 2, 3, 4), new EqualsBuilderTest.TestTTLeafObject(1, 2, 3, 4), true))));150 }151 @Test152 public void testSuper() {153 EqualsBuilderTest.TestObject o1 = new EqualsBuilderTest.TestObject(4);154 EqualsBuilderTest.TestObject o2 = new EqualsBuilderTest.TestObject(5);155 Assert.assertEquals(true, new EqualsBuilder().appendSuper(true).append(o1, o1).isEquals());156 Assert.assertEquals(false, new EqualsBuilder().appendSuper(false).append(o1, o1).isEquals());157 Assert.assertEquals(false, new EqualsBuilder().appendSuper(true).append(o1, o2).isEquals());158 Assert.assertEquals(false, new EqualsBuilder().appendSuper(false).append(o1, o2).isEquals());159 }160 @Test161 public void testObject() {162 EqualsBuilderTest.TestObject o1 = new EqualsBuilderTest.TestObject(4);163 EqualsBuilderTest.TestObject o2 = new EqualsBuilderTest.TestObject(5);164 Assert.assertTrue(new EqualsBuilder().append(o1, o1).isEquals());165 Assert.assertTrue((!(new EqualsBuilder().append(o1, o2).isEquals())));166 o2.setA(4);167 Assert.assertTrue(new EqualsBuilder().append(o1, o2).isEquals());168 Assert.assertTrue((!(new EqualsBuilder().append(o1, this).isEquals())));169 Assert.assertTrue((!(new EqualsBuilder().append(o1, null).isEquals())));170 Assert.assertTrue((!(new EqualsBuilder().append(null, o2).isEquals())));171 Assert.assertTrue(new EqualsBuilder().append(((Object) (null)), ((Object) (null))).isEquals());172 }173 @Test174 public void testLong() {175 long o1 = 1L;176 long o2 = 2L;177 Assert.assertTrue(new EqualsBuilder().append(o1, o1).isEquals());178 Assert.assertTrue((!(new EqualsBuilder().append(o1, o2).isEquals())));179 }180 @Test181 public void testInt() {182 int o1 = 1;183 int o2 = 2;184 Assert.assertTrue(new EqualsBuilder().append(o1, o1).isEquals());185 Assert.assertTrue((!(new EqualsBuilder().append(o1, o2).isEquals())));186 }187 @Test188 public void testShort() {189 short o1 = 1;190 short o2 = 2;191 Assert.assertTrue(new EqualsBuilder().append(o1, o1).isEquals());192 Assert.assertTrue((!(new EqualsBuilder().append(o1, o2).isEquals())));193 }194 @Test195 public void testChar() {196 char o1 = 1;197 char o2 = 2;198 Assert.assertTrue(new EqualsBuilder().append(o1, o1).isEquals());199 Assert.assertTrue((!(new EqualsBuilder().append(o1, o2).isEquals())));200 }201 @Test202 public void testByte() {203 byte o1 = 1;204 byte o2 = 2;205 Assert.assertTrue(new EqualsBuilder().append(o1, o1).isEquals());206 Assert.assertTrue((!(new EqualsBuilder().append(o1, o2).isEquals())));207 }208 @Test209 public void testDouble() {210 double o1 = 1;211 double o2 = 2;212 Assert.assertTrue(new EqualsBuilder().append(o1, o1).isEquals());213 Assert.assertTrue((!(new EqualsBuilder().append(o1, o2).isEquals())));214 Assert.assertTrue((!(new EqualsBuilder().append(o1, Double.NaN).isEquals())));215 Assert.assertTrue(new EqualsBuilder().append(Double.NaN, Double.NaN).isEquals());216 Assert.assertTrue(new EqualsBuilder().append(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY).isEquals());217 }218 @Test219 public void testFloat() {220 float o1 = 1;221 float o2 = 2;222 Assert.assertTrue(new EqualsBuilder().append(o1, o1).isEquals());223 Assert.assertTrue((!(new EqualsBuilder().append(o1, o2).isEquals())));224 Assert.assertTrue((!(new EqualsBuilder().append(o1, Float.NaN).isEquals())));225 Assert.assertTrue(new EqualsBuilder().append(Float.NaN, Float.NaN).isEquals());226 Assert.assertTrue(new EqualsBuilder().append(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY).isEquals());227 }228 // https://issues.apache.org/jira/browse/LANG-393229 @Test230 public void testBigDecimal() {231 BigDecimal o1 = new BigDecimal("2.0");232 BigDecimal o2 = new BigDecimal("2.00");233 Assert.assertTrue(new EqualsBuilder().append(o1, o1).isEquals());234 Assert.assertTrue(new EqualsBuilder().append(o1, o2).isEquals());235 }236 @Test237 public void testAccessors() {238 EqualsBuilder equalsBuilder = new EqualsBuilder();239 Assert.assertTrue(equalsBuilder.isEquals());240 equalsBuilder.setEquals(true);241 Assert.assertTrue(equalsBuilder.isEquals());242 equalsBuilder.setEquals(false);243 Assert.assertFalse(equalsBuilder.isEquals());244 }245 @Test246 public void testBoolean() {247 boolean o1 = true;248 boolean o2 = false;249 Assert.assertTrue(new EqualsBuilder().append(o1, o1).isEquals());250 Assert.assertTrue((!(new EqualsBuilder().append(o1, o2).isEquals())));251 }252 @Test253 public void testObjectArray() {254 EqualsBuilderTest.TestObject[] obj1 = new EqualsBuilderTest.TestObject[3];255 obj1[0] = new EqualsBuilderTest.TestObject(4);256 obj1[1] = new EqualsBuilderTest.TestObject(5);257 obj1[2] = null;258 EqualsBuilderTest.TestObject[] obj2 = new EqualsBuilderTest.TestObject[3];259 obj2[0] = new EqualsBuilderTest.TestObject(4);260 obj2[1] = new EqualsBuilderTest.TestObject(5);261 obj2[2] = null;262 Assert.assertTrue(new EqualsBuilder().append(obj1, obj1).isEquals());263 Assert.assertTrue(new EqualsBuilder().append(obj2, obj2).isEquals());264 Assert.assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());265 obj1[1].setA(6);266 Assert.assertTrue((!(new EqualsBuilder().append(obj1, obj2).isEquals())));267 obj1[1].setA(5);268 Assert.assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());269 obj1[2] = obj1[1];270 Assert.assertTrue((!(new EqualsBuilder().append(obj1, obj2).isEquals())));271 obj1[2] = null;272 Assert.assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());273 obj2 = null;274 Assert.assertTrue((!(new EqualsBuilder().append(obj1, obj2).isEquals())));275 obj1 = null;276 Assert.assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());277 }278 @Test279 public void testLongArray() {280 long[] obj1 = new long[2];281 obj1[0] = 5L;282 obj1[1] = 6L;283 long[] obj2 = new long[2];284 obj2[0] = 5L;285 obj2[1] = 6L;286 Assert.assertTrue(new EqualsBuilder().append(obj1, obj1).isEquals());287 Assert.assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());288 obj1[1] = 7;289 Assert.assertTrue((!(new EqualsBuilder().append(obj1, obj2).isEquals())));290 obj2 = null;291 Assert.assertTrue((!(new EqualsBuilder().append(obj1, obj2).isEquals())));292 obj1 = null;293 Assert.assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());294 }295 @Test296 public void testIntArray() {297 int[] obj1 = new int[2];298 obj1[0] = 5;299 obj1[1] = 6;300 int[] obj2 = new int[2];301 obj2[0] = 5;302 obj2[1] = 6;303 Assert.assertTrue(new EqualsBuilder().append(obj1, obj1).isEquals());304 Assert.assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());305 obj1[1] = 7;306 Assert.assertTrue((!(new EqualsBuilder().append(obj1, obj2).isEquals())));307 obj2 = null;308 Assert.assertTrue((!(new EqualsBuilder().append(obj1, obj2).isEquals())));309 obj1 = null;310 Assert.assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());311 }312 @Test313 public void testShortArray() {314 short[] obj1 = new short[2];315 obj1[0] = 5;316 obj1[1] = 6;317 short[] obj2 = new short[2];318 obj2[0] = 5;319 obj2[1] = 6;320 Assert.assertTrue(new EqualsBuilder().append(obj1, obj1).isEquals());321 Assert.assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());322 obj1[1] = 7;323 Assert.assertTrue((!(new EqualsBuilder().append(obj1, obj2).isEquals())));324 obj2 = null;325 Assert.assertTrue((!(new EqualsBuilder().append(obj1, obj2).isEquals())));326 obj1 = null;327 Assert.assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());328 }329 @Test330 public void testCharArray() {331 char[] obj1 = new char[2];332 obj1[0] = 5;333 obj1[1] = 6;334 char[] obj2 = new char[2];335 obj2[0] = 5;336 obj2[1] = 6;337 Assert.assertTrue(new EqualsBuilder().append(obj1, obj1).isEquals());338 Assert.assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());339 obj1[1] = 7;340 Assert.assertTrue((!(new EqualsBuilder().append(obj1, obj2).isEquals())));341 obj2 = null;342 Assert.assertTrue((!(new EqualsBuilder().append(obj1, obj2).isEquals())));343 obj1 = null;344 Assert.assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());345 }346 @Test347 public void testByteArray() {348 byte[] obj1 = new byte[2];349 obj1[0] = 5;350 obj1[1] = 6;351 byte[] obj2 = new byte[2];352 obj2[0] = 5;353 obj2[1] = 6;354 Assert.assertTrue(new EqualsBuilder().append(obj1, obj1).isEquals());355 Assert.assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());356 obj1[1] = 7;357 Assert.assertTrue((!(new EqualsBuilder().append(obj1, obj2).isEquals())));358 obj2 = null;359 Assert.assertTrue((!(new EqualsBuilder().append(obj1, obj2).isEquals())));360 obj1 = null;361 Assert.assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());362 }363 @Test364 public void testDoubleArray() {365 double[] obj1 = new double[2];366 obj1[0] = 5;367 obj1[1] = 6;368 double[] obj2 = new double[2];369 obj2[0] = 5;370 obj2[1] = 6;371 Assert.assertTrue(new EqualsBuilder().append(obj1, obj1).isEquals());372 Assert.assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());373 obj1[1] = 7;374 Assert.assertTrue((!(new EqualsBuilder().append(obj1, obj2).isEquals())));375 obj2 = null;376 Assert.assertTrue((!(new EqualsBuilder().append(obj1, obj2).isEquals())));377 obj1 = null;378 Assert.assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());379 }380 @Test381 public void testFloatArray() {382 float[] obj1 = new float[2];383 obj1[0] = 5;384 obj1[1] = 6;385 float[] obj2 = new float[2];386 obj2[0] = 5;387 obj2[1] = 6;388 Assert.assertTrue(new EqualsBuilder().append(obj1, obj1).isEquals());389 Assert.assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());390 obj1[1] = 7;391 Assert.assertTrue((!(new EqualsBuilder().append(obj1, obj2).isEquals())));392 obj2 = null;393 Assert.assertTrue((!(new EqualsBuilder().append(obj1, obj2).isEquals())));394 obj1 = null;395 Assert.assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());396 }397 @Test398 public void testBooleanArray() {399 boolean[] obj1 = new boolean[2];400 obj1[0] = true;401 obj1[1] = false;402 boolean[] obj2 = new boolean[2];403 obj2[0] = true;404 obj2[1] = false;405 Assert.assertTrue(new EqualsBuilder().append(obj1, obj1).isEquals());406 Assert.assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());407 obj1[1] = true;408 Assert.assertTrue((!(new EqualsBuilder().append(obj1, obj2).isEquals())));409 obj2 = null;410 Assert.assertTrue((!(new EqualsBuilder().append(obj1, obj2).isEquals())));411 obj1 = null;412 Assert.assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());413 }414 @Test415 public void testMultiLongArray() {416 long[][] array1 = new long[2][2];417 long[][] array2 = new long[2][2];418 for (int i = 0; i < (array1.length); ++i) {419 for (int j = 0; j < (array1[0].length); j++) {420 array1[i][j] = (i + 1) * (j + 1);421 array2[i][j] = (i + 1) * (j + 1);422 }423 }424 Assert.assertTrue(new EqualsBuilder().append(array1, array1).isEquals());425 Assert.assertTrue(new EqualsBuilder().append(array1, array2).isEquals());426 array1[1][1] = 0;427 Assert.assertTrue((!(new EqualsBuilder().append(array1, array2).isEquals())));428 }429 @Test430 public void testMultiIntArray() {431 int[][] array1 = new int[2][2];432 int[][] array2 = new int[2][2];433 for (int i = 0; i < (array1.length); ++i) {434 for (int j = 0; j < (array1[0].length); j++) {435 array1[i][j] = (i + 1) * (j + 1);436 array2[i][j] = (i + 1) * (j + 1);437 }438 }439 Assert.assertTrue(new EqualsBuilder().append(array1, array1).isEquals());440 Assert.assertTrue(new EqualsBuilder().append(array1, array2).isEquals());441 array1[1][1] = 0;442 Assert.assertTrue((!(new EqualsBuilder().append(array1, array2).isEquals())));443 }444 @Test445 public void testMultiShortArray() {446 short[][] array1 = new short[2][2];447 short[][] array2 = new short[2][2];448 for (short i = 0; i < (array1.length); ++i) {449 for (short j = 0; j < (array1[0].length); j++) {450 array1[i][j] = i;451 array2[i][j] = i;452 }453 }454 Assert.assertTrue(new EqualsBuilder().append(array1, array1).isEquals());455 Assert.assertTrue(new EqualsBuilder().append(array1, array2).isEquals());456 array1[1][1] = 0;457 Assert.assertTrue((!(new EqualsBuilder().append(array1, array2).isEquals())));458 }459 @Test460 public void testMultiCharArray() {461 char[][] array1 = new char[2][2];462 char[][] array2 = new char[2][2];463 for (char i = 0; i < (array1.length); ++i) {464 for (char j = 0; j < (array1[0].length); j++) {465 array1[i][j] = i;466 array2[i][j] = i;467 }468 }469 Assert.assertTrue(new EqualsBuilder().append(array1, array1).isEquals());470 Assert.assertTrue(new EqualsBuilder().append(array1, array2).isEquals());471 array1[1][1] = 0;472 Assert.assertTrue((!(new EqualsBuilder().append(array1, array2).isEquals())));473 }474 @Test475 public void testMultiByteArray() {476 byte[][] array1 = new byte[2][2];477 byte[][] array2 = new byte[2][2];478 for (byte i = 0; i < (array1.length); ++i) {479 for (byte j = 0; j < (array1[0].length); j++) {480 array1[i][j] = i;481 array2[i][j] = i;482 }483 }484 Assert.assertTrue(new EqualsBuilder().append(array1, array1).isEquals());485 Assert.assertTrue(new EqualsBuilder().append(array1, array2).isEquals());486 array1[1][1] = 0;487 Assert.assertTrue((!(new EqualsBuilder().append(array1, array2).isEquals())));488 }489 @Test490 public void testMultiFloatArray() {491 float[][] array1 = new float[2][2];492 float[][] array2 = new float[2][2];493 for (int i = 0; i < (array1.length); ++i) {494 for (int j = 0; j < (array1[0].length); j++) {495 array1[i][j] = (i + 1) * (j + 1);496 array2[i][j] = (i + 1) * (j + 1);497 }498 }499 Assert.assertTrue(new EqualsBuilder().append(array1, array1).isEquals());500 Assert.assertTrue(new EqualsBuilder().append(array1, array2).isEquals());501 array1[1][1] = 0;502 Assert.assertTrue((!(new EqualsBuilder().append(array1, array2).isEquals())));503 }504 @Test505 public void testMultiDoubleArray() {506 double[][] array1 = new double[2][2];507 double[][] array2 = new double[2][2];508 for (int i = 0; i < (array1.length); ++i) {509 for (int j = 0; j < (array1[0].length); j++) {510 array1[i][j] = (i + 1) * (j + 1);511 array2[i][j] = (i + 1) * (j + 1);512 }513 }514 Assert.assertTrue(new EqualsBuilder().append(array1, array1).isEquals());515 Assert.assertTrue(new EqualsBuilder().append(array1, array2).isEquals());516 array1[1][1] = 0;517 Assert.assertTrue((!(new EqualsBuilder().append(array1, array2).isEquals())));518 }519 @Test520 public void testMultiBooleanArray() {521 boolean[][] array1 = new boolean[2][2];522 boolean[][] array2 = new boolean[2][2];523 for (int i = 0; i < (array1.length); ++i) {524 for (int j = 0; j < (array1[0].length); j++) {525 array1[i][j] = (i == 1) || (j == 1);526 array2[i][j] = (i == 1) || (j == 1);527 }528 }529 Assert.assertTrue(new EqualsBuilder().append(array1, array1).isEquals());530 Assert.assertTrue(new EqualsBuilder().append(array1, array2).isEquals());531 array1[1][1] = false;532 Assert.assertTrue((!(new EqualsBuilder().append(array1, array2).isEquals())));533 // compare 1 dim to 2.534 boolean[] array3 = new boolean[]{ true, true };535 Assert.assertFalse(new EqualsBuilder().append(array1, array3).isEquals());536 Assert.assertFalse(new EqualsBuilder().append(array3, array1).isEquals());537 Assert.assertFalse(new EqualsBuilder().append(array2, array3).isEquals());538 Assert.assertFalse(new EqualsBuilder().append(array3, array2).isEquals());539 }540 @Test541 public void testRaggedArray() {542 long[][] array1 = new long[2][];543 long[][] array2 = new long[2][];544 for (int i = 0; i < (array1.length); ++i) {545 array1[i] = new long[2];546 array2[i] = new long[2];547 for (int j = 0; j < (array1[i].length); ++j) {548 array1[i][j] = (i + 1) * (j + 1);549 array2[i][j] = (i + 1) * (j + 1);550 }551 }552 Assert.assertTrue(new EqualsBuilder().append(array1, array1).isEquals());553 Assert.assertTrue(new EqualsBuilder().append(array1, array2).isEquals());554 array1[1][1] = 0;555 Assert.assertTrue((!(new EqualsBuilder().append(array1, array2).isEquals())));556 }557 @Test558 public void testMixedArray() {559 Object[] array1 = new Object[2];560 Object[] array2 = new Object[2];561 for (int i = 0; i < (array1.length); ++i) {562 array1[i] = new long[2];563 array2[i] = new long[2];564 for (int j = 0; j < 2; ++j) {565 ((long[]) (array1[i]))[j] = (i + 1) * (j + 1);566 ((long[]) (array2[i]))[j] = (i + 1) * (j + 1);567 }568 }569 Assert.assertTrue(new EqualsBuilder().append(array1, array1).isEquals());570 Assert.assertTrue(new EqualsBuilder().append(array1, array2).isEquals());571 ((long[]) (array1[1]))[1] = 0;572 Assert.assertTrue((!(new EqualsBuilder().append(array1, array2).isEquals())));573 }574 @Test575 public void testObjectArrayHiddenByObject() {576 EqualsBuilderTest.TestObject[] array1 = new EqualsBuilderTest.TestObject[2];577 array1[0] = new EqualsBuilderTest.TestObject(4);578 array1[1] = new EqualsBuilderTest.TestObject(5);579 EqualsBuilderTest.TestObject[] array2 = new EqualsBuilderTest.TestObject[2];580 array2[0] = new EqualsBuilderTest.TestObject(4);581 array2[1] = new EqualsBuilderTest.TestObject(5);582 Object obj1 = array1;583 Object obj2 = array2;584 Assert.assertTrue(new EqualsBuilder().append(obj1, obj1).isEquals());585 Assert.assertTrue(new EqualsBuilder().append(obj1, array1).isEquals());586 Assert.assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());587 Assert.assertTrue(new EqualsBuilder().append(obj1, array2).isEquals());588 array1[1].setA(6);589 Assert.assertTrue((!(new EqualsBuilder().append(obj1, obj2).isEquals())));590 }591 @Test592 public void testLongArrayHiddenByObject() {593 long[] array1 = new long[2];594 array1[0] = 5L;595 array1[1] = 6L;596 long[] array2 = new long[2];597 array2[0] = 5L;598 array2[1] = 6L;599 Object obj1 = array1;600 Object obj2 = array2;601 Assert.assertTrue(new EqualsBuilder().append(obj1, obj1).isEquals());602 Assert.assertTrue(new EqualsBuilder().append(obj1, array1).isEquals());603 Assert.assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());604 Assert.assertTrue(new EqualsBuilder().append(obj1, array2).isEquals());605 array1[1] = 7;606 Assert.assertTrue((!(new EqualsBuilder().append(obj1, obj2).isEquals())));607 }608 @Test609 public void testIntArrayHiddenByObject() {610 int[] array1 = new int[2];611 array1[0] = 5;612 array1[1] = 6;613 int[] array2 = new int[2];614 array2[0] = 5;615 array2[1] = 6;616 Object obj1 = array1;617 Object obj2 = array2;618 Assert.assertTrue(new EqualsBuilder().append(obj1, obj1).isEquals());619 Assert.assertTrue(new EqualsBuilder().append(obj1, array1).isEquals());620 Assert.assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());621 Assert.assertTrue(new EqualsBuilder().append(obj1, array2).isEquals());622 array1[1] = 7;623 Assert.assertTrue((!(new EqualsBuilder().append(obj1, obj2).isEquals())));624 }625 @Test626 public void testShortArrayHiddenByObject() {627 short[] array1 = new short[2];628 array1[0] = 5;629 array1[1] = 6;630 short[] array2 = new short[2];631 array2[0] = 5;632 array2[1] = 6;633 Object obj1 = array1;634 Object obj2 = array2;635 Assert.assertTrue(new EqualsBuilder().append(obj1, obj1).isEquals());636 Assert.assertTrue(new EqualsBuilder().append(obj1, array1).isEquals());637 Assert.assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());638 Assert.assertTrue(new EqualsBuilder().append(obj1, array2).isEquals());639 array1[1] = 7;640 Assert.assertTrue((!(new EqualsBuilder().append(obj1, obj2).isEquals())));641 }642 @Test643 public void testCharArrayHiddenByObject() {644 char[] array1 = new char[2];645 array1[0] = 5;646 array1[1] = 6;647 char[] array2 = new char[2];648 array2[0] = 5;649 array2[1] = 6;650 Object obj1 = array1;651 Object obj2 = array2;652 Assert.assertTrue(new EqualsBuilder().append(obj1, obj1).isEquals());653 Assert.assertTrue(new EqualsBuilder().append(obj1, array1).isEquals());654 Assert.assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());655 Assert.assertTrue(new EqualsBuilder().append(obj1, array2).isEquals());656 array1[1] = 7;657 Assert.assertTrue((!(new EqualsBuilder().append(obj1, obj2).isEquals())));658 }659 @Test660 public void testByteArrayHiddenByObject() {661 byte[] array1 = new byte[2];662 array1[0] = 5;663 array1[1] = 6;664 byte[] array2 = new byte[2];665 array2[0] = 5;666 array2[1] = 6;667 Object obj1 = array1;668 Object obj2 = array2;669 Assert.assertTrue(new EqualsBuilder().append(obj1, obj1).isEquals());670 Assert.assertTrue(new EqualsBuilder().append(obj1, array1).isEquals());671 Assert.assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());672 Assert.assertTrue(new EqualsBuilder().append(obj1, array2).isEquals());673 array1[1] = 7;674 Assert.assertTrue((!(new EqualsBuilder().append(obj1, obj2).isEquals())));675 }676 @Test677 public void testDoubleArrayHiddenByObject() {678 double[] array1 = new double[2];679 array1[0] = 5;680 array1[1] = 6;681 double[] array2 = new double[2];682 array2[0] = 5;683 array2[1] = 6;684 Object obj1 = array1;685 Object obj2 = array2;686 Assert.assertTrue(new EqualsBuilder().append(obj1, obj1).isEquals());687 Assert.assertTrue(new EqualsBuilder().append(obj1, array1).isEquals());688 Assert.assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());689 Assert.assertTrue(new EqualsBuilder().append(obj1, array2).isEquals());690 array1[1] = 7;691 Assert.assertTrue((!(new EqualsBuilder().append(obj1, obj2).isEquals())));692 }693 @Test694 public void testFloatArrayHiddenByObject() {695 float[] array1 = new float[2];696 array1[0] = 5;697 array1[1] = 6;698 float[] array2 = new float[2];699 array2[0] = 5;700 array2[1] = 6;701 Object obj1 = array1;702 Object obj2 = array2;703 Assert.assertTrue(new EqualsBuilder().append(obj1, obj1).isEquals());704 Assert.assertTrue(new EqualsBuilder().append(obj1, array1).isEquals());705 Assert.assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());706 Assert.assertTrue(new EqualsBuilder().append(obj1, array2).isEquals());707 array1[1] = 7;708 Assert.assertTrue((!(new EqualsBuilder().append(obj1, obj2).isEquals())));709 }710 @Test711 public void testBooleanArrayHiddenByObject() {712 boolean[] array1 = new boolean[2];713 array1[0] = true;714 array1[1] = false;715 boolean[] array2 = new boolean[2];716 array2[0] = true;717 array2[1] = false;718 Object obj1 = array1;719 Object obj2 = array2;720 Assert.assertTrue(new EqualsBuilder().append(obj1, obj1).isEquals());721 Assert.assertTrue(new EqualsBuilder().append(obj1, array1).isEquals());722 Assert.assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());723 Assert.assertTrue(new EqualsBuilder().append(obj1, array2).isEquals());724 array1[1] = true;725 Assert.assertTrue((!(new EqualsBuilder().append(obj1, obj2).isEquals())));726 }727 public static class TestACanEqualB {728 private int a;729 public TestACanEqualB(int a) {730 this.a = a;731 }732 public boolean equals(Object o) {733 if (o == (this)) {734 return true;735 }736 if (o instanceof EqualsBuilderTest.TestACanEqualB) {737 return (this.a) == (((EqualsBuilderTest.TestACanEqualB) (o)).getA());738 }739 if (o instanceof EqualsBuilderTest.TestBCanEqualA) {740 return (this.a) == (((EqualsBuilderTest.TestBCanEqualA) (o)).getB());741 }742 return false;743 }744 public int hashCode() {745 return 1;746 }747 public int getA() {748 return this.a;749 }750 }751 public static class TestBCanEqualA {752 private int b;753 public TestBCanEqualA(int b) {754 this.b = b;755 }756 public boolean equals(Object o) {757 if (o == (this)) {758 return true;759 }760 if (o instanceof EqualsBuilderTest.TestACanEqualB) {761 return (this.b) == (((EqualsBuilderTest.TestACanEqualB) (o)).getA());762 }763 if (o instanceof EqualsBuilderTest.TestBCanEqualA) {764 return (this.b) == (((EqualsBuilderTest.TestBCanEqualA) (o)).getB());765 }766 return false;767 }768 public int hashCode() {769 return 1;770 }771 public int getB() {772 return this.b;773 }774 }775 /**776 * Tests two instances of classes that can be equal and that are not "related". The two classes are not subclasses777 * of each other and do not share a parent aside from Object.778 * See http://issues.apache.org/bugzilla/show_bug.cgi?id=33069779 */780 @Test781 public void testUnrelatedClasses() {782 Object[] x = new Object[]{ new EqualsBuilderTest.TestACanEqualB(1) };783 Object[] y = new Object[]{ new EqualsBuilderTest.TestBCanEqualA(1) };784 // sanity checks:785 Assert.assertTrue(Arrays.equals(x, x));786 Assert.assertTrue(Arrays.equals(y, y));787 Assert.assertTrue(Arrays.equals(x, y));788 Assert.assertTrue(Arrays.equals(y, x));789 // real tests:790 Assert.assertTrue(x[0].equals(x[0]));791 Assert.assertTrue(y[0].equals(y[0]));792 Assert.assertTrue(x[0].equals(y[0]));793 Assert.assertTrue(y[0].equals(x[0]));794 Assert.assertTrue(new EqualsBuilder().append(x, x).isEquals());795 Assert.assertTrue(new EqualsBuilder().append(y, y).isEquals());796 Assert.assertTrue(new EqualsBuilder().append(x, y).isEquals());797 Assert.assertTrue(new EqualsBuilder().append(y, x).isEquals());798 }799 /**800 * Test from http://issues.apache.org/bugzilla/show_bug.cgi?id=33067801 */802 @Test803 public void testNpeForNullElement() {804 Object[] x1 = new Object[]{ new Integer(1), null, new Integer(3) };805 Object[] x2 = new Object[]{ new Integer(1), new Integer(2), new Integer(3) };806 // causes an NPE in 2.0 according to:807 // http://issues.apache.org/bugzilla/show_bug.cgi?id=33067808 new EqualsBuilder().append(x1, x2);809 }810 @Test811 public void testReflectionEqualsExcludeFields() throws Exception {812 EqualsBuilderTest.TestObjectWithMultipleFields x1 = new EqualsBuilderTest.TestObjectWithMultipleFields(1, 2, 3);813 EqualsBuilderTest.TestObjectWithMultipleFields x2 = new EqualsBuilderTest.TestObjectWithMultipleFields(1, 3, 4);814 // not equal when including all fields815 Assert.assertTrue((!(EqualsBuilder.reflectionEquals(x1, x2))));816 // doesn't barf on null, empty array, or non-existent field, but still tests as not equal817 Assert.assertTrue((!(EqualsBuilder.reflectionEquals(x1, x2, ((String[]) (null))))));818 Assert.assertTrue((!(EqualsBuilder.reflectionEquals(x1, x2, new String[]{ }))));819 Assert.assertTrue((!(EqualsBuilder.reflectionEquals(x1, x2, new String[]{ "xxx" }))));820 // not equal if only one of the differing fields excluded821 Assert.assertTrue((!(EqualsBuilder.reflectionEquals(x1, x2, new String[]{ "two" }))));822 Assert.assertTrue((!(EqualsBuilder.reflectionEquals(x1, x2, new String[]{ "three" }))));823 // equal if both differing fields excluded824 Assert.assertTrue(EqualsBuilder.reflectionEquals(x1, x2, new String[]{ "two", "three" }));825 // still equal as long as both differing fields are among excluded826 Assert.assertTrue(EqualsBuilder.reflectionEquals(x1, x2, new String[]{ "one", "two", "three" }));827 Assert.assertTrue(EqualsBuilder.reflectionEquals(x1, x2, new String[]{ "one", "two", "three", "xxx" }));828 }829 @SuppressWarnings("unused")830 static class TestObjectWithMultipleFields {831 private EqualsBuilderTest.TestObject one;832 private EqualsBuilderTest.TestObject two;833 private EqualsBuilderTest.TestObject three;834 public TestObjectWithMultipleFields(int one, int two, int three) {835 this.one = new EqualsBuilderTest.TestObject(one);836 this.two = new EqualsBuilderTest.TestObject(two);837 this.three = new EqualsBuilderTest.TestObject(three);838 }839 }840}...
EqualsBuilderTest
Using AI Code Generation
1[INFO] [INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile) @ mockito-core ---2[INFO] [INFO] --- maven-surefire-plugin:2.22.1:test (default-test) @ mockito-core ---3[INFO] [INFO] --- maven-jar-plugin:3.1.0:jar (default-jar) @ mockito-core ---4[INFO] [INFO] --- maven-source-plugin:3.0.1:jar-no-fork (attach-sources) @ mockito-core ---5[INFO] [INFO] --- maven-javadoc-plugin:3.0.1:jar (attach-javadocs) @ mockito-core ---6[INFO] [INFO] --- maven-install-plugin:2.5.2:install (default-install) @ mockito-core ---
EqualsBuilderTest
Using AI Code Generation
1package org.mockito.internal.matchers.apachecommons;2import static org.junit.Assert.*;3import org.junit.Test;4import org.mockito.internal.matchers.apachecommons.EqualsBuilder;5public class EqualsBuilderTest {6 public void testReflectionEquals() {7 EqualsBuilder equalsBuilder = new EqualsBuilder();8 boolean result = equalsBuilder.reflectionEquals(null, null);9 assertEquals(true, result);10 }11}
EqualsBuilderTest
Using AI Code Generation
1public class EqualsBuilderTest {2 private EqualsBuilder equalsBuilder;3 public void setUp() {4 equalsBuilder = new EqualsBuilder();5 }6 public void testAppendSuperTrue() {7 equalsBuilder.appendSuper(true);8 assertTrue(equalsBuilder.isEquals());9 }10 public void testAppendSuperFalse() {11 equalsBuilder.appendSuper(false);12 assertFalse(equalsBuilder.isEquals());13 }14 public void testAppendTrue() {15 equalsBuilder.append(true, true);16 assertTrue(equalsBuilder.isEquals());17 }18 public void testAppendFalse() {19 equalsBuilder.append(true, false);20 assertFalse(equalsBuilder.isEquals());21 }22 public void testAppendWithNull() {23 equalsBuilder.append(null, null);24 assertTrue(equalsBuilder.isEquals());25 }26 public void testAppendWithEqualObjects() {27 equalsBuilder.append("a", "a");28 assertTrue(equalsBuilder.isEquals());29 }30 public void testAppendWithDifferentObjects() {31 equalsBuilder.append("a", "b");32 assertFalse(equalsBuilder.isEquals());33 }34 public void testAppendWithEqualArrays() {35 equalsBuilder.append(new int[]{1, 2}, new int[]{1, 2});36 assertTrue(equalsBuilder.isEquals());37 }38 public void testAppendWithDifferentArrays() {39 equalsBuilder.append(new int[]{1, 2}, new int[]{3, 4});40 assertFalse(equalsBuilder.isEquals());41 }42 public void testAppendWithEqualObjectsInArrays() {43 equalsBuilder.append(new Object[]{"a", "b"}, new Object[]{"a", "b"});44 assertTrue(equalsBuilder.isEquals());45 }46 public void testAppendWithDifferentObjectsInArrays() {47 equalsBuilder.append(new Object[]{"a", "b
EqualsBuilderTest
Using AI Code Generation
1[ERROR] import org.apache.commons.lang3.builder.EqualsBuilder;2[ERROR] import org.apache.commons.lang3.builder.HashCodeBuilder;3[ERROR] import org.apache.commons.lang3.builder.ToStringBuilder;4[ERROR] import org.apache.commons.lang3.builder.ToStringStyle;5[ERROR] import org.apache.commons.lang3.builder.ToStringStyle;6[ERROR] import org.apache.commons.lang3.builder.ToStringStyle;7[ERROR] import org.apache.commons.lang3.builder.ToStringStyle;8[ERROR] import org.apache.commons.lang3.builder.ToStringStyle;
EqualsBuilderTest
Using AI Code Generation
1import org.apache.commons.lang3.builder.EqualsBuilder;2import org.apache.commons.lang3.builder.HashCodeBuilder;3import org.apache.commons.lang3.builder.ToStringBuilder;4import org.apache.commons.lang3.builder.ToStringStyle;5import org.junit.Test;6import static org.junit.Assert.*;7public class EqualsBuilderTest {8 public void testEquals() {9 EqualsBuilderTest obj1 = new EqualsBuilderTest();10 EqualsBuilderTest obj2 = new EqualsBuilderTest();11 obj1.setAge(18);12 obj1.setName("Tom");13 obj2.setAge(18);14 obj2.setName("Tom");15 assertTrue(obj1.equals(obj2));16 }17 private int age;18 private String name;19 public int getAge() {20 return age;21 }22 public void setAge(int age) {23 this.age = age;24 }25 public String getName() {26 return name;27 }28 public void setName(String name) {29 this.name = name;30 }31 public boolean equals(Object obj) {32 if (obj == null) {33 return false;34 }35 if (obj == this) {36 return true;37 }38 if (obj.getClass() != getClass()) {39 return false;40 }41 EqualsBuilderTest rhs = (EqualsBuilderTest) obj;42 return new EqualsBuilder()43 .appendSuper(super.equals(obj))44 .append(this.age, rhs.age)45 .append(this.name, rhs.name)46 .isEquals();47 }48 public int hashCode() {49 return new HashCodeBuilder()50 .append(age)51 .append(name)52 .toHashCode();53 }54 public String toString() {55 return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)56 .append("age", age)57 .append("name", name)58 .toString();59 }60}61import org.apache.commons.lang3.builder.EqualsBuilder;62import org.apache.commons.lang3.builder.HashCodeBuilder;63import org.apache.commons.lang3.builder.ToStringBuilder;64import org.apache.commons.lang3.builder.ToStringStyle;65import org.junit.Test;66import static org.junit.Assert.*;67public class EqualsBuilderTest {
EqualsBuilderTest
Using AI Code Generation
1import org.mockito.internal.matchers.apachecommons.EqualsBuilderTest;2import org.testng.annotations.Test;3public class EqualsBuilderTestTest {4public void testEquals() {5EqualsBuilderTest equalsBuilderTest = new EqualsBuilderTest();6equalsBuilderTest.testEquals();7}8}9C:\Users\user\workspace\Mockito>java -cp "C:\Users\user\workspace\Mockito\bin;C:\Users\user\workspace\Mockito\libs\*" org.testng.TestNG testng.xml
EqualsBuilderTest
Using AI Code Generation
1import org.mockito.internal.matchers.apachecommons.EqualsBuilderTest;2import org.mockito.internal.matchers.apachecommons.EqualsBuilderTest.*;3class EqualsBuilderTest {4 def 'equals should return true for two equal objects'() {5 def a = new EqualsBuilderTest()6 def b = new EqualsBuilderTest()7 a.equals(b)8 }9 def 'equals should return false for two unequal objects'() {10 def a = new EqualsBuilderTest()11 def b = new EqualsBuilderTest()12 !a.equals(b)13 }14 def 'equals should return false for two unequal objects with different types'() {15 def a = new EqualsBuilderTest()16 def b = new Object()17 !a.equals(b)18 }19 def 'equals should return false for two unequal objects with different types'() {20 def a = new EqualsBuilderTest()21 def b = new Object()22 !a.equals(b)23 }24 def 'equals should return false for two unequal objects with different types'() {25 def a = new EqualsBuilderTest()26 def b = new Object()27 !a.equals(b)28 }29 def 'equals should return false for two unequal objects with different types'() {30 def a = new EqualsBuilderTest()31 def b = new Object()32 !a.equals(b)33 }34 def 'equals should return false for two unequal objects with different types'() {35 def a = new EqualsBuilderTest()36 def b = new Object()37 !a.equals(b)38 }39 def 'equals should return false for two unequal objects with different types'() {40 def a = new EqualsBuilderTest()41 def b = new Object()42 !a.equals(b)43 }44 def 'equals should return false for two unequal objects with different types'() {45 def a = new EqualsBuilderTest()46 def b = new Object()47 !a.equals(b)48 }49 def 'equals should return false for two unequal objects with different types'() {50 def a = new EqualsBuilderTest()51 def b = new Object()
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!