How to use should_ignore_actual_null_fields method of org.assertj.core.api.recursive.comparison.RecursiveComparisonConfiguration_shouldIgnoreFields_Test class

Best Assertj code snippet using org.assertj.core.api.recursive.comparison.RecursiveComparisonConfiguration_shouldIgnoreFields_Test.should_ignore_actual_null_fields

Source:RecursiveComparisonConfiguration_shouldIgnoreFields_Test.java Github

copy

Full Screen

...49 then(fields).containsExactlyInAnyOrder("foo", "bar", "foo.bar");50 }51 @ParameterizedTest(name = "{0} should be ignored")52 @MethodSource53 void should_ignore_actual_null_fields(DualValue dualValue) {54 // GIVEN55 recursiveComparisonConfiguration.setIgnoreAllActualNullFields(true);56 // WHEN57 boolean ignored = recursiveComparisonConfiguration.shouldIgnore(dualValue);58 // THEN59 then(ignored).as("%s should be ignored", dualValue).isTrue();60 }61 private static Stream<Arguments> should_ignore_actual_null_fields() {62 return Stream.of(arguments(dualValue(null, "John")),63 arguments(dualValue(null, 123)),64 arguments(dualValue(null, null)),65 arguments(dualValue(null, new Date())));66 }67 @ParameterizedTest(name = "{0} should be ignored")68 @MethodSource69 void should_ignore_actual_optional_empty_fields(DualValue dualValue) {70 // GIVEN71 recursiveComparisonConfiguration.setIgnoreAllActualEmptyOptionalFields(true);72 // WHEN73 boolean ignored = recursiveComparisonConfiguration.shouldIgnore(dualValue);74 // THEN75 then(ignored).as("%s should be ignored", dualValue).isTrue();76 }77 private static Stream<Arguments> should_ignore_actual_optional_empty_fields() {78 return Stream.of(arguments(dualValue(Optional.empty(), "John")),79 arguments(dualValue(Optional.empty(), Optional.of("John"))),80 arguments(dualValue(OptionalInt.empty(), OptionalInt.of(123))),81 arguments(dualValue(OptionalLong.empty(), OptionalLong.of(123L))),82 arguments(dualValue(OptionalDouble.empty(), OptionalDouble.of(123.0))));83 }84 @ParameterizedTest(name = "{0} should be ignored")85 @MethodSource86 void should_ignore_expected_null_fields(DualValue dualValue) {87 // GIVEN88 recursiveComparisonConfiguration.setIgnoreAllExpectedNullFields(true);89 // WHEN90 boolean ignored = recursiveComparisonConfiguration.shouldIgnore(dualValue);91 // THEN92 then(ignored).as("%s should be ignored", dualValue).isTrue();93 }94 private static Stream<Arguments> should_ignore_expected_null_fields() {95 return Stream.of(arguments(dualValue("John", null)),96 arguments(dualValue(123, null)),97 arguments(dualValue(null, null)),98 arguments(dualValue(new Date(), null)));99 }100 @ParameterizedTest(name = "{0} should be ignored with these ignored fields {1}")101 @MethodSource102 void should_ignore_specified_fields(DualValue dualValue, List<String> ignoredFields) {103 // GIVEN104 recursiveComparisonConfiguration.ignoreFields(ignoredFields.toArray(new String[0]));105 // WHEN106 boolean ignored = recursiveComparisonConfiguration.shouldIgnore(dualValue);107 // THEN108 then(ignored).as("%s should be ignored with these ignored fields %s", dualValue, ignoredFields).isTrue();109 }110 private static Stream<Arguments> should_ignore_specified_fields() {111 return Stream.of(arguments(dualValueWithPath("name"), list("name")),112 arguments(dualValueWithPath("name"), list("foo", "name", "foo")),113 arguments(dualValueWithPath("name", "first"), list("name.first")),114 arguments(dualValueWithPath("name", "[2]", "first"), list("name.first")),115 arguments(dualValueWithPath("[0]", "first"), list("first")),116 arguments(dualValueWithPath("[1]", "first", "second"), list("first.second")),117 arguments(dualValueWithPath("father", "name", "first"), list("father", "name.first", "father.name.first")));118 }119 @Test120 void ignoring_fields_with_regex_does_not_replace_previous_regexes() {121 // WHEN122 recursiveComparisonConfiguration.ignoreFieldsMatchingRegexes("foo");123 recursiveComparisonConfiguration.ignoreFieldsMatchingRegexes("bar", "baz");124 // THEN125 then(recursiveComparisonConfiguration.getIgnoredFieldsRegexes()).extracting(Pattern::pattern)126 .containsExactlyInAnyOrder("foo", "bar", "baz");127 }128 @ParameterizedTest(name = "{0} should be ignored with these regexes {1}")129 @MethodSource130 void should_ignore_fields_matching_given_regexes(DualValue dualValue, List<String> regexes) {131 // GIVEN132 recursiveComparisonConfiguration.ignoreFieldsMatchingRegexes(regexes.toArray(new String[0]));133 // WHEN134 boolean ignored = recursiveComparisonConfiguration.shouldIgnore(dualValue);135 // THEN136 then(ignored).as("%s should be ignored with these regexes %s", dualValue, regexes).isTrue();137 }138 private static Stream<Arguments> should_ignore_fields_matching_given_regexes() {139 return Stream.of(arguments(dualValueWithPath("name"), list(".*name")),140 arguments(dualValueWithPath("name"), list("foo", "n.m.", "foo")),141 arguments(dualValueWithPath("name", "first"), list("name\\.first")),142 arguments(dualValueWithPath("name", "first"), list(".*first")),143 arguments(dualValueWithPath("name", "first"), list("name.*")),144 arguments(dualValueWithPath("name", "[2]", "first"), list("name\\.first")),145 arguments(dualValueWithPath("[0]", "first"), list("fir.*")),146 arguments(dualValueWithPath("[1]", "first", "second"), list("f..st\\..*nd")),147 arguments(dualValueWithPath("father", "name", "first"),148 list("father", "name.first", "father\\.name\\.first")));149 }150 @ParameterizedTest(name = "{0} should be ignored")151 @MethodSource152 void should_ignore_fields(DualValue dualValue) {153 // GIVEN154 recursiveComparisonConfiguration.ignoreFieldsMatchingRegexes(".*name");155 recursiveComparisonConfiguration.ignoreFields("number");156 recursiveComparisonConfiguration.ignoreFieldsOfTypes(String.class);157 // WHEN158 boolean ignored = recursiveComparisonConfiguration.shouldIgnore(dualValue);159 // THEN160 then(ignored).as("%s should be ignored", dualValue).isTrue();161 }162 private static Stream<Arguments> should_ignore_fields() {163 return Stream.of(arguments(dualValueWithPath("name")),164 arguments(dualValueWithPath("number")),165 arguments(dualValueWithPath("surname")),166 arguments(dualValueWithPath("first", "name")),167 arguments(new DualValue(randomPath(), "actual", "expected")));168 }169 @Test170 void ignoring_fields_for_types_does_not_replace_previous_ignored_types() {171 // WHEN172 recursiveComparisonConfiguration.ignoreFieldsOfTypes(UUID.class);173 recursiveComparisonConfiguration.ignoreFieldsOfTypes(ZonedDateTime.class, String.class);174 // THEN175 then(recursiveComparisonConfiguration.getIgnoredTypes()).containsExactlyInAnyOrder(UUID.class, ZonedDateTime.class,176 String.class);177 }178 @ParameterizedTest(name = "{0} should be ignored with these ignored types {1}")179 @MethodSource180 void should_ignore_fields_for_specified_types(DualValue dualValue, List<Class<?>> ignoredTypes) {181 // GIVEN182 recursiveComparisonConfiguration.ignoreFieldsOfTypes(ignoredTypes.toArray(new Class<?>[0]));183 // WHEN184 boolean ignored = recursiveComparisonConfiguration.shouldIgnore(dualValue);185 // THEN186 then(ignored).as("%s should be ignored with these ignored types %s", dualValue, ignoredTypes)187 .isTrue();188 }189 private static Stream<Arguments> should_ignore_fields_for_specified_types() {190 return Stream.of(arguments(new DualValue(randomPath(), "actual", "expected"), list(String.class)),191 arguments(new DualValue(randomPath(), randomUUID(), randomUUID()), list(String.class, UUID.class)));192 }193 @Test194 void should_return_false_if_the_field_type_is_not_ignored() {195 // GIVEN196 DualValue dualValue = new DualValue(randomPath(), "actual", "expected");197 recursiveComparisonConfiguration.ignoreFieldsOfTypes(UUID.class);198 // WHEN199 boolean ignored = recursiveComparisonConfiguration.shouldIgnore(dualValue);200 // THEN201 then(ignored).isFalse();202 }203 @Test204 void should_be_able_to_ignore_boolean() {205 // GIVEN206 DualValue dualValue = new DualValue(randomPath(), true, false);207 recursiveComparisonConfiguration.ignoreFieldsOfTypes(boolean.class);208 // WHEN209 boolean ignored = recursiveComparisonConfiguration.shouldIgnore(dualValue);210 // THEN211 then(ignored).isTrue();212 }213 @Test214 void should_be_able_to_ignore_byte() {215 // GIVEN216 DualValue dualValue = new DualValue(randomPath(), (byte) 0, (byte) 1);217 recursiveComparisonConfiguration.ignoreFieldsOfTypes(byte.class);218 // WHEN219 boolean ignored = recursiveComparisonConfiguration.shouldIgnore(dualValue);220 // THEN221 then(ignored).isTrue();222 }223 @Test224 void should_be_able_to_ignore_char() {225 // GIVEN226 DualValue dualValue = new DualValue(randomPath(), 'a', 'b');227 recursiveComparisonConfiguration.ignoreFieldsOfTypes(char.class);228 // WHEN229 boolean ignored = recursiveComparisonConfiguration.shouldIgnore(dualValue);230 // THEN231 then(ignored).isTrue();232 }233 @Test234 void should_be_able_to_ignore_short() {235 // GIVEN236 DualValue dualValue = new DualValue(randomPath(), (short) 123, (short) 123);237 recursiveComparisonConfiguration.ignoreFieldsOfTypes(short.class);238 // WHEN239 boolean ignored = recursiveComparisonConfiguration.shouldIgnore(dualValue);240 // THEN241 then(ignored).isTrue();242 }243 @Test244 void should_be_able_to_ignore_int() {245 // GIVEN246 DualValue dualValue = new DualValue(randomPath(), 123, 123);247 recursiveComparisonConfiguration.ignoreFieldsOfTypes(int.class);248 // WHEN249 boolean ignored = recursiveComparisonConfiguration.shouldIgnore(dualValue);250 // THEN251 then(ignored).isTrue();252 }253 @Test254 void should_be_able_to_ignore_float() {255 // GIVEN256 DualValue dualValue = new DualValue(randomPath(), 123.0f, 123.0f);257 recursiveComparisonConfiguration.ignoreFieldsOfTypes(float.class);258 // WHEN259 boolean ignored = recursiveComparisonConfiguration.shouldIgnore(dualValue);260 // THEN261 then(ignored).isTrue();262 }263 @Test264 void should_be_able_to_ignore_double() {265 // GIVEN266 DualValue dualValue = new DualValue(randomPath(), 123.0, 123.0);267 recursiveComparisonConfiguration.ignoreFieldsOfTypes(double.class);268 // WHEN269 boolean ignored = recursiveComparisonConfiguration.shouldIgnore(dualValue);270 // THEN271 then(ignored).isTrue();272 }273 @ParameterizedTest(name = "{0} should be ignored by specifying to ignore {1}")274 @MethodSource275 void should_be_able_to_ignore_primitive_field_by_specifying_their_wrapper_type(Object fieldValue, Class<?> wrapperType) {276 // GIVEN277 DualValue dualValue = new DualValue(randomPath(), fieldValue, fieldValue);278 recursiveComparisonConfiguration.ignoreFieldsOfTypes(wrapperType);279 // WHEN280 boolean ignored = recursiveComparisonConfiguration.shouldIgnore(dualValue);281 // THEN282 then(ignored).isTrue();283 }284 private static Stream<Arguments> should_be_able_to_ignore_primitive_field_by_specifying_their_wrapper_type() {285 return Stream.of(arguments(false, Boolean.class),286 arguments((byte) 0, Byte.class),287 arguments('b', Character.class),288 arguments(123, Integer.class),289 arguments(123.0f, Float.class),290 arguments(123.0, Double.class),291 arguments((short) 123, Short.class));292 }293 @Test294 void should_return_false_if_the_field_type_is_subtype_of_an_ignored_type() {295 // GIVEN296 DualValue dualValue = new DualValue(randomPath(), Double.MAX_VALUE, "expected");297 recursiveComparisonConfiguration.ignoreFieldsOfTypes(Number.class);298 // WHEN299 boolean ignored = recursiveComparisonConfiguration.shouldIgnore(dualValue);300 // THEN301 then(ignored).isFalse();302 }303 @Test304 void should_not_ignore_actual_null_fields_for_specified_types_if_strictTypeChecking_is_disabled() {305 // GIVEN306 DualValue dualValue = new DualValue(randomPath(), null, "expected");307 recursiveComparisonConfiguration.strictTypeChecking(false);308 recursiveComparisonConfiguration.ignoreFieldsOfTypes(String.class);309 // WHEN310 boolean ignored = recursiveComparisonConfiguration.shouldIgnore(dualValue);311 // THEN312 then(ignored).isFalse();313 }314 @Test315 void should_ignore_actual_null_fields_for_specified_types_if_strictTypeChecking_is_enabled_and_expected_is_not_null() {316 // GIVEN317 DualValue dualValue = new DualValue(randomPath(), null, "expected");318 recursiveComparisonConfiguration.strictTypeChecking(true);319 recursiveComparisonConfiguration.ignoreFieldsOfTypes(String.class);320 // WHEN321 boolean ignored = recursiveComparisonConfiguration.shouldIgnore(dualValue);322 // THEN323 then(ignored).isTrue();324 }325 @ParameterizedTest(name = "{0} should be compared: {1}")326 @MethodSource327 void should_honor_compared_fields(DualValue dualValue, boolean toCompare) {328 // GIVEN329 recursiveComparisonConfiguration.compareOnlyFields("number", "name", "address.street.geolocation", "person.children");...

Full Screen

Full Screen

should_ignore_actual_null_fields

Using AI Code Generation

copy

Full Screen

1import static org.assertj.core.api.Assertions.assertThat;2import static org.assertj.core.api.recursive.comparison.RecursiveComparisonConfiguration.shouldIgnoreFields;3import static org.assertj.core.util.Lists.list;4import java.util.List;5import org.assertj.core.api.recursive.comparison.RecursiveComparisonConfiguration;6import org.junit.Test;7public class RecursiveComparisonConfiguration_shouldIgnoreFields_Test {8 public void should_ignore_fields() {9 List<String> fieldsToIgnore = list("name");10 RecursiveComparisonConfiguration recursiveComparisonConfiguration = shouldIgnoreFields(fieldsToIgnore);11 boolean ignoreActualNullFields = recursiveComparisonConfiguration.shouldIgnoreActualNullFields();12 assertThat(ignoreActualNullFields).isFalse();13 }14}

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