1 4 package com.tc.test; 5 6 import junit.framework.Assert; 7 8 13 public class EqualityChecker { 14 15 public static void checkArraysForEquality(Object [] env1, Object [] env2) { 16 checkArraysForEquality(env1, env2, true); 17 } 18 19 public static void checkArraysForEquality(Object [] env1, Object [] env2, boolean checkHashCode) { 20 if (env1 == null && env2 == null) { return; } 21 for (int i = 0; i < env1.length; ++i) { 22 for (int j = 0; j < env2.length; ++j) { 23 if (i == j) { 24 Assert.assertEquals(env1[i], env2[j]); 25 if (checkHashCode) Assert.assertEquals(env1[i].hashCode(), env2[j].hashCode()); 26 27 Assert.assertEquals(env1[i], env1[i]); 28 if (checkHashCode) Assert.assertEquals(env1[i].hashCode(), env1[j].hashCode()); 29 30 Assert.assertEquals(env2[i], env2[i]); 31 if (checkHashCode) Assert.assertEquals(env2[i].hashCode(), env2[j].hashCode()); 32 } else { 33 Assert.assertFalse("Object in array #1 at position " + i 34 + " is equal to the object in the same array at position " + j, env1[i].equals(env1[j])); 35 Assert 36 .assertFalse("Object in array #1 at position " + i + " is equal to object in array #2 at position " + j, 37 env1[i].equals(env2[j])); 38 Assert.assertFalse("Object in array #2 at position " + i 39 + " is equal to the object in the same array at position " + j, env2[i].equals(env2[j])); 40 } 41 } 42 } 43 } 44 45 } | Popular Tags |