How to use registerComparatorForFieldsMatchingRegexes method of org.assertj.core.api.recursive.comparison.FieldComparators class

Best Assertj code snippet using org.assertj.core.api.recursive.comparison.FieldComparators.registerComparatorForFieldsMatchingRegexes

Source:RecursiveComparisonConfiguration.java Github

copy

Full Screen

...399 * @throws NullPointerException if the given BiPredicate is null.400 * @since 3.24.0401 */402 public void registerEqualsForFieldsMatchingRegexes(BiPredicate<?, ?> equals, String... regexes) {403 fieldComparators.registerComparatorForFieldsMatchingRegexes(regexes, toComparator(equals));404 }405 /**406 * Registers the giving message which would be shown when differences in the given fields while comparison occurred.407 * <p>408 * The fields must be specified from the root object, for example if {@code Foo} has a {@code Bar} field and both409 * have an {@code id} field, one can register a message for Foo and Bar's {@code id} by calling:410 * <pre><code class='java'> registerErrorMessageForFields("some message", "foo.id", "foo.bar.id")</code></pre>411 * <p>412 * Messages registered with this method have precedence over the ones registered with {@link #registerErrorMessageForType(String, Class)}.413 * <p>414 * In case of {@code null} as message the default error message will be used (See {@link ComparisonDifference#DEFAULT_TEMPLATE}).415 *416 * @param message the error message that will be thrown when comparison error occurred417 * @param fieldLocations the field locations the error message should be used for418 */419 public void registerErrorMessageForFields(String message, String... fieldLocations) {420 Stream.of(fieldLocations).forEach(fieldLocation -> fieldMessages.registerMessage(fieldLocation, message));421 }422 /**423 * Registers the giving message which would be shown when differences for the giving type while comparison424 * occurred.425 * <p>426 * Message registered with this method have less precedence than the ones registered with {@link #registerErrorMessageForFields(String, String...)}.427 * <p>428 * In case of {@code null} as message the default error message will be used (See {@link ComparisonDifference#DEFAULT_TEMPLATE}).429 *430 * @param message the error message that will be thrown when comparison error occurred431 * @param clazz the type the error message should be used for432 */433 public void registerErrorMessageForType(String message, Class<?> clazz) {434 typeMessages.registerMessage(clazz, message);435 }436 /**437 * Sets whether the recursive comparison will check that actual's type is compatible with expected's type (the same applies for each field).438 * Compatible means that the expected's type is the same or a subclass of actual's type.439 * <p>440 * See {@link RecursiveComparisonAssert#withStrictTypeChecking()} for code examples.441 *442 * @param strictTypeChecking whether the recursive comparison will check that actual's type is compatible with expected's type.443 */444 public void strictTypeChecking(boolean strictTypeChecking) {445 this.strictTypeChecking = strictTypeChecking;446 }447 public boolean isInStrictTypeCheckingMode() {448 return strictTypeChecking;449 }450 public List<Class<?>> getIgnoredOverriddenEqualsForTypes() {451 return ignoredOverriddenEqualsForTypes;452 }453 public List<String> getIgnoredOverriddenEqualsForFields() {454 return ignoredOverriddenEqualsForFields;455 }456 public List<Pattern> getIgnoredOverriddenEqualsForFieldsMatchingRegexes() {457 return ignoredOverriddenEqualsForFieldsMatchingRegexes;458 }459 public Stream<Entry<String, Comparator<?>>> comparatorByFields() {460 return fieldComparators.comparatorByFields();461 }462 @Override463 public String toString() {464 return multiLineDescription(CONFIGURATION_PROVIDER.representation());465 }466 @Override467 public int hashCode() {468 return java.util.Objects.hash(fieldComparators, ignoreAllActualEmptyOptionalFields, ignoreAllActualNullFields,469 ignoreAllExpectedNullFields, ignoreAllOverriddenEquals, ignoreCollectionOrder,470 ignoredCollectionOrderInFields, ignoredCollectionOrderInFieldsMatchingRegexes,471 getIgnoredFields(),472 getIgnoredFieldsRegexes(), ignoredOverriddenEqualsForFields,473 ignoredOverriddenEqualsForTypes,474 ignoredOverriddenEqualsForFieldsMatchingRegexes, getIgnoredTypes(), strictTypeChecking,475 typeComparators, comparedFields, fieldMessages, typeMessages);476 }477 @Override478 public boolean equals(Object obj) {479 if (this == obj) return true;480 if (obj == null) return false;481 if (getClass() != obj.getClass()) return false;482 RecursiveComparisonConfiguration other = (RecursiveComparisonConfiguration) obj;483 return java.util.Objects.equals(fieldComparators, other.fieldComparators)484 && ignoreAllActualEmptyOptionalFields == other.ignoreAllActualEmptyOptionalFields485 && ignoreAllActualNullFields == other.ignoreAllActualNullFields486 && ignoreAllExpectedNullFields == other.ignoreAllExpectedNullFields487 && ignoreAllOverriddenEquals == other.ignoreAllOverriddenEquals488 && ignoreCollectionOrder == other.ignoreCollectionOrder489 && java.util.Objects.equals(ignoredCollectionOrderInFields, other.ignoredCollectionOrderInFields)490 && java.util.Objects.equals(getIgnoredFields(), other.getIgnoredFields())491 && java.util.Objects.equals(comparedFields, other.comparedFields)492 && java.util.Objects.equals(getIgnoredFieldsRegexes(), other.getIgnoredFieldsRegexes())493 && java.util.Objects.equals(ignoredOverriddenEqualsForFields, other.ignoredOverriddenEqualsForFields)494 && java.util.Objects.equals(ignoredOverriddenEqualsForTypes, other.ignoredOverriddenEqualsForTypes)495 && java.util.Objects.equals(ignoredOverriddenEqualsForFieldsMatchingRegexes,496 other.ignoredOverriddenEqualsForFieldsMatchingRegexes)497 && java.util.Objects.equals(getIgnoredTypes(), other.getIgnoredTypes())498 && strictTypeChecking == other.strictTypeChecking499 && java.util.Objects.equals(typeComparators, other.typeComparators)500 && java.util.Objects.equals(ignoredCollectionOrderInFieldsMatchingRegexes,501 other.ignoredCollectionOrderInFieldsMatchingRegexes)502 && java.util.Objects.equals(fieldMessages, other.fieldMessages)503 && java.util.Objects.equals(typeMessages, other.typeMessages);504 }505 public String multiLineDescription(Representation representation) {506 StringBuilder description = new StringBuilder();507 describeIgnoreAllActualNullFields(description);508 describeIgnoreAllActualEmptyOptionalFields(description);509 describeIgnoreAllExpectedNullFields(description);510 describeComparedFields(description);511 describeIgnoredFields(description);512 describeIgnoredFieldsRegexes(description);513 describeIgnoredFieldsForTypes(description);514 describeOverriddenEqualsMethodsUsage(description, representation);515 describeIgnoreCollectionOrder(description);516 describeIgnoredCollectionOrderInFields(description);517 describeIgnoredCollectionOrderInFieldsMatchingRegexes(description);518 describeRegisteredComparatorByTypes(description);519 describeRegisteredComparatorForFields(description);520 describeTypeCheckingStrictness(description);521 describeRegisteredErrorMessagesForFields(description);522 describeRegisteredErrorMessagesForTypes(description);523 return description.toString();524 }525 boolean shouldIgnore(DualValue dualValue) {526 return shouldIgnoreFieldBasedOnFieldLocation(dualValue.fieldLocation) || shouldIgnoreFieldBasedOnFieldValue(dualValue);527 }528 private boolean shouldBeCompared(FieldLocation fieldLocation) {529 // empty comparedFields <=> no restriction on compared fields <=> must be compared530 if (comparedFields.isEmpty()) return true;531 return comparedFields.stream().anyMatch(matchesComparedField(fieldLocation));532 }533 private static Predicate<FieldLocation> matchesComparedField(FieldLocation field) {534 // a field f must be compared if any compared fields is f itself (obviously), a parent of f or a child of f.535 // - "name.first" must be compared if "name" is a compared field so will other "name" subfields like "name.last"536 // - "name" must be compared if "name.first" is a compared field otherwise "name" is ignored and "name.first" too537 return comparedField -> field.matches(comparedField) // exact match538 || field.hasParent(comparedField) // ex: field "name.first" and "name" compared field539 || field.hasChild(comparedField); // ex: field "name" and "name.first" compared field540 }541 Set<String> getActualFieldNamesToCompare(DualValue dualValue) {542 Set<String> actualFieldsNames = Objects.getFieldsNames(dualValue.actual.getClass());543 // we are doing the same as shouldIgnore(DualValue dualValue) but in two steps for performance reasons:544 // - we filter first ignored field by names that don't need building DualValues545 // - then we filter field DualValues with the remaining criteria that need to get the field value546 // DualValues are built introspecting fields which is expensive.547 return actualFieldsNames.stream()548 // evaluate field name ignoring criteria on dualValue field location + field name549 .filter(fieldName -> !shouldIgnoreFieldBasedOnFieldLocation(dualValue.fieldLocation.field(fieldName)))550 .map(fieldName -> dualValueForField(dualValue, fieldName))551 // evaluate field value ignoring criteria552 .filter(fieldDualValue -> !shouldIgnoreFieldBasedOnFieldValue(fieldDualValue))553 // back to field name554 .map(DualValue::getFieldName)555 .filter(fieldName -> !fieldName.isEmpty())556 .collect(toSet());557 }558 // non accessible stuff559 private boolean shouldIgnoreFieldBasedOnFieldValue(DualValue dualValue) {560 return matchesAnIgnoredNullField(dualValue)561 || matchesAnIgnoredFieldType(dualValue)562 || matchesAnIgnoredEmptyOptionalField(dualValue);563 }564 private boolean shouldIgnoreFieldBasedOnFieldLocation(FieldLocation fieldLocation) {565 return !shouldBeCompared(fieldLocation) || matchesAnIgnoredField(fieldLocation) || matchesAnIgnoredFieldRegex(fieldLocation);566 }567 private static DualValue dualValueForField(DualValue parentDualValue, String fieldName) {568 Object actualFieldValue = COMPARISON.getSimpleValue(fieldName, parentDualValue.actual);569 // no guarantees we have a field in expected named as fieldName570 Object expectedFieldValue;571 try {572 expectedFieldValue = COMPARISON.getSimpleValue(fieldName, parentDualValue.expected);573 } catch (@SuppressWarnings("unused") Exception e) {574 // set the field to null to express it is absent, this not 100% accurate as the value could be null,575 // but it works to evaluate if dualValue should be ignored with matchesAnIgnoredFieldType576 expectedFieldValue = null;577 }578 FieldLocation fieldLocation = parentDualValue.fieldLocation.field(fieldName);579 return new DualValue(fieldLocation, actualFieldValue, expectedFieldValue);580 }581 boolean hasCustomComparator(DualValue dualValue) {582 String fieldName = dualValue.getConcatenatedPath();583 if (hasComparatorForField(fieldName)) return true;584 if (dualValue.actual == null && dualValue.expected == null) return false;585 // best effort assuming actual and expected have the same type (not 100% true as we can compare object of different types)586 Class<?> valueType = dualValue.actual != null ? dualValue.actual.getClass() : dualValue.expected.getClass();587 return hasComparatorForType(valueType);588 }589 boolean shouldIgnoreOverriddenEqualsOf(DualValue dualValue) {590 // we must compare java basic types otherwise the recursive comparison loops infinitely!591 if (dualValue.isActualJavaType()) return false;592 // enums don't have fields, comparing them field by field makes no sense, we need to use equals which is overridden and final593 if (dualValue.isActualAnEnum()) return false;594 return ignoreAllOverriddenEquals595 || matchesAnIgnoredOverriddenEqualsField(dualValue.fieldLocation)596 || (dualValue.actual != null && shouldIgnoreOverriddenEqualsOf(dualValue.actual.getClass()));597 }598 @VisibleForTesting599 boolean shouldIgnoreOverriddenEqualsOf(Class<?> clazz) {600 return matchesAnIgnoredOverriddenEqualsType(clazz);601 }602 boolean shouldIgnoreCollectionOrder(FieldLocation fieldLocation) {603 return ignoreCollectionOrder604 || matchesAnIgnoredCollectionOrderInField(fieldLocation)605 || matchesAnIgnoredCollectionOrderInFieldRegex(fieldLocation);606 }607 private void describeComparedFields(StringBuilder description) {608 if (!comparedFields.isEmpty())609 description.append(format("- the comparison was performed on the following fields: %s%n", describeComparedFields()));610 }611 private void describeIgnoredFieldsForTypes(StringBuilder description) {612 if (!getIgnoredTypes().isEmpty())613 description.append(format("- the following types were ignored in the comparison: %s%n", describeIgnoredTypes()));614 }615 protected void describeIgnoreAllActualNullFields(StringBuilder description) {616 if (ignoreAllActualNullFields) description.append(format("- all actual null fields were ignored in the comparison%n"));617 }618 protected void describeIgnoreAllActualEmptyOptionalFields(StringBuilder description) {619 if (ignoreAllActualEmptyOptionalFields)620 description.append(format(621 "- all actual empty optional fields were ignored in the comparison (including Optional, OptionalInt, OptionalLong and OptionalDouble)%n"));622 }623 private void describeIgnoreAllExpectedNullFields(StringBuilder description) {624 if (ignoreAllExpectedNullFields) description.append(format("- all expected null fields were ignored in the comparison%n"));625 }626 private void describeOverriddenEqualsMethodsUsage(StringBuilder description, Representation representation) {627 String header = ignoreAllOverriddenEquals628 ? "- no overridden equals methods were used in the comparison (except for java types)"629 : "- overridden equals methods were used in the comparison";630 description.append(header);631 if (isConfiguredToIgnoreSomeButNotAllOverriddenEqualsMethods()) {632 description.append(format(" except for:%n"));633 describeIgnoredOverriddenEqualsMethods(description, representation);634 } else {635 description.append(format("%n"));636 }637 }638 private void describeIgnoredOverriddenEqualsMethods(StringBuilder description, Representation representation) {639 if (!ignoredOverriddenEqualsForFields.isEmpty())640 description.append(format("%s the following fields: %s%n", INDENT_LEVEL_2,641 describeIgnoredOverriddenEqualsForFields()));642 if (!ignoredOverriddenEqualsForTypes.isEmpty())643 description.append(format("%s the following types: %s%n", INDENT_LEVEL_2,644 describeIgnoredOverriddenEqualsForTypes(representation)));645 if (!ignoredOverriddenEqualsForFieldsMatchingRegexes.isEmpty())646 description.append(format("%s the fields matching the following regexes: %s%n", INDENT_LEVEL_2,647 describeRegexes(ignoredOverriddenEqualsForFieldsMatchingRegexes)));648 }649 private String describeIgnoredOverriddenEqualsForTypes(Representation representation) {650 List<String> fieldsDescription = ignoredOverriddenEqualsForTypes.stream()651 .map(representation::toStringOf)652 .collect(toList());653 return join(fieldsDescription);654 }655 private String describeIgnoredOverriddenEqualsForFields() {656 return join(ignoredOverriddenEqualsForFields);657 }658 private void describeIgnoreCollectionOrder(StringBuilder description) {659 if (ignoreCollectionOrder) description.append(format("- collection order was ignored in all fields in the comparison%n"));660 }661 private void describeIgnoredCollectionOrderInFields(StringBuilder description) {662 if (!ignoredCollectionOrderInFields.isEmpty())663 description.append(format("- collection order was ignored in the following fields in the comparison: %s%n",664 describeIgnoredCollectionOrderInFields()));665 }666 private void describeIgnoredCollectionOrderInFieldsMatchingRegexes(StringBuilder description) {667 if (!ignoredCollectionOrderInFieldsMatchingRegexes.isEmpty())668 description.append(669 format("- collection order was ignored in the fields matching the following regexes in the comparison: %s%n",670 describeRegexes(ignoredCollectionOrderInFieldsMatchingRegexes)));671 }672 private boolean matchesAnIgnoredOverriddenEqualsRegex(FieldLocation fieldLocation) {673 if (ignoredOverriddenEqualsForFieldsMatchingRegexes.isEmpty()) return false; // shortcut674 String pathToUseInRules = fieldLocation.getPathToUseInRules();675 return ignoredOverriddenEqualsForFieldsMatchingRegexes.stream().anyMatch(regex -> regex.matcher(pathToUseInRules).matches());676 }677 private boolean matchesAnIgnoredOverriddenEqualsType(Class<?> clazz) {678 return ignoredOverriddenEqualsForTypes.contains(clazz);679 }680 private boolean matchesAnIgnoredOverriddenEqualsField(FieldLocation fieldLocation) {681 return ignoredOverriddenEqualsForFields.stream().anyMatch(fieldLocation::matches)682 || matchesAnIgnoredOverriddenEqualsRegex(fieldLocation);683 }684 private boolean matchesAnIgnoredNullField(DualValue dualValue) {685 return (ignoreAllActualNullFields && dualValue.actual == null)686 || (ignoreAllExpectedNullFields && dualValue.expected == null);687 }688 private boolean matchesAnIgnoredEmptyOptionalField(DualValue dualValue) {689 return ignoreAllActualEmptyOptionalFields690 && dualValue.isActualFieldAnEmptyOptionalOfAnyType();691 }692 private boolean matchesAnIgnoredFieldType(DualValue dualValue) {693 Object actual = dualValue.actual;694 if (actual != null) return getIgnoredTypes().contains(actual.getClass());695 Object expected = dualValue.expected;696 // actual is null => we can't evaluate its type, we can only reliably check dualValue.expected's type if697 // strictTypeChecking is enabled which guarantees expected is of the same type.698 if (strictTypeChecking && expected != null) return getIgnoredTypes().contains(expected.getClass());699 // if strictTypeChecking is disabled, we can't safely ignore the field (if we did, we would ignore all null fields!).700 return false;701 }702 private boolean matchesAnIgnoredCollectionOrderInField(FieldLocation fieldLocation) {703 return ignoredCollectionOrderInFields.stream().anyMatch(fieldLocation::matches);704 }705 private boolean matchesAnIgnoredCollectionOrderInFieldRegex(FieldLocation fieldLocation) {706 String pathToUseInRules = fieldLocation.getPathToUseInRules();707 return ignoredCollectionOrderInFieldsMatchingRegexes.stream().anyMatch(regex -> regex.matcher(pathToUseInRules).matches());708 }709 private String describeComparedFields() {710 return join(comparedFields.stream().map(FieldLocation::shortDescription).collect(toList()));711 }712 private String describeIgnoredCollectionOrderInFields() {713 return join(ignoredCollectionOrderInFields);714 }715 private boolean isConfiguredToIgnoreSomeButNotAllOverriddenEqualsMethods() {716 boolean ignoreSomeOverriddenEqualsMethods = !ignoredOverriddenEqualsForFieldsMatchingRegexes.isEmpty()717 || !ignoredOverriddenEqualsForTypes.isEmpty()718 || !ignoredOverriddenEqualsForFields.isEmpty();719 return !ignoreAllOverriddenEquals && ignoreSomeOverriddenEqualsMethods;720 }721 private void describeRegisteredComparatorByTypes(StringBuilder description) {722 if (!typeComparators.isEmpty()) {723 description.append(format("- these types were compared with the following comparators:%n"));724 describeComparatorForTypes(description);725 }726 }727 private void describeComparatorForTypes(StringBuilder description) {728 typeComparators.comparatorByTypes()729 .map(this::formatRegisteredComparatorByType)730 .forEach(description::append);731 }732 private String formatRegisteredComparatorByType(Entry<Class<?>, Comparator<?>> next) {733 return format("%s %s -> %s%n", INDENT_LEVEL_2, next.getKey().getName(), next.getValue());734 }735 private void describeRegisteredComparatorForFields(StringBuilder description) {736 if (!fieldComparators.isEmpty()) {737 if (fieldComparators.hasFieldComparators()) {738 description.append(format("- these fields were compared with the following comparators:%n"));739 describeComparatorForFields(description);740 }741 if (fieldComparators.hasRegexFieldComparators()) {742 description.append(format("- the fields matching these regexes were compared with the following comparators:%n"));743 describeComparatorForRegexFields(description);744 }745 if (fieldComparators.hasFieldComparators() && fieldComparators.hasRegexFieldComparators()) {746 description.append(format("- field comparators take precedence over regex field matching comparators.%n"));747 }748 if (!typeComparators.isEmpty()) {749 description.append(format("- field comparators take precedence over type comparators.%n"));750 }751 }752 }753 private void describeComparatorForFields(StringBuilder description) {754 fieldComparators.comparatorByFields()755 .map(this::formatRegisteredComparatorForField)756 .forEach(description::append);757 }758 private void describeComparatorForRegexFields(StringBuilder description) {759 fieldComparators.comparatorByRegexFields()760 .map(this::formatRegisteredComparatorForRegexFields)761 .sorted()762 .forEach(description::append);763 }764 private String formatRegisteredComparatorForField(Entry<String, Comparator<?>> comparatorForField) {765 return format("%s %s -> %s%n", INDENT_LEVEL_2, comparatorForField.getKey(), comparatorForField.getValue());766 }767 private String formatRegisteredComparatorForRegexFields(Entry<List<Pattern>, Comparator<?>> comparatorForRegexFields) {768 return format("%s %s -> %s%n", INDENT_LEVEL_2, comparatorForRegexFields.getKey(), comparatorForRegexFields.getValue());769 }770 private void describeTypeCheckingStrictness(StringBuilder description) {771 String str = strictTypeChecking772 ? "- actual and expected objects and their fields were considered different when of incompatible types (i.e. expected type does not extend actual's type) even if all their fields match, for example a Person instance will never match a PersonDto (call strictTypeChecking(false) to change that behavior).%n"773 : "- actual and expected objects and their fields were compared field by field recursively even if they were not of the same type, this allows for example to compare a Person to a PersonDto (call strictTypeChecking(true) to change that behavior).%n";774 description.append(format(str));775 }776 private void describeRegisteredErrorMessagesForFields(StringBuilder description) {777 if (!fieldMessages.isEmpty()) {778 description.append(format("- these fields had overridden error messages:%n"));779 describeErrorMessagesForFields(description);780 if (!typeMessages.isEmpty()) {781 description.append(format("- field custom messages take precedence over type messages.%n"));782 }783 }784 }785 private void describeErrorMessagesForFields(StringBuilder description) {786 String fields = fieldMessages.messageByFields()787 .map(Entry::getKey)788 .collect(joining(DEFAULT_DELIMITER));789 description.append(format("%s %s%n", INDENT_LEVEL_2, fields));790 }791 private void describeRegisteredErrorMessagesForTypes(StringBuilder description) {792 if (!typeMessages.isEmpty()) {793 description.append("- these types had overridden error messages:%n");794 describeErrorMessagesForType(description);795 }796 }797 private void describeErrorMessagesForType(StringBuilder description) {798 String types = typeMessages.messageByTypes()799 .map(it -> it.getKey().getName())800 .collect(joining(DEFAULT_DELIMITER));801 description.append(format("%s %s%n", INDENT_LEVEL_2, types));802 }803 /**804 * Creates builder to build {@link RecursiveComparisonConfiguration}.805 * @return created builder806 */807 public static Builder builder() {808 return new Builder();809 }810 /**811 * Builder to build {@link RecursiveComparisonConfiguration}.812 */813 public static final class Builder extends AbstractBuilder<Builder> {814 private boolean strictTypeChecking;815 private boolean ignoreAllActualNullFields;816 private boolean ignoreAllActualEmptyOptionalFields;817 private boolean ignoreAllExpectedNullFields;818 private FieldLocation[] comparedFields = {};819 private Class<?>[] ignoredOverriddenEqualsForTypes = {};820 private String[] ignoredOverriddenEqualsForFields = {};821 private String[] ignoredOverriddenEqualsForFieldsMatchingRegexes = {};822 private boolean ignoreAllOverriddenEquals = DEFAULT_IGNORE_ALL_OVERRIDDEN_EQUALS;823 private boolean ignoreCollectionOrder;824 private String[] ignoredCollectionOrderInFields = {};825 private String[] ignoredCollectionOrderInFieldsMatchingRegexes = {};826 private final TypeComparators typeComparators = defaultTypeComparators();827 private final FieldComparators fieldComparators = new FieldComparators();828 private final FieldMessages fieldMessages = new FieldMessages();829 private final TypeMessages typeMessages = new TypeMessages();830 private Builder() {831 super(Builder.class);832 }833 /**834 * Sets whether the recursive comparison will check that actual's type is compatible with expected's type (the same applies for each field).835 * Compatible means that the expected's type is the same or a subclass of actual's type.836 * <p>837 * See {@link RecursiveComparisonAssert#withStrictTypeChecking()} for code examples.838 *839 * @param strictTypeChecking whether the recursive comparison will check that actual's type is compatible with expected's type.840 * @return this builder.841 */842 public Builder withStrictTypeChecking(boolean strictTypeChecking) {843 this.strictTypeChecking = strictTypeChecking;844 return this;845 }846 /**847 * Sets whether actual null fields are ignored in the recursive comparison.848 * <p>849 * See {@link RecursiveComparisonAssert#ignoringActualNullFields()} for code examples.850 *851 * @param ignoreAllActualNullFields whether to ignore actual null fields in the recursive comparison852 * @return this builder.853 */854 public Builder withIgnoreAllActualNullFields(boolean ignoreAllActualNullFields) {855 this.ignoreAllActualNullFields = ignoreAllActualNullFields;856 return this;857 }858 /**859 * Sets whether actual empty optional fields are ignored in the recursive comparison.860 * <p>861 * See {@link RecursiveComparisonAssert#ignoringActualEmptyOptionalFields()} for code examples.862 *863 * @param ignoreAllActualEmptyOptionalFields whether to ignore actual empty optional fields in the recursive comparison864 * @return this builder.865 */866 public Builder withIgnoreAllActualEmptyOptionalFields(boolean ignoreAllActualEmptyOptionalFields) {867 this.ignoreAllActualEmptyOptionalFields = ignoreAllActualEmptyOptionalFields;868 return this;869 }870 /**871 * Sets whether expected null fields are ignored in the recursive comparison.872 * <p>873 * See {@link RecursiveComparisonAssert#ignoringExpectedNullFields()} for code examples.874 *875 * @param ignoreAllExpectedNullFields whether to ignore expected null fields in the recursive comparison876 * @return this builder.877 */878 public Builder withIgnoreAllExpectedNullFields(boolean ignoreAllExpectedNullFields) {879 this.ignoreAllExpectedNullFields = ignoreAllExpectedNullFields;880 return this;881 }882 /**883 * Adds the given fields to the set of fields from the object under test to compare in the recursive comparison.884 * <p>885 * Nested fields can be specified like this: home.address.street.886 * <p>887 * See {@link RecursiveComparisonAssert#comparingOnlyFields(String...)} for examples.888 *889 * @param fieldsToCompare the fields of the object under test to compare.890 * @return this builder.891 */892 public Builder withComparedFields(String... fieldsToCompare) {893 this.comparedFields = Stream.of(fieldsToCompare).map(FieldLocation::new).toArray(FieldLocation[]::new);894 return this;895 }896 /**897 * Adds the given types to the list of types to force a recursive comparison on.898 * <p>899 * See {@link RecursiveComparisonAssert#ignoringOverriddenEqualsForTypes(Class...) RecursiveComparisonAssert#ignoringOverriddenEqualsForTypes(Class...)} for examples.900 *901 * @param types the types to the list of types to force a recursive comparison on.902 * @return this builder.903 */904 public Builder withIgnoredOverriddenEqualsForTypes(Class<?>... types) {905 this.ignoredOverriddenEqualsForTypes = types;906 return this;907 }908 /**909 * Adds the given fields to the list of fields to force a recursive comparison on.910 * <p>911 * See {@link RecursiveComparisonAssert#ignoringOverriddenEqualsForFields(String...) RecursiveComparisonAssert#ignoringOverriddenEqualsForFields(String...)} for examples.912 *913 * @param fields the fields to force a recursive comparison on.914 * @return this builder.915 */916 public Builder withIgnoredOverriddenEqualsForFields(String... fields) {917 this.ignoredOverriddenEqualsForFields = fields;918 return this;919 }920 /**921 * Adds the given regexes to the list of regexes used find the fields to force a recursive comparison on.922 * <p>923 * See {@link RecursiveComparisonAssert#ignoringOverriddenEqualsForFieldsMatchingRegexes(String...) RecursiveComparisonAssert#ignoringOverriddenEqualsForFieldsMatchingRegexes(String...)} for examples.924 *925 * @param regexes regexes used to specify the fields we want to force a recursive comparison on.926 * @return this builder.927 */928 public Builder withIgnoredOverriddenEqualsForFieldsMatchingRegexes(String... regexes) {929 this.ignoredOverriddenEqualsForFieldsMatchingRegexes = regexes;930 return this;931 }932 /**933 * Force a recursive comparison on all fields (except java types) if true.934 * <p>935 * See {@link RecursiveComparisonAssert#ignoringAllOverriddenEquals()} for examples.936 *937 * @param ignoreAllOverriddenEquals whether to force a recursive comparison on all fields (except java types) or not.938 * @return this builder.939 */940 public Builder withIgnoreAllOverriddenEquals(boolean ignoreAllOverriddenEquals) {941 this.ignoreAllOverriddenEquals = ignoreAllOverriddenEquals;942 return this;943 }944 /**945 * Sets whether to ignore collection order in the comparison.946 * <p>947 * See {@link RecursiveComparisonAssert#ignoringCollectionOrder()} for code examples.948 *949 * @param ignoreCollectionOrder whether to ignore collection order in the comparison.950 * @return this builder.951 */952 public Builder withIgnoreCollectionOrder(boolean ignoreCollectionOrder) {953 this.ignoreCollectionOrder = ignoreCollectionOrder;954 return this;955 }956 /**957 * Adds the given fields to the list fields from the object under test to ignore collection order in the recursive comparison.958 * <p>959 * See {@link RecursiveComparisonAssert#ignoringCollectionOrderInFields(String...) RecursiveComparisonAssert#ignoringCollectionOrderInFields(String...)} for examples.960 *961 * @param fieldsToIgnoreCollectionOrder the fields of the object under test to ignore collection order in the comparison.962 * @return this builder.963 */964 public Builder withIgnoredCollectionOrderInFields(String... fieldsToIgnoreCollectionOrder) {965 this.ignoredCollectionOrderInFields = fieldsToIgnoreCollectionOrder;966 return this;967 }968 /**969 * Adds the given regexes to the list of regexes used to find the object under test fields to ignore collection order in the recursive comparison.970 * <p>971 * See {@link RecursiveComparisonAssert#ignoringCollectionOrderInFieldsMatchingRegexes(String...) RecursiveComparisonAssert#ignoringCollectionOrderInFieldsMatchingRegexes(String...)} for examples.972 *973 * @param regexes regexes used to find the object under test fields to ignore collection order in the comparison.974 * @return this builder.975 */976 public Builder withIgnoredCollectionOrderInFieldsMatchingRegexes(String... regexes) {977 this.ignoredCollectionOrderInFieldsMatchingRegexes = regexes;978 return this;979 }980 /**981 * Registers the given {@link Comparator} to compare the fields with the given type.982 * <p>983 * Comparators registered with this method have less precedence than comparators registered with {@link #withComparatorForFields(Comparator, String...)}984 * or BiPredicate registered with {@link #withEqualsForFields(BiPredicate, String...)}.985 * <p>986 * Note that registering a {@link Comparator} for a given type will override the previously registered BiPredicate/Comparator (if any).987 * <p>988 * See {@link RecursiveComparisonAssert#withComparatorForType(Comparator, Class)} for examples.989 *990 * @param <T> the class type to register a comparator for991 * @param comparator the {@link java.util.Comparator Comparator} to use to compare the given field992 * @param type the type to be compared with the given comparator.993 * @return this builder.994 * @throws NullPointerException if the given Comparator is null.995 */996 public <T> Builder withComparatorForType(Comparator<? super T> comparator, Class<T> type) {997 requireNonNull(comparator, "Expecting a non null Comparator");998 this.typeComparators.registerComparator(type, comparator);999 return this;1000 }1001 /**1002 * Registers the given {@link BiPredicate} to compare the fields with the given type.1003 * <p>1004 * BiPredicates registered with this method have less precedence than the ones registered with {@link #withEqualsForFields(BiPredicate, String...)}1005 * or the comparators registered with {@link #withComparatorForFields(Comparator, String...)}.1006 * <p>1007 * Note that registering a {@link BiPredicate} for a given type will override the previously registered BiPredicate/Comparator (if any).1008 * <p>1009 * See {@link RecursiveComparisonAssert#withEqualsForType(BiPredicate, Class)} for examples.1010 *1011 * @param <T> the class type to register a BiPredicate for1012 * @param equals the {@link BiPredicate} to use to compare the given field1013 * @param type the type to be compared with the given comparator.1014 * @return this builder.1015 * @since 3.17.01016 * @throws NullPointerException if the given BiPredicate is null.1017 */1018 @SuppressWarnings("unchecked")1019 public <T> Builder withEqualsForType(BiPredicate<? super T, ? super T> equals, Class<T> type) {1020 return withComparatorForType(toComparator(equals), type);1021 }1022 /**1023 * Registers the given {@link Comparator} to compare the fields at the given locations.1024 * <p>1025 * The fields must be specified from the root object, for example if {@code Foo} has a {@code Bar} field and both have an {@code id} field,1026 * one can register a comparator for Foo and Bar's {@code id} by calling:1027 * <pre><code class='java'> registerComparatorForFields(idComparator, "foo.id", "foo.bar.id")</code></pre>1028 * <p>1029 * Comparators registered with this method have precedence over comparators registered with {@link #withComparatorForType(Comparator, Class)}1030 * or BiPredicate registered with {@link #withEqualsForType(BiPredicate, Class)}.1031 * <p>1032 * Note that registering a {@link Comparator} for a given field will override the previously registered BiPredicate/Comparator (if any).1033 * <p>1034 * See {@link RecursiveComparisonAssert#withComparatorForFields(Comparator, String...) RecursiveComparisonAssert#withComparatorForFields(Comparator comparator, String...fields)} for examples.1035 *1036 * @param comparator the {@link java.util.Comparator Comparator} to use to compare the given field1037 * @param fields the fields the comparator should be used for1038 * @return this builder.1039 * @throws NullPointerException if the given Comparator is null.1040 */1041 public Builder withComparatorForFields(Comparator<?> comparator, String... fields) {1042 requireNonNull(comparator, "Expecting a non null Comparator");1043 Stream.of(fields).forEach(fieldLocation -> fieldComparators.registerComparator(fieldLocation, comparator));1044 return this;1045 }1046 /**1047 * Registers the given {@link BiPredicate} to compare the fields at the given locations.1048 * <p>1049 * The fields must be specified from the root object, for example if {@code Foo} has a {@code Bar} field and both have an {@code id} field,1050 * one can register a BiPredicate for Foo and Bar's {@code id} by calling:1051 * <pre><code class='java'> withEqualsForFields(idBiPredicate, "foo.id", "foo.bar.id")</code></pre>1052 * <p>1053 * BiPredicates registered with this method have precedence over the ones registered with {@link #withEqualsForType(BiPredicate, Class)}1054 * or the comparators registered with {@link #withComparatorForType(Comparator, Class)}.1055 * <p>1056 * Note that registering a {@link BiPredicate} for a given field will override the previously registered BiPredicate/Comparator (if any).1057 * <p>1058 * See {@link RecursiveComparisonAssert#withEqualsForFields(BiPredicate, String...) RecursiveComparisonAssert#withEqualsForFields(BiPredicate equals, String...fields)} for examples.1059 *1060 * @param equals the {@link BiPredicate} to use to compare the given fields1061 * @param fields the fields the BiPredicate should be used for1062 * @return this builder.1063 * @since 3.17.01064 * @throws NullPointerException if the given BiPredicate is null.1065 */1066 public Builder withEqualsForFields(BiPredicate<?, ?> equals, String... fields) {1067 return withComparatorForFields(toComparator(equals), fields);1068 }1069 /**1070 * Allows to register a {@link BiPredicate} to compare fields whose location matches the given regexes.1071 * A typical usage is to compare double/float fields with a given precision.1072 * <p>1073 * The fields are evaluated from the root object, for example if {@code Foo} has a {@code Bar} field and both have an {@code id} field,1074 * one can register a BiPredicate for Foo and Bar's {@code id} by calling:1075 * <pre><code class='java'> withEqualsForFields(idBiPredicate, ".*id")</code></pre>1076 * or1077 * <pre><code class='java'> withEqualsForFields(idBiPredicate, "foo.*id")</code></pre>1078 * <p>1079 * BiPredicates registered with this method have precedence over the ones registered with {@link #registerEqualsForType(BiPredicate, Class)}1080 * or the comparators registered with {@link #registerComparatorForType(Comparator, Class)} but don't have precedence over the1081 * ones registered with exact location match: {@link #registerEqualsForFields(BiPredicate, String...)} or {@link #registerComparatorForFields(Comparator, String...)}1082 * <p>1083 * If registered regexes for different {@link BiPredicate} match a given field, the latest registered regexes {@link BiPredicate} wins.1084 * <p>1085 * See {@link RecursiveComparisonAssert#withEqualsForFieldsMatchingRegexes(BiPredicate, String...)} RecursiveComparisonAssert#withEqualsForFieldsMatchingRegexes(BiPredicate equals, String...fields)} for examples.1086 *1087 * @param equals the {@link BiPredicate} to use to compare the fields matching the given regexes1088 * @param regexes the regexes to match fields against1089 * @return this builder.1090 * @since 3.24.01091 * @throws NullPointerException if the given BiPredicate is null.1092 */1093 public Builder withEqualsForFieldsMatchingRegexes(BiPredicate<?, ?> equals, String... regexes) {1094 fieldComparators.registerComparatorForFieldsMatchingRegexes(regexes, toComparator(equals));1095 return this;1096 }1097 /**1098 * Registers the giving message which would be shown when differences in the given fields while comparison occurred.1099 * <p>1100 * The fields must be specified from the root object, for example if {@code Foo} has a {@code Bar} field and both1101 * have an {@code id} field, one can register a message for Foo and Bar's {@code id} by calling:1102 * <pre><code class='java'> withErrorMessageForFields("some message", "foo.id", "foo.bar.id")</code></pre>1103 * <p>1104 * Messages registered with this method have precedence over the ones registered with {@link #withErrorMessageForType(String, Class)}.1105 * <p>1106 * In case of {@code null} as message the default error message will be used (See1107 * {@link ComparisonDifference#DEFAULT_TEMPLATE}).1108 *...

Full Screen

Full Screen

Source:FieldComparators.java Github

copy

Full Screen

...41 *42 * @param regexes the regexes field location where to apply the comparator43 * @param comparator the comparator to use for the regexes44 */45 public void registerComparatorForFieldsMatchingRegexes(String[] regexes, Comparator<?> comparator) {46 List<Pattern> patterns = Stream.of(regexes).map(Pattern::compile).collect(toList());47 comparatorByPatterns.addFirst(new ComparatorForPatterns(patterns, comparator));48 }49 /**50 * Checks, whether an any comparator is associated with the giving field location.51 *52 * @param fieldLocation the field location which association need to check53 * @return is field location contain a custom comparator54 */55 public boolean hasComparatorForField(String fieldLocation) {56 // TODO sanitize here?57 boolean hasComparatorForExactFieldLocation = super.hasEntity(fieldLocation);58 // comparator for exact location takes precedence over the one with location matched by regexes59 if (hasComparatorForExactFieldLocation) return true;...

Full Screen

Full Screen

Source:FieldComparators_Test.java Github

copy

Full Screen

...59 "com.bar.baz",60 })61 void should_register_comparator_for_regexes_field_location(String fieldLocation) {62 // WHEN63 fieldComparators.registerComparatorForFieldsMatchingRegexes(array(".*foo", ".*bar.*"), ALWAYS_EQUALS);64 // THEN65 then(fieldComparators.hasComparatorForField(fieldLocation)).isTrue();66 then(fieldComparators.getComparatorForField(fieldLocation)).isSameAs(ALWAYS_EQUALS);67 }68 @Test69 void should_use_latest_registered_comparator_when_several_regexes_match_field_location() {70 // GIVEN71 fieldComparators.registerComparatorForFieldsMatchingRegexes(array(".*foo", ".*bar.*"), ALWAYS_EQUALS);72 then(fieldComparators.hasComparatorForField("com.foo")).isTrue();73 then(fieldComparators.getComparatorForField("com.foo")).isSameAs(ALWAYS_EQUALS);74 // WHEN75 fieldComparators.registerComparatorForFieldsMatchingRegexes(array(".*foo.*", ".*baz.*"), ALWAY_DIFFERENT);76 // THEN77 then(fieldComparators.hasComparatorForField("com.foo")).isTrue();78 then(fieldComparators.getComparatorForField("com.foo")).isNotSameAs(ALWAYS_EQUALS);79 then(fieldComparators.getComparatorForField("com.foo")).isSameAs(ALWAY_DIFFERENT);80 }81 @Test82 void should_prefer_exact_field_location_comparator_over_regex_one() {83 // GIVEN84 fieldComparators.registerComparator("foo", ALWAYS_EQUALS);85 fieldComparators.registerComparatorForFieldsMatchingRegexes(array(".*foo.*", ".*baz.*"), ALWAY_DIFFERENT);86 // THEN87 then(fieldComparators.hasComparatorForField("foo")).isTrue();88 then(fieldComparators.getComparatorForField("foo")).isSameAs(ALWAYS_EQUALS);89 then(fieldComparators.getComparatorForField("com.foo")).isSameAs(ALWAY_DIFFERENT);90 }91 @Test92 void hasComparatorForField_should_return_false_for_field_location_without_comparator() {93 // GIVEN94 String fooLocation = "foo";95 // THEN96 then(fieldComparators.hasComparatorForField(fooLocation)).isFalse();97 }98 @Test99 void getComparatorForField_should_return_null_for_field_location_without_comparator() {100 // GIVEN101 String fooLocation = "foo";102 // THEN103 then(fieldComparators.getComparatorForField(fooLocation)).isNull();104 }105 @Test106 void isEmpty_should_return_true_if_no_field_or_field_regexes_comparators_are_registered() {107 assertThat(fieldComparators.isEmpty()).isTrue();108 }109 @Test110 void isEmpty_should_return_false_if_a_field_comparators_is_registered() {111 // GIVEN112 fieldComparators.registerComparator("foo", ALWAYS_EQUALS);113 // WHEN/THEN114 then(fieldComparators.isEmpty()).isFalse();115 then(fieldComparators.hasFieldComparators()).isTrue();116 }117 @Test118 void isEmpty_should_return_false_if_a_regex_field_comparators_is_registered() {119 // GIVEN120 fieldComparators.registerComparatorForFieldsMatchingRegexes(array(".*foo.*"), ALWAYS_EQUALS);121 // WHEN/THEN122 then(fieldComparators.isEmpty()).isFalse();123 then(fieldComparators.hasRegexFieldComparators()).isTrue();124 }125}...

Full Screen

Full Screen

registerComparatorForFieldsMatchingRegexes

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.api.recursive.comparison.FieldComparators;2import org.assertj.core.api.recursive.comparison.RecursiveComparisonConfiguration;3import org.assertj.core.api.recursive.comparison.RecursiveComparisonDifference;4import org.assertj.core.api.recursive.comparison.RecursiveComparisonDifferenceEvaluator;5import org.assertj.core.api.recursive.comparison.RecursiveComparisonDifferenceEvaluator.RecursiveComparisonDifferenceEvaluatorFactory;6import org.assertj.core.api.recursive.comparison.RecursiveComparisonDifferenceEvaluator.RecursiveComparisonDifferenceEvaluatorFactory.RecursiveComparisonDifferenceEvaluatorFactoryBuilder;7import org.assertj.core.api.recursive.comparison.RecursiveComparisonDifferenceEvaluator.RecursiveComparisonDifferenceEvaluatorFactory.RecursiveComparisonDifferenceEvaluatorFactoryBuilder.RecursiveComparisonDifferenceEvaluatorFactoryBuilderImpl;8import org.assertj.core.api.recursive.comparison.RecursiveComparisonDifferenceEvaluator.RecursiveComparisonDifferenceEvaluatorFactory.RecursiveComparisonDifferenceEvaluatorFactoryBuilder.RecursiveComparisonDifferenceEvaluatorFactoryBuilderImpl.RecursiveComparisonDifferenceEvaluatorFactoryBuilderImplBuilder;9import org.assertj.core.api.recursive.comparison.RecursiveComparisonDifferenceEvaluator.RecursiveComparisonDifferenceEvaluatorFactory.RecursiveComparisonDifferenceEvaluatorFactoryBuilder.RecursiveComparisonDifferenceEvaluatorFactoryBuilderImpl.RecursiveComparisonDifferenceEvaluatorFactoryBuilderImplBuilder.RecursiveComparisonDifferenceEvaluatorFactoryBuilderImplBuilderImpl;10import org.assertj.core.api.recursive.comparison.RecursiveComparisonDifferenceEvaluator.RecursiveComparisonDifferenceEvaluatorFactory.RecursiveComparisonDifferenceEvaluatorFactoryBuilder.RecursiveComparisonDifferenceEvaluatorFactoryBuilderImpl.RecursiveComparisonDifferenceEvaluatorFactoryBuilderImplBuilder.RecursiveComparisonDifferenceEvaluatorFactoryBuilderImplBuilderImpl.RecursiveComparisonDifferenceEvaluatorFactoryBuilderImplBuilderImplBuilder;11import org.assertj.core.api.recursive.comparison.RecursiveComparisonDifferenceEvaluator.RecursiveComparisonDifferenceEvaluatorFactory.RecursiveComparisonDifferenceEvaluatorFactoryBuilder.RecursiveComparisonDifferenceEvaluatorFactoryBuilderImpl.RecursiveComparisonDifferenceEvaluatorFactoryBuilderImplBuilder.RecursiveComparisonDifferenceEvaluatorFactoryBuilderImplBuilderImpl.RecursiveComparisonDifferenceEvaluatorFactoryBuilderImplBuilderImplBuilder.RecursiveComparisonDifferenceEvaluatorFactoryBuilderImplBuilderImplBuilderImpl;12import org.assertj.core.api.recursive.comparison.RecursiveComparisonDifferenceEvaluator.RecursiveComparisonDifferenceEvaluatorFactory.RecursiveComparisonDifferenceEvaluatorFactoryBuilder.RecursiveComparisonDifferenceEvaluatorFactoryBuilderImpl.RecursiveComparisonDifferenceEvaluatorFactoryBuilderImplBuilder.RecursiveComparisonDifferenceEvaluatorFactoryBuilderImplBuilderImpl.RecursiveComparisonDifferenceEvaluatorFactoryBuilderImplBuilderImplBuilder.RecursiveComparisonDifferenceEvaluatorFactoryBuilderImplBuilderImplBuilderImpl.RecursiveComparisonDifferenceEvaluatorFactoryBuilderImplBuilderImplBuilderImplImpl;13import org.assertj.core.api.recursive.comparison.RecursiveComparisonDifferenceEvaluator.RecursiveComparisonDifferenceEvaluatorFactory.Recursive

Full Screen

Full Screen

registerComparatorForFieldsMatchingRegexes

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.api.recursive.comparison.FieldComparators;2import org.assertj.core.api.recursive.comparison.RecursiveComparisonConfiguration;3import org.assertj.core.api.recursive.comparison.RecursiveComparisonDifference;4import org.assertj.core.api.recursive.comparison.RecursiveComparisonDifferenceCalculator;5import org.assertj.core.api.recursive.comparison.RecursiveComparisonDifferenceCalculator.RecursiveComparisonDifferenceCalculatorFactory;6import org.assertj.core.api.recursive.comparison.RecursiveComparisonDifferenceCalculator.RecursiveComparisonDifferenceCalculatorFactoryImpl;7import org.assertj.core.api.recursive.comparison.RecursiveComparisonDifferenceCalculator.RecursiveComparisonDifferenceCalculatorImpl;8import org.assertj.core.api.recursive.comparison.RecursiveComparisonDifferenceCalculator.RecursiveComparisonDifferenceCalculatorImpl.RecursiveComparisonDifferenceCalculatorImplFactory;9import org.assertj.core.api.recursive.comparison.RecursiveComparisonDifferenceCalculator.RecursiveComparisonDifferenceCalculatorImpl.RecursiveComparisonDifferenceCalculatorImplFactoryImpl;10import org.assertj.core.api.recursive.comparison.RecursiveComparisonDifferenceCalculator.RecursiveComparisonDifferenceCalculatorImpl.RecursiveComparisonDifferenceCalculatorImplFactoryImpl.RecursiveComparisonDifferenceCalculatorImplFactoryImplFactory;11import org.assertj.core.api.recursive.comparison.RecursiveComparisonDifferenceCalculator.RecursiveComparisonDifferenceCalculatorImpl.RecursiveComparisonDifferenceCalculatorImplFactoryImpl.RecursiveComparisonDifferenceCalculatorImplFactoryImplFactoryImpl;12import org.assertj.core.api.recursive.comparison.RecursiveComparisonDifferenceCalculator.RecursiveComparisonDifferenceCalculatorImpl.RecursiveComparisonDifferenceCalculatorImplFactoryImpl.RecursiveComparisonDifferenceCalculatorImplFactoryImplFactoryImpl.RecursiveComparisonDifferenceCalculatorImplFactoryImplFactoryImplFactory;13import org.assertj.core.api.recursive.comparison.RecursiveComparisonDifferenceCalculator.RecursiveComparisonDifferenceCalculatorImpl.RecursiveComparisonDifferenceCalculatorImplFactoryImpl.RecursiveComparisonDifferenceCalculatorImplFactoryImplFactoryImpl.RecursiveComparisonDifferenceCalculatorImplFactoryImplFactoryImplFactoryImpl;14import org.assertj.core.api.recursive.comparison.RecursiveComparisonDifferenceCalculator.RecursiveComparisonDifferenceCalculatorImpl.RecursiveComparisonDifferenceCalculatorImplFactoryImpl.RecursiveComparisonDifferenceCalculatorImplFactoryImplFactoryImpl.RecursiveComparisonDifferenceCalculatorImplFactoryImplFactoryImplFactoryImpl.RecursiveComparisonDifferenceCalculatorImplFactoryImplFactoryImplFactoryImplFactory;15import org.assertj.core.api.recursive.comparison.RecursiveComparisonDifferenceCalculator.RecursiveComparisonDifferenceCalculatorImpl.RecursiveComparisonDifferenceCalculatorImplFactoryImpl.RecursiveComparisonDifferenceComparatorFactory;16import org.assertj.core.api.recursive.comparison.RecursiveComparisonDifferenceCalculator.RecursiveComparisonDifferenceCalculatorImpl.RecursiveComparisonDifferenceCalculatorImplFactoryImpl.RecursiveComparisonDifferenceComparatorFactoryImpl;17import org.assertj.core.api.recursive.com

Full Screen

Full Screen

registerComparatorForFieldsMatchingRegexes

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.api.recursive.comparison.FieldComparators;2import org.assertj.core.api.recursive.comparison.FieldLocation;3import org.assertj.core.api.recursive.comparison.FieldLocationComparator;4import org.assertj.core.api.recursive.comparison.FieldLocationComparatorByFieldNames;5import org.assertj.core.api.recursive.comparison.FieldLocationComparatorByFieldTypes;6import org.assertj.core.api.recursive.comparison.FieldLocationComparatorByFieldTypesAndNames;7import org.assertj.core.configuration.Configuration;8import org.assertj.core.configuration.ConfigurationProvider;9import org.assertj.core.internal.TypeComparators;10import org.assertj.core.internal.TypeComparatorsFactory;11import org.assertj.core.util.VisibleForTesting;12import org.assertj.core.util.introspection.FieldSupport;13import org.assertj.core.util.introspection.IntrospectionError;14import org.assertj.core.util.introspection.IntrospectionSupport;15import org.assertj.core.util.introspection.PropertyOrFieldSupport;16public class FieldComparatorsExample {17 public static void main(String[] args) {18 Configuration configuration = ConfigurationProvider.CONFIGURATION_PROVIDER.getConfiguration();19 FieldComparators fieldComparators = FieldComparators.instance();20 fieldComparators.registerComparatorForFieldsMatchingRegexes(".*\\.Id", new FieldLocationComparator() {21 public int compare(FieldLocation actual, FieldLocation expected) {22 return 0;23 }24 });25 fieldComparators.registerComparatorForFieldsMatchingRegexes(".*\\.Name", new FieldLocationComparator() {26 public int compare(FieldLocation actual, FieldLocation expected) {27 return 0;28 }29 });30 }31}

Full Screen

Full Screen

registerComparatorForFieldsMatchingRegexes

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.api.recursive.comparison.FieldComparators;2import org.assertj.core.api.recursive.comparison.RecursiveComparisonConfiguration;3import org.assertj.core.api.recursive.comparison.RecursiveComparisonConfigurationBuilder;4import org.assertj.core.api.recursive.comparison.RecursiveComparisonDifference;5import java.util.regex.Pattern;6public class 1 {7 public static void main(String[] args) {8 RecursiveComparisonConfiguration recursiveComparisonConfiguration = new RecursiveComparisonConfigurationBuilder()9 .registerComparatorForFieldsMatchingRegexes(Pattern.compile(".*"), (o1, o2) -> {10 return RecursiveComparisonDifference.different("always different");11 })12 .build();13 }14}15 .registerComparatorForFieldsMatchingRegexes(Pattern.compile(".*"), (o1, o2) -> {16 symbol: method registerComparatorForFieldsMatchingRegexes(Pattern,lambda expression)

Full Screen

Full Screen

registerComparatorForFieldsMatchingRegexes

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.api.recursive.comparison.FieldComparators;2import org.junit.Test;3import org.junit.runner.RunWith;4import org.springframework.beans.factory.annotation.Autowired;5import org.springframework.boot.test.context.SpringBootTest;6import org.springframework.test.context.junit4.SpringRunner;7import java.util.regex.Pattern;8import static org.assertj.core.api.Assertions.assertThat;9import static org.assertj.core.api.recursive.comparison.FieldComparators.registerComparatorForFieldsMatchingRegexes;10import static org.assertj.core.api.recursive.comparison.RecursiveComparisonConfiguration.builder;11import static org.assertj.core.api.recursive.comparison.RecursiveComparisonConfiguration.recursiveComparison;12import static org.assertj.core.api.recursive.comparison.RecursiveComparisonConfiguration.withStrictTypeChecking;13@RunWith(SpringRunner.class)14public class TestClass {15 private EmployeeService employeeService;16 public void test1() {17 Employee employee = employeeService.getEmployee();18 Employee employee1 = new Employee();19 employee1.setId(1);20 employee1.setFirstName("John");21 employee1.setLastName("Doe");22 employee1.setSalary(1000);23 employee1.setAge(30);24 employee1.setAddress("123 Main St.");25 employee1.setCity("Anytown");26 employee1.setState("CA");27 employee1.setZipCode("12345");28 employee1.setPhone("123-456-7890");29 employee1.setSsn("123-45-6789");30 employee1.setDepartment("IT");31 employee1.setManagerId(1);32 employee1.setManagerName("Jane Doe");33 employee1.setManagerEmail("

Full Screen

Full Screen

registerComparatorForFieldsMatchingRegexes

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.api.recursive.comparison.RecursiveComparisonConfiguration;2import org.assertj.core.api.recursive.comparison.FieldComparators;3import org.assertj.core.api.recursive.comparison.FieldLocation;4public class Main {5 public static void main(String[] args) {6 RecursiveComparisonConfiguration config = new RecursiveComparisonConfiguration();7 FieldComparators comparators = config.getFieldComparators();8 comparators.registerComparatorForFieldsMatchingRegexes(".*\\.age", (fieldLocation, fieldValue1, fieldValue2) -> {9 return true;10 });11 }12}13import org.assertj.core.api.recursive.comparison.RecursiveComparisonConfiguration;14import org.assertj.core.api.recursive.comparison.FieldComparators;15import org.assertj.core.api.recursive.comparison.FieldLocation;16public class Main {17 public static void main(String[] args) {18 RecursiveComparisonConfiguration config = new RecursiveComparisonConfiguration();19 FieldComparators comparators = config.getFieldComparators();20 comparators.registerComparatorForFieldsMatchingRegexes(".*\\.age", (fieldLocation, fieldValue1, fieldValue2) -> {21 return false;22 });23 }24}25import org.assertj.core.api.recursive.comparison.RecursiveComparisonConfiguration;26import org.assertj.core.api.recursive.comparison.FieldComparators;27import org.assertj.core.api.recursive.comparison.FieldLocation;28public class Main {29 public static void main(String[] args) {30 RecursiveComparisonConfiguration config = new RecursiveComparisonConfiguration();31 FieldComparators comparators = config.getFieldComparators();32 comparators.registerComparatorForFieldsMatchingRegexes(".*\\.age", (fieldLocation, fieldValue1, fieldValue2) -> {33 return fieldValue1.equals(fieldValue2);34 });35 }36}37import org.assertj.core.api.recursive.comparison.RecursiveComparisonConfiguration;38import org.assertj.core.api.recursive.comparison.FieldComparators;39import org.assertj.core.api.recursive.comparison.FieldLocation;40public class Main {41 public static void main(String[] args) {

Full Screen

Full Screen

registerComparatorForFieldsMatchingRegexes

Using AI Code Generation

copy

Full Screen

1package com.zetcode;2import org.assertj.core.api.recursive.comparison.FieldComparators;3import org.assertj.core.api.recursive.comparison.RecursiveComparisonConfiguration;4import org.assertj.core.api.recursive.comparison.RecursiveComparisonDifference;5import java.util.List;6import java.util.regex.Pattern;7public class AssertJRecursiveComparison {8 public static void main(String[] args) {9 var p1 = new Person("John", "Doe", "

Full Screen

Full Screen

registerComparatorForFieldsMatchingRegexes

Using AI Code Generation

copy

Full Screen

1public class Main {2 public static void main(String[] args) {3 FieldComparators.registerComparatorForFieldsMatchingRegexes(".*Id$", (o1, o2) -> {4 return true;5 });6 }7}8public class Main {9 public static void main(String[] args) {10 FieldComparators.registerComparatorForFieldsMatchingRegexes(".*Id$", (o1, o2) -> {11 return true;12 });13 }14}15public class Main {16 public static void main(String[] args) {17 FieldComparators.registerComparatorForFieldsMatchingRegexes(".*Id$", (o1, o2) -> {18 return true;19 });20 }21}22public class Main {23 public static void main(String[] args) {24 FieldComparators.registerComparatorForFieldsMatchingRegexes(".*Id$", (o1, o2) -> {25 return true;26 });27 }28}29public class Main {30 public static void main(String[] args) {31 FieldComparators.registerComparatorForFieldsMatchingRegexes(".*Id$", (o1, o2) -> {32 return true;33 });34 }35}

Full Screen

Full Screen

registerComparatorForFieldsMatchingRegexes

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.api.recursive.comparison.FieldComparators;2import org.assertj.core.api.recursive.comparison.FieldLocation;3import org.assertj.core.api.recursive.comparison.FieldLocation.FieldLocationBuilder;4import org.assertj.core.api.recursive.comparison.RecursiveComparisonConfiguration;5import org.assertj.core.api.recursive.comparison.RecursiveComparisonDifference;6import org.assertj.core.api.recursive.comparison.RecursiveComparisonDifference.DifferenceType;7import java.util.List;8import java.util.regex.Pattern;9public class 1 {10 public static void main(String[] args) {11 User user1 = new User("John", "Doe", "

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.

Run Assertj automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful