How to use DualKey method of org.assertj.core.internal.DeepDifference class

Best Assertj code snippet using org.assertj.core.internal.DeepDifference.DualKey

Source:DeepDifference.java Github

copy

Full Screen

...48public class DeepDifference {49 private static final String MISSING_FIELDS = "%s can't be compared to %s as %s does not declare all %s fields, it lacks these:%s";50 private static final Map<Class<?>, Boolean> customEquals = new ConcurrentHashMap<>();51 private static final Map<Class<?>, Boolean> customHash = new ConcurrentHashMap<>();52 private final static class DualKey {53 private final List<String> path;54 private final Object key1;55 private final Object key2;56 private DualKey(List<String> path, Object key1, Object key2) {57 this.path = path;58 this.key1 = key1;59 this.key2 = key2;60 }61 @Override62 public boolean equals(Object other) {63 if (!(other instanceof DualKey)) {64 return false;65 }66 DualKey that = (DualKey) other;67 return key1 == that.key1 && key2 == that.key2;68 }69 @Override70 public int hashCode() {71 int h1 = key1 != null ? key1.hashCode() : 0;72 int h2 = key2 != null ? key2.hashCode() : 0;73 return h1 + h2;74 }75 @Override76 public String toString() {77 return "DualKey [key1=" + key1 + ", key2=" + key2 + "]";78 }79 public List<String> getPath() {80 return path;81 }82 public String getConcatenatedPath() {83 return join(path).with(".");84 }85 }86 public static class Difference {87 List<String> path;88 Object actual;89 Object other;90 Optional<String> description;91 public Difference(List<String> path, Object actual, Object other) {92 this(path, actual, other, null);93 }94 public Difference(List<String> path, Object actual, Object other, String description) {95 this.path = path;96 this.actual = actual;97 this.other = other;98 this.description = Optional.ofNullable(description);99 }100 public List<String> getPath() {101 return path;102 }103 public Object getActual() {104 return actual;105 }106 public Object getOther() {107 return other;108 }109 public Optional<String> getDescription() {110 return description;111 }112 @Override113 public String toString() {114 return description.isPresent()115 ? format("Difference [path=%s, actual=%s, other=%s, description=%s]", path, actual, other, description.get())116 : format("Difference [path=%s, actual=%s, other=%s]", path, actual, other);117 }118 }119 /**120 * Compare two objects for differences by doing a 'deep' comparison. This will traverse the121 * Object graph and perform either a field-by-field comparison on each122 * object (if not .equals() method has been overridden from Object), or it123 * will call the customized .equals() method if it exists.124 * <p>125 *126 * This method handles cycles correctly, for example A-&gt;B-&gt;C-&gt;A.127 * Suppose a and a' are two separate instances of the A with the same values128 * for all fields on A, B, and C. Then a.deepEquals(a') will return an empty list. It129 * uses cycle detection storing visited objects in a Set to prevent endless130 * loops.131 *132 * @param a Object one to compare133 * @param b Object two to compare134 * @param comparatorByPropertyOrField comparators to compare properties or fields with the given names135 * @param comparatorByType comparators to compare properties or fields with the given types136 * @return the list of differences found or an empty list if objects are equivalent.137 * Equivalent means that all field values of both subgraphs are the same,138 * either at the field level or via the respectively encountered overridden139 * .equals() methods during traversal.140 */141 public static List<Difference> determineDifferences(Object a, Object b,142 Map<String, Comparator<?>> comparatorByPropertyOrField,143 TypeComparators comparatorByType) {144 // replace null comparators groups by empty one to simplify code afterwards145 comparatorByPropertyOrField = comparatorByPropertyOrField == null146 ? new TreeMap<>()147 : comparatorByPropertyOrField;148 comparatorByType = comparatorByType == null ? defaultTypeComparators() : comparatorByType;149 return determineDifferences(a, b, null, comparatorByPropertyOrField, comparatorByType);150 }151 private static List<Difference> determineDifferences(Object a, Object b, List<String> parentPath,152 Map<String, Comparator<?>> comparatorByPropertyOrField,153 TypeComparators comparatorByType) {154 final Set<DualKey> visited = new HashSet<>();155 final Deque<DualKey> toCompare = initStack(a, b, parentPath, comparatorByPropertyOrField, comparatorByType);156 final List<Difference> differences = new ArrayList<>();157 while (!toCompare.isEmpty()) {158 final DualKey dualKey = toCompare.removeFirst();159 visited.add(dualKey);160 final List<String> currentPath = dualKey.getPath();161 final Object key1 = dualKey.key1;162 final Object key2 = dualKey.key2;163 if (key1 == key2) {164 continue;165 }166 if (hasCustomComparator(dualKey, comparatorByPropertyOrField, comparatorByType)) {167 if (propertyOrFieldValuesAreEqual(key1, key2, dualKey.getConcatenatedPath(),168 comparatorByPropertyOrField, comparatorByType))169 continue;170 }171 if (key1 == null || key2 == null) {172 differences.add(new Difference(currentPath, key1, key2));173 continue;174 }175 if (key1 instanceof Collection) {176 if (!(key2 instanceof Collection)) {177 differences.add(new Difference(currentPath, key1, key2));178 continue;179 }180 } else if (key2 instanceof Collection) {181 differences.add(new Difference(currentPath, key1, key2));182 continue;183 }184 if (key1 instanceof SortedSet) {185 if (!(key2 instanceof SortedSet)) {186 differences.add(new Difference(currentPath, key1, key2));187 continue;188 }189 } else if (key2 instanceof SortedSet) {190 differences.add(new Difference(currentPath, key1, key2));191 continue;192 }193 if (key1 instanceof SortedMap) {194 if (!(key2 instanceof SortedMap)) {195 differences.add(new Difference(currentPath, key1, key2));196 continue;197 }198 } else if (key2 instanceof SortedMap) {199 differences.add(new Difference(currentPath, key1, key2));200 continue;201 }202 if (key1 instanceof Map) {203 if (!(key2 instanceof Map)) {204 differences.add(new Difference(currentPath, key1, key2));205 continue;206 }207 } else if (key2 instanceof Map) {208 differences.add(new Difference(currentPath, key1, key2));209 continue;210 }211 // Handle all [] types. In order to be equal, the arrays must be the212 // same length, be of the same type, be in the same order, and all213 // elements within the array must be deeply equivalent.214 if (key1.getClass().isArray()) {215 if (!compareArrays(key1, key2, currentPath, toCompare, visited)) {216 differences.add(new Difference(currentPath, key1, key2));217 continue;218 }219 continue;220 }221 // Special handle SortedSets because they are fast to compare222 // because their elements must be in the same order to be equivalent Sets.223 if (key1 instanceof SortedSet) {224 if (!compareOrderedCollection((Collection<?>) key1, (Collection<?>) key2, currentPath, toCompare, visited)) {225 differences.add(new Difference(currentPath, key1, key2));226 continue;227 }228 continue;229 }230 // Check List, as element order matters this comparison is faster than using unordered comparison.231 if (key1 instanceof List) {232 if (!compareOrderedCollection((Collection<?>) key1, (Collection<?>) key2, currentPath, toCompare, visited)) {233 differences.add(new Difference(currentPath, key1, key2));234 continue;235 }236 continue;237 }238 // Handle unordered Collection.239 if (key1 instanceof Collection) {240 if (!compareUnorderedCollection((Collection<?>) key1, (Collection<?>) key2, currentPath, toCompare,241 visited, comparatorByPropertyOrField, comparatorByType)) {242 differences.add(new Difference(currentPath, key1, key2));243 continue;244 }245 continue;246 }247 // Compare two SortedMaps. This takes advantage of the fact that these248 // Maps can be compared in O(N) time due to their ordering.249 if (key1 instanceof SortedMap) {250 if (!compareSortedMap((SortedMap<?, ?>) key1, (SortedMap<?, ?>) key2, currentPath, toCompare, visited)) {251 differences.add(new Difference(currentPath, key1, key2));252 continue;253 }254 continue;255 }256 // Compare two Unordered Maps. This is a slightly more expensive comparison because257 // order cannot be assumed, therefore a temporary Map must be created, however the258 // comparison still runs in O(N) time.259 if (key1 instanceof Map) {260 if (!compareUnorderedMap((Map<?, ?>) key1, (Map<?, ?>) key2, currentPath, toCompare, visited)) {261 differences.add(new Difference(currentPath, key1, key2));262 continue;263 }264 continue;265 }266 if (hasCustomEquals(key1.getClass())) {267 if (!key1.equals(key2)) {268 differences.add(new Difference(currentPath, key1, key2));269 continue;270 }271 continue;272 }273 Set<String> key1FieldsNames = getFieldsNames(getDeclaredFieldsIncludingInherited(key1.getClass()));274 Set<String> key2FieldsNames = getFieldsNames(getDeclaredFieldsIncludingInherited(key2.getClass()));275 if (!key2FieldsNames.containsAll(key1FieldsNames)) {276 Set<String> key1FieldsNamesNotInKey2 = newHashSet(key1FieldsNames);277 key1FieldsNamesNotInKey2.removeAll(key2FieldsNames);278 String missingFields = key1FieldsNamesNotInKey2.toString();279 String key2ClassName = key2.getClass().getName();280 String key1ClassName = key1.getClass().getName();281 String missingFieldsDescription = format(MISSING_FIELDS, key1ClassName, key2ClassName, key2.getClass().getSimpleName(),282 key1.getClass().getSimpleName(), missingFields);283 differences.add(new Difference(currentPath, key1, key2, missingFieldsDescription));284 } else {285 for (String fieldName : key1FieldsNames) {286 List<String> path = new ArrayList<>(currentPath);287 path.add(fieldName);288 DualKey dk = new DualKey(path,289 COMPARISON.getSimpleValue(fieldName, key1),290 COMPARISON.getSimpleValue(fieldName, key2));291 if (!visited.contains(dk)) {292 toCompare.addFirst(dk);293 }294 }295 }296 }297 return differences;298 }299 private static boolean hasCustomComparator(DualKey dualKey, Map<String, Comparator<?>> comparatorByPropertyOrField,300 TypeComparators comparatorByType) {301 String fieldName = dualKey.getConcatenatedPath();302 if (comparatorByPropertyOrField.containsKey(fieldName)) return true;303 // we know that dualKey.key1 != dualKey.key2 at this point, so one the key is not null304 Class<?> keyType = dualKey.key1 != null ? dualKey.key1.getClass() : dualKey.key2.getClass();305 return comparatorByType.getComparatorForType(keyType) != null;306 }307 private static Deque<DualKey> initStack(Object a, Object b, List<String> parentPath,308 Map<String, Comparator<?>> comparatorByPropertyOrField,309 TypeComparators comparatorByType) {310 Deque<DualKey> stack = new LinkedList<>();311 boolean isRootObject = parentPath == null;312 List<String> currentPath = isRootObject ? new ArrayList<>() : parentPath;313 DualKey basicDualKey = new DualKey(currentPath, a, b);314 if (a != null && b != null && !isContainerType(a) && !isContainerType(b)315 && (isRootObject || !hasCustomComparator(basicDualKey, comparatorByPropertyOrField, comparatorByType))) {316 // disregard the equals method and start comparing fields317 Set<String> aFieldsNames = getFieldsNames(getDeclaredFieldsIncludingInherited(a.getClass()));318 if (!aFieldsNames.isEmpty()) {319 Set<String> bFieldsNames = getFieldsNames(getDeclaredFieldsIncludingInherited(b.getClass()));320 if (!bFieldsNames.containsAll(aFieldsNames)) {321 stack.addFirst(basicDualKey);322 } else {323 for (String fieldName : aFieldsNames) {324 List<String> fieldPath = new ArrayList<>(currentPath);325 fieldPath.add(fieldName);326 DualKey dk = new DualKey(fieldPath,327 COMPARISON.getSimpleValue(fieldName, a),328 COMPARISON.getSimpleValue(fieldName, b));329 stack.addFirst(dk);330 }331 }332 } else {333 stack.addFirst(basicDualKey);334 }335 } else {336 stack.addFirst(basicDualKey);337 }338 return stack;339 }340 private static Set<String> getFieldsNames(Collection<Field> fields) {341 Set<String> fieldNames = new LinkedHashSet<>();342 for (Field field : fields) {343 fieldNames.add(field.getName());344 }345 return fieldNames;346 }347 private static boolean isContainerType(Object o) {348 return o instanceof Collection || o instanceof Map;349 }350 /**351 * Deeply compare to Arrays []. Both arrays must be of the same type, same352 * length, and all elements within the arrays must be deeply equal in order353 * to return true.354 *355 * @param array1 [] type (Object[], String[], etc.)356 * @param array2 [] type (Object[], String[], etc.)357 * @param path the path to the arrays to compare358 * @param toCompare add items to compare to the Stack (Stack versus recursion)359 * @param visited Set of objects already compared (prevents cycles)360 * @return true if the two arrays are the same length and contain deeply361 * equivalent items.362 */363 private static boolean compareArrays(Object array1, Object array2, List<String> path, Deque<DualKey> toCompare,364 Set<DualKey> visited) {365 int len = Array.getLength(array1);366 if (len != Array.getLength(array2)) {367 return false;368 }369 for (int i = 0; i < len; i++) {370 DualKey dk = new DualKey(path, Array.get(array1, i), Array.get(array2, i));371 if (!visited.contains(dk)) {372 toCompare.addFirst(dk);373 }374 }375 return true;376 }377 /**378 * Deeply compare two Collections that must be same length and in same379 * order.380 *381 * @param <K> the key type382 * @param <V> the value type383 * @param col1 First collection of items to compare384 * @param col2 Second collection of items to compare385 * @param path The path to the collections386 * @param toCompare add items to compare to the Stack (Stack versus recursion)387 * @param visited388 * Set of objects already compared (prevents cycles) value of389 * 'true' indicates that the Collections may be equal, and the390 * sets items will be added to the Stack for further comparison.391 *392 * @return boolean false if the Collections are for certain not equals393 */394 private static <K, V> boolean compareOrderedCollection(Collection<K> col1, Collection<V> col2,395 List<String> path, Deque<DualKey> toCompare,396 Set<DualKey> visited) {397 if (col1.size() != col2.size()) return false;398 Iterator<V> i2 = col2.iterator();399 for (K k : col1) {400 DualKey dk = new DualKey(path, k, i2.next());401 if (!visited.contains(dk)) toCompare.addFirst(dk);402 }403 return true;404 }405 /**406 * It places one collection into a temporary Map by deepHashCode(), so that it407 * can walk the other collection and look for each item in the map, which408 * runs in O(N) time, rather than an O(N^2) lookup that would occur if each409 * item from collection one was scanned for in collection two.410 *411 * @param <K> the key type412 * @param <V> the value type413 * @param col1 First collection of items to compare414 * @param col2 Second collection of items to compare415 * @param path the path to the collections to compare416 * @param toCompare add items to compare to the Stack (Stack versus recursion)417 * @param visited Set containing items that have already been compared, so as to418 * prevent cycles.419 * @return boolean false if the Collections are for certain not equals. A420 * value of 'true' indicates that the Collections may be equal, and421 * the sets items will be added to the Stack for further comparison.422 */423 private static <K, V> boolean compareUnorderedCollectionByHashCodes(Collection<K> col1, Collection<V> col2,424 List<String> path, Deque<DualKey> toCompare,425 Set<DualKey> visited) {426 Map<Integer, Object> fastLookup = new HashMap<>();427 for (Object o : col2) {428 fastLookup.put(deepHashCode(o), o);429 }430 for (Object o : col1) {431 Object other = fastLookup.get(deepHashCode(o));432 if (other == null) {433 // Item not even found in other Collection, no need to continue.434 return false;435 }436 DualKey dk = new DualKey(path, o, other);437 if (!visited.contains(dk)) {438 toCompare.addFirst(dk);439 }440 }441 return true;442 }443 // Deeply compares two collections referenced by dualKey. This method attempts444 // to quickly determine inequality by length, then if lengths match, in case of445 // collection type is Set and there are passed no custom comparators, there is used446 // comparison on hashcodes basis, otherwise each element from one collection is checked447 // for existence in another one using 'deep' comparison.448 private static <K, V> boolean compareUnorderedCollection(Collection<K> col1, Collection<V> col2,449 List<String> path, Deque<DualKey> toCompare,450 Set<DualKey> visited,451 Map<String, Comparator<?>> comparatorByPropertyOrField,452 TypeComparators comparatorByType) {453 if (col1.size() != col2.size()) return false;454 boolean noCustomComparators = comparatorByPropertyOrField.isEmpty() && comparatorByType.isEmpty();455 if (noCustomComparators && col1 instanceof Set) {456 // this comparison is used for performance optimization reasons457 return compareUnorderedCollectionByHashCodes(col1, col2, path, toCompare, visited);458 }459 Collection<V> col2Copy = new LinkedList<>(col2);460 for (Object o1 : col1) {461 Iterator<V> iterator = col2Copy.iterator();462 while (iterator.hasNext()) {463 Object o2 = iterator.next();464 if (determineDifferences(o1, o2, path, comparatorByPropertyOrField, comparatorByType).isEmpty()) {465 iterator.remove();466 break;467 }468 }469 }470 return col2Copy.isEmpty();471 }472 /**473 * Deeply compare two SortedMap instances. This method walks the Maps in474 * order, taking advantage of the fact that the Maps are SortedMaps.475 *476 * @param <K1> the first key type477 * @param <V1> the first value type478 * @param <K2> the second key type479 * @param <V2> the second value type480 * @param map1 SortedMap one481 * @param map2 SortedMap two482 * @param path the path to the maps to compare483 * @param toCompare add items to compare to the Stack (Stack versus recursion)484 * @param visited Set containing items that have already been compared, to485 * prevent cycles.486 * @return false if the Maps are for certain not equals. 'true' indicates487 * that 'on the surface' the maps are equal, however, it will place488 * the contents of the Maps on the stack for further comparisons.489 */490 private static <K1, V1, K2, V2> boolean compareSortedMap(SortedMap<K1, V1> map1, SortedMap<K2, V2> map2,491 List<String> path, Deque<DualKey> toCompare,492 Set<DualKey> visited) {493 if (map1.size() != map2.size()) {494 return false;495 }496 Iterator<Map.Entry<K2, V2>> i2 = map2.entrySet().iterator();497 for (Map.Entry<K1, V1> entry1 : map1.entrySet()) {498 Map.Entry<K2, V2> entry2 = i2.next();499 // Must split the Key and Value so that Map.Entry's equals() method is not used.500 DualKey dk = new DualKey(path, entry1.getKey(), entry2.getKey());501 if (!visited.contains(dk)) {502 toCompare.addFirst(dk);503 }504 dk = new DualKey(path, entry1.getValue(), entry2.getValue());505 if (!visited.contains(dk)) {506 toCompare.addFirst(dk);507 }508 }509 return true;510 }511 /**512 * Deeply compare two Map instances. After quick short-circuit tests, this513 * method uses a temporary Map so that this method can run in O(N) time.514 *515 * @param <K1> the first key type516 * @param <V1> the first value type517 * @param <K2> the second key type518 * @param <V2> the second value type519 * @param map1 Map one520 * @param map2 Map two521 * @param path the path to the maps to compare522 * @param toCompare add items to compare to the Stack (Stack versus recursion)523 * @param visited Set containing items that have already been compared, to524 * prevent cycles.525 * @return false if the Maps are for certain not equals. 'true' indicates526 * that 'on the surface' the maps are equal, however, it will place527 * the contents of the Maps on the stack for further comparisons.528 */529 private static <K1, V1, K2, V2> boolean compareUnorderedMap(Map<K1, V1> map1, Map<K2, V2> map2,530 List<String> path, Deque<DualKey> toCompare,531 Set<DualKey> visited) {532 if (map1.size() != map2.size()) {533 return false;534 }535 Map<Integer, Map.Entry<K2, V2>> fastLookup = new HashMap<>();536 for (Map.Entry<K2, V2> entry : map2.entrySet()) {537 fastLookup.put(deepHashCode(entry.getKey()), entry);538 }539 for (Map.Entry<K1, V1> entry : map1.entrySet()) {540 Map.Entry<K2, V2> other = fastLookup.get(deepHashCode(entry.getKey()));541 if (other == null) {542 return false;543 }544 DualKey dk = new DualKey(path, entry.getKey(), other.getKey());545 if (!visited.contains(dk)) {546 toCompare.addFirst(dk);547 }548 dk = new DualKey(path, entry.getValue(), other.getValue());549 if (!visited.contains(dk)) {550 toCompare.addFirst(dk);551 }552 }553 return true;554 }555 /**556 * Determine if the passed in class has a non-Object.equals() method. This557 * method caches its results in static ConcurrentHashMap to benefit558 * execution performance.559 *560 * @param c Class to check.561 * @return true, if the passed in Class has a .equals() method somewhere562 * between itself and just below Object in it's inheritance....

Full Screen

Full Screen

Source:DualKey.java Github

copy

Full Screen

2import static org.assertj.core.util.Strings.join;3import java.util.List;4/*5 * Similarly to the Difference class, the DeepDifference class method determineDifferences,6 * will return a list of all the determined differences between fields. DualKey is a crucial 7 * component, as it will utilise the two key objects (key1 and key2), to determine the difference between the different fields.8 * */9public final class DualKey {10 final List<String> path;11 final Object key1;12 final Object key2;13 DualKey(List<String> path, Object key1, Object key2) {14 this.path = path;15 this.key1 = key1;16 this.key2 = key2;17 }18 @Override19 public boolean equals(Object other) {20 if (!(other instanceof DualKey)) {21 return false;22 }23 DualKey that = (DualKey) other;24 return key1 == that.key1 && key2 == that.key2;25 }26 @Override27 public int hashCode() {28 int h1 = key1 != null ? key1.hashCode() : 0;29 int h2 = key2 != null ? key2.hashCode() : 0;30 return h1 + h2;31 }32 @Override33 public String toString() {34 return "DualKey [key1=" + key1 + ", key2=" + key2 + "]";35 }36 public List<String> getPath() {37 return path;38 }39 public String getConcatenatedPath() {40 return join(path).with(".");41 }42 43 44}...

Full Screen

Full Screen

DualKey

Using AI Code Generation

copy

Full Screen

1public class DualKeyTest {2 public static void main(String[] args) {3 DualKey dualKey = new DualKey("a", "b");4 System.out.println("dualKey = " + dualKey);5 }6}7public class DualKeyTest {8 public static void main(String[] args) {9 DualKey dualKey = new DualKey("a", "b");10 System.out.println("dualKey = " + dualKey);11 }12}13public class DualKeyTest {14 public static void main(String[] args) {15 DualKey dualKey = new DualKey("a", "b");16 System.out.println("dualKey = " + dualKey);17 }18}19public class DualKeyTest {20 public static void main(String[] args) {21 DualKey dualKey = new DualKey("a", "b");22 System.out.println("dualKey = " + dualKey);23 }24}25public class DualKeyTest {26 public static void main(String[] args) {27 DualKey dualKey = new DualKey("a", "b");28 System.out.println("dualKey = " + dualKey);29 }30}31public class DualKeyTest {32 public static void main(String[] args) {33 DualKey dualKey = new DualKey("a", "b");34 System.out.println("dualKey = " + dualKey);35 }36}37public class DualKeyTest {38 public static void main(String[] args) {39 DualKey dualKey = new DualKey("a", "b");40 System.out.println("dualKey = " + dualKey);41 }42}

Full Screen

Full Screen

DualKey

Using AI Code Generation

copy

Full Screen

1import static org.assertj.core.api.Assertions.assertThat;2import static org.assertj.core.internal.DeepDifference.DualKey;3import org.assertj.core.internal.DeepDifference;4public class Test {5 public static void main(String[] args) {6 DeepDifference deepDifference = new DeepDifference();7 DualKey dualKey = deepDifference.dualKey("hello", "world");8 System.out.println(dualKey);9 }10}11import static org.assertj.core.api.Assertions.assertThat;12import static org.assertj.core.internal.DeepDifference.DualKey;13import org.assertj.core.internal.DeepDifference;14public class Test {15 public static void main(String[] args) {16 DeepDifference deepDifference = new DeepDifference();17 DualKey dualKey = deepDifference.dualKey("hello", "hello");18 System.out.println(dualKey);19 }20}21import static org.assertj.core.api.Assertions.assertThat;22import static org.assertj.core.internal.DeepDifference.DualKey;23import org.assertj.core.internal.DeepDifference;24public class Test {25 public static void main(String[] args) {26 DeepDifference deepDifference = new DeepDifference();27 DualKey dualKey = deepDifference.dualKey("hello", "world");28 System.out.println(dualKey);29 System.out.println(dualKey.key1);30 System.out.println(dualKey.key2);31 }32}33import static org.assertj.core.api.Assertions.assertThat;34import static org.assertj.core.internal.DeepDifference.DualKey;35import org.assertj.core.internal.DeepDifference;36public class Test {37 public static void main(String[] args) {38 DeepDifference deepDifference = new DeepDifference();39 DualKey dualKey = deepDifference.dualKey("hello", "hello");40 System.out.println(dualKey);41 System.out.println(dualKey.key1);42 System.out.println(dualKey

Full Screen

Full Screen

DualKey

Using AI Code Generation

copy

Full Screen

1DeepDifference deepDifference = new DeepDifference();2Map<String, Difference> dualKeyDifference = deepDifference.dualKeyDifference(actual, expected);3DeepDifference deepDifference = new DeepDifference();4Map<String, Difference> dualKeyDifference = deepDifference.dualKeyDifference(actual, expected, new DualKeyDiff());5DeepDifference deepDifference = new DeepDifference();6Map<String, Difference> dualKeyDifference = deepDifference.dualKeyDifference(actual, expected, new DualKeyDiff(), new DualKeyDiff());7DeepDifference deepDifference = new DeepDifference();8Map<String, Difference> dualKeyDifference = deepDifference.dualKeyDifference(actual, expected, new DualKeyDiff(), new DualKeyDiff(), new DualKeyDiff());9DeepDifference deepDifference = new DeepDifference();10Map<String, Difference> dualKeyDifference = deepDifference.dualKeyDifference(actual, expected, new DualKeyDiff(), new DualKeyDiff(), new DualKeyDiff(), new DualKeyDiff());11DeepDifference deepDifference = new DeepDifference();12Map<String, Difference> dualKeyDifference = deepDifference.dualKeyDifference(actual, expected, new DualKeyDiff(), new DualKeyDiff(), new DualKeyDiff(), new DualKeyDiff(), new DualKeyDiff());13DeepDifference deepDifference = new DeepDifference();14Map<String, Difference> dualKeyDifference = deepDifference.dualKeyDifference(actual, expected, new DualKeyDiff(), new DualKeyDiff(), new DualKeyDiff(), new DualKeyDiff(), new DualKeyDiff(), new DualKeyDiff());

Full Screen

Full Screen

DualKey

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.internal.DeepDifference;2import org.assertj.core.internal.DualKey;3public class 1 {4 public static void main(String[] args) {5 Object obj1 = new Object();6 Object obj2 = new Object();7 DeepDifference deepDifference = new DeepDifference();8 DualKey dualKey = deepDifference.dualKey(obj1, obj2);9 System.out.println(deepDifference.differences(dualKey));10 }11}12import org.assertj.core.internal.DeepDifference;13import org.assertj.core.internal.DualKey;14public class 2 {15 public static void main(String[] args) {16 Object obj1 = new Object();17 Object obj2 = new Object();18 DeepDifference deepDifference = new DeepDifference();19 DualKey dualKey = deepDifference.dualKey(obj1, obj2);20 System.out.println(deepDifference.differences(dualKey));21 }22}23import org.assertj.core.internal.DeepDifference;24import org.assertj.core.internal.DualKey;25public class 3 {26 public static void main(String[] args) {27 Object obj1 = new Object();28 Object obj2 = new Object();29 DeepDifference deepDifference = new DeepDifference();30 DualKey dualKey = deepDifference.dualKey(obj1, obj2);31 System.out.println(deepDifference.differences(dualKey));32 }33}34import org.assertj.core.internal.DeepDifference;35import org.assertj.core.internal.DualKey;36public class 4 {37 public static void main(String[] args) {38 Object obj1 = new Object();39 Object obj2 = new Object();40 DeepDifference deepDifference = new DeepDifference();41 DualKey dualKey = deepDifference.dualKey(obj1, obj2);42 System.out.println(de

Full Screen

Full Screen

DualKey

Using AI Code Generation

copy

Full Screen

1package org.assertj.core.internal;2import java.util.ArrayList;3import java.util.List;4import org.assertj.core.util.VisibleForTesting;5public class DeepDifference {6 private final List<DualKey> differences = new ArrayList<>();7 private final List<DualKey> visited = new ArrayList<>();8 public List<DualKey> difference(Object actual, Object other) {9 if (actual == other) return differences;10 if (actual == null || other == null) {11 differences.add(new DualKey(actual, other));12 return differences;13 }14 if (actual.getClass() != other.getClass()) {15 differences.add(new DualKey(actual, other));16 return differences;17 }18 if (actual instanceof Iterable) {19 deepDifferenceForIterable((Iterable<?>) actual, (Iterable<?>) other);20 } else if (actual instanceof Object[]) {21 deepDifferenceForArray((Object[]) actual, (Object[]) other);22 } else if (!actual.equals(other)) {23 differences.add(new DualKey(actual, other));24 }25 return differences;26 }27 private void deepDifferenceForIterable(Iterable<?> actual, Iterable<?> other) {28 DualKey dualKey = new DualKey(actual, other);29 if (visited.contains(dualKey)) return;30 visited.add(dualKey);31 int actualSize = sizeOf(actual);32 int otherSize = sizeOf(other);33 if (actualSize != otherSize) {34 differences.add(dualKey);35 return;36 }37 int index = 0;38 for (Object o : actual) {39 difference(o, get(other, index++));40 }41 }42 private void deepDifferenceForArray(Object[] actual, Object[] other) {43 DualKey dualKey = new DualKey(actual, other);44 if (visited.contains(dualKey)) return;45 visited.add(dualKey);46 if (actual.length != other.length) {47 differences.add(dualKey);48 return;49 }50 for (int i = 0; i < actual.length; i++) {51 difference(actual[i], other[i]);52 }53 }54 private int sizeOf(Iterable<?> iterable) {55 int size = 0;56 for (@SuppressWarnings("unused")

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful