Best Assertj code snippet using org.assertj.core.api.recursive.assertion.RecursiveAssertionDriver.evaluateAssertion
Source:RecursiveAssertionDriver.java
...56 if (nodeMustBeIgnored(node, nodeType, fieldLocation)) return;57 boolean nodeAlreadyVisited = markNodeAsVisited(node);58 if (nodeAlreadyVisited) return;59 if (!isRootObject(fieldLocation) && shouldEvaluateAssertion(nodeType)) {60 evaluateAssertion(predicate, node, fieldLocation);61 }62 recurseIntoFieldsOfCurrentNode(predicate, node, nodeType, fieldLocation);63 }64 private boolean nodeMustBeIgnored(Object node, Class<?> nodeType, FieldLocation fieldLocation) {65 return isNullWhichAreIgnored(node)66 || isPrimitiveWhichAreIgnored(nodeType)67 || configuration.matchesAnIgnoredField(fieldLocation)68 || configuration.matchesAnIgnoredFieldRegex(fieldLocation)69 || configuration.getIgnoredTypes().contains(nodeType);70 }71 private boolean isRootObject(FieldLocation fieldLocation) {72 return fieldLocation.equals(rootFieldLocation());73 }74 private boolean isNullWhichAreIgnored(Object node) {75 return node == null && configuration.shouldIgnoreAllNullFields();76 }77 private boolean isPrimitiveWhichAreIgnored(Class<?> nodeType) {78 return configuration.shouldIgnorePrimitiveFields() && isPrimitiveOrWrapper(nodeType);79 }80 private void evaluateAssertion(Predicate<Object> predicate, Object node, FieldLocation fieldLocation) {81 if (assertionFails(predicate, node)) {82 fieldsFailingTheAssertion.add(fieldLocation);83 }84 }85 private boolean assertionFails(Predicate<Object> predicate, Object node) {86 return !predicate.test(node);87 }88 private boolean shouldEvaluateAssertion(Class<?> nodeType) {89 boolean ignoreContainerAssertion = configuration.shouldIgnoreContainer() && isContainer(nodeType);90 boolean ignoreMapAssertion = configuration.shouldIgnoreMap() && isMap(nodeType);91 boolean ignoreOptionalAssertion = configuration.shouldIgnoreOptional() && isOptionalOrPrimitiveOptional(nodeType);92 return !(ignoreContainerAssertion || ignoreMapAssertion || ignoreOptionalAssertion);93 }94 private boolean isContainer(Class<?> nodeType) {95 return isCollection(nodeType) || isArray(nodeType);96 }97 private void recurseIntoFieldsOfCurrentNode(Predicate<Object> predicate, Object node, Class<?> nodeType,98 FieldLocation fieldLocation) {99 if (isTypeRequiringSpecificHandling(nodeType)) {100 if (shouldRecurseOverSpecialTypes(nodeType)) {101 doRecursionForSpecialTypes(predicate, node, nodeType, fieldLocation);102 }103 } else if (shouldRecurseIntoNode(node)) {104 evaluateFieldsOfCurrentNodeRecursively(predicate, node, fieldLocation);105 }106 }107 private boolean isTypeRequiringSpecificHandling(Class<?> nodeType) {108 return isCollection(nodeType) || isMap(nodeType) || isArray(nodeType) || isOptionalOrPrimitiveOptional(nodeType);109 }110 private boolean shouldRecurseOverSpecialTypes(Class<?> nodeType) {111 boolean recurseOverContainer = isContainer(nodeType)112 && configuration.getCollectionAssertionPolicy() != COLLECTION_OBJECT_ONLY;113 boolean recurseOverMap = isMap(nodeType) && configuration.getMapAssertionPolicy() != MAP_OBJECT_ONLY;114 boolean recurseOverOptional = isOptionalOrPrimitiveOptional(nodeType)115 && configuration.getOptionalAssertionPolicy() != OPTIONAL_OBJECT_ONLY;116 return recurseOverContainer || recurseOverMap || recurseOverOptional;117 }118 private void doRecursionForSpecialTypes(Predicate<Object> predicate, Object node, Class<?> nodeType,119 FieldLocation fieldLocation) {120 if (isCollection(nodeType)) {121 recurseIntoCollection(predicate, (Collection<?>) node, fieldLocation);122 } else if (isArray(nodeType)) {123 recurseIntoArray(predicate, node, nodeType, fieldLocation);124 } else if (isMap(nodeType)) {125 recurseIntoMap(predicate, (Map<?, ?>) node, fieldLocation);126 } else if (isOptionalOrPrimitiveOptional(nodeType)) {127 recurseIntoOptional(predicate, node, fieldLocation);128 }129 }130 private void recurseIntoCollection(Predicate<Object> predicate, Collection<?> collection, FieldLocation fieldLocation) {131 // TODO handle collection if needed by policy132 int index = 0;133 for (Object element : collection) {134 assertRecursively(predicate, element, safeGetClass(element), fieldLocation.field(format(INDEX_FORMAT, index)));135 index++;136 }137 }138 private void recurseIntoArray(Predicate<Object> predicate, Object node, Class<?> nodeType, FieldLocation fieldLocation) {139 Class<?> arrayType = nodeType.getComponentType();140 Object[] array = Arrays.asObjectArray(node);141 for (int i = 0; i < array.length; i++) {142 assertRecursively(predicate, array[i], arrayType, fieldLocation.field(format(INDEX_FORMAT, i)));143 }144 }145 private void recurseIntoOptional(Predicate<Object> predicate, Object node, FieldLocation fieldLocation) {146 // If we are here, we know the node is an optional or a primitive optional147 if (node instanceof Optional) {148 Optional<?> optionalNode = (Optional<?>) node;149 if (optionalNode.isPresent()) {150 Class<?> nextNodeType = safeGetClass(optionalNode.get());151 assertRecursively(predicate, optionalNode.get(), nextNodeType, fieldLocation.field("value"));152 }153 } else if (node instanceof OptionalInt) {154 OptionalInt optionalIntNode = (OptionalInt) node;155 if (optionalIntNode.isPresent()) {156 evaluateAssertion(predicate, optionalIntNode.getAsInt(), fieldLocation.field("value"));157 }158 } else if (node instanceof OptionalLong) {159 OptionalLong optionalLongNode = (OptionalLong) node;160 if (optionalLongNode.isPresent()) {161 evaluateAssertion(predicate, optionalLongNode.getAsLong(), fieldLocation.field("value"));162 }163 } else if (node instanceof OptionalDouble) {164 OptionalDouble optionalDoubleNode = (OptionalDouble) node;165 if (optionalDoubleNode.isPresent()) {166 evaluateAssertion(predicate, optionalDoubleNode.getAsDouble(), fieldLocation.field("value"));167 }168 }169 }170 private void recurseIntoMap(Predicate<Object> predicate, Map<?, ?> node, FieldLocation fieldLocation) {171 // If we are here, we can assume the policy is not MAP_OBJECT_ONLY172 // For both policies VALUES_ONLY and MAP_OBJECT_AND_ENTRIES we have to recurse over the values.173 recurseIntoMapValues(predicate, node, fieldLocation);174 if (configuration.getMapAssertionPolicy() == MAP_OBJECT_AND_ENTRIES) {175 recurseIntoMapKeys(predicate, node, fieldLocation);176 }177 }178 private void recurseIntoMapValues(Predicate<Object> predicate, Map<?, ?> currentNode, FieldLocation fieldLocation) {179 currentNode.values().forEach(nextNode -> recurseIntoMapElement(predicate, fieldLocation, nextNode, VALUE_FORMAT));180 }...
evaluateAssertion
Using AI Code Generation
1RecursiveAssertionDriver.evaluateAssertion(softAssertions, actual, assertion);2RecursiveAssertionDriver.evaluateAssertion(softAssertions, actual, assertion, recursiveComparisonConfiguration);3RecursiveAssertionDriver.evaluateAssertion(softAssertions, actual, assertion, RecursiveComparisonConfiguration.builder().build());4RecursiveAssertionDriver.evaluateAssertion(softAssertions, actual, assertion, recursiveComparisonConfiguration, recursiveComparisonConfiguration);5RecursiveAssertionDriver.evaluateAssertion(softAssertions, actual, assertion, RecursiveComparisonConfiguration.builder().build(), recursiveComparisonConfiguration);6RecursiveAssertionDriver.evaluateAssertion(softAssertions, actual, assertion, recursiveComparisonConfiguration, RecursiveComparisonConfiguration.builder().build());7RecursiveAssertionDriver.evaluateAssertion(softAssertions, actual, assertion, RecursiveComparisonConfiguration.builder().build(), RecursiveComparisonConfiguration.builder().build());8RecursiveAssertionDriver.evaluateAssertion(softAssertions, actual, assertion, recursiveComparisonConfiguration, recursiveComparisonConfiguration, recursiveComparisonConfiguration);9RecursiveAssertionDriver.evaluateAssertion(softAssertions, actual, assertion, RecursiveComparisonConfiguration.builder().build(), recursiveComparisonConfiguration, recursiveComparisonConfiguration);10RecursiveAssertionDriver.evaluateAssertion(softAssertions, actual, assertion, recursiveComparisonConfiguration, RecursiveComparisonConfiguration.builder().build(), recursiveComparisonConfiguration);11RecursiveAssertionDriver.evaluateAssertion(softAssertions, actual, assertion, recursiveComparisonConfiguration, recursiveComparisonConfiguration, RecursiveComparisonConfiguration.builder().build());
evaluateAssertion
Using AI Code Generation
1import org.assertj.core.api.recursive.comparison.RecursiveComparisonConfiguration2import org.assertj.core.api.recursive.comparison.RecursiveComparisonConfigurationBuilder3import org.assertj.core.api.recursive.comparison.RecursiveComparisonDifference4import org.assertj.core.api.recursive.comparison.RecursiveComparisonDifferenceType5import org.assertj.core.api.recursive.comparison.RecursiveComparisonDifferenceVisitor6import org.assertj.core.api.recursive.comparison.RecursiveComparisonResult7import org.assertj.core.api.recursive.comparison.RecursiveComparisonResultVisito
evaluateAssertion
Using AI Code Generation
1import org.assertj.core.api.recursive.assertion.RecursiveAssertionDriver;2public class RecursiveAssertionDriverExample {3 public static void main(String[] args) {4 RecursiveAssertionDriver.evaluateAssertion("foo", "foo");5 }6}7RecursiveAssertionDriver.evaluateAssertion("foo", "bar");8RecursiveAssertionDriver.evaluateAssertion("foo", null);9RecursiveAssertionDriver.evaluateAssertion(null, "foo");10RecursiveAssertionDriver.evaluateAssertion(null, null);11RecursiveAssertionDriver.evaluateAssertion(new String[] { "foo", "bar" }, new String[] { "foo", "bar" });12RecursiveAssertionDriver.evaluateAssertion(new String[] { "foo", "bar" }, new String[] { "bar", "foo" });
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!!