How to use extract method of org.assertj.core.api.iterable.IterableAssert_extracting_with_SortedSet_Test class

Best Assertj code snippet using org.assertj.core.api.iterable.IterableAssert_extracting_with_SortedSet_Test.extract

Source:IterableAssert_extracting_with_SortedSet_Test.java Github

copy

Full Screen

...28import static org.assertj.core.data.TolkienCharacter.Race.ELF;29import static org.assertj.core.data.TolkienCharacter.Race.HOBBIT;30import static org.assertj.core.data.TolkienCharacter.Race.MAIA;31import static org.assertj.core.data.TolkienCharacter.Race.MAN;32import static org.assertj.core.extractor.Extractors.byName;33import static org.assertj.core.presentation.UnicodeRepresentation.UNICODE_REPRESENTATION;34import static org.assertj.core.test.AlwaysEqualComparator.ALWAY_EQUALS_STRING;35import static org.assertj.core.test.AlwaysEqualComparator.ALWAY_EQUALS_TIMESTAMP;36import static org.assertj.core.test.AlwaysEqualComparator.ALWAY_EQUALS_TUPLE;37import static org.assertj.core.util.Lists.list;38import java.sql.Timestamp;39import java.util.SortedSet;40import java.util.TreeSet;41import java.util.function.Function;42import org.assertj.core.api.AbstractListAssert;43import org.assertj.core.data.TolkienCharacter;44import org.assertj.core.extractor.Extractors;45import org.assertj.core.groups.Tuple;46import org.assertj.core.test.Employee;47import org.assertj.core.test.Name;48import org.assertj.core.util.introspection.IntrospectionError;49import org.junit.jupiter.api.BeforeEach;50import org.junit.jupiter.api.Test;51class IterableAssert_extracting_with_SortedSet_Test {52 private Employee yoda;53 private Employee luke;54 private SortedSet<Employee> jedis;55 private SortedSet<TolkienCharacter> fellowshipOfTheRing;56 @SuppressWarnings("deprecation")57 private static final Extractor<Employee, String> firstName = new Extractor<Employee, String>() {58 @Override59 public String extract(Employee input) {60 return input.getName().getFirst();61 }62 };63 private static final Function<Employee, Integer> age = Employee::getAge;64 private static final ThrowingExtractor<Employee, Object, Exception> throwingExtractor = new ThrowingExtractor<Employee, Object, Exception>() {65 @Override66 public Object extractThrows(Employee employee) throws Exception {67 if (employee.getAge() < 20) throw new Exception("age < 20");68 return employee.getName().getFirst();69 }70 };71 @BeforeEach72 void setUp() {73 yoda = new Employee(1L, new Name("Yoda"), 800);74 luke = new Employee(2L, new Name("Luke", "Skywalker"), 26);75 jedis = new TreeSet<>(comparing(Employee::getAge));76 jedis.add(luke);77 jedis.add(yoda);78 fellowshipOfTheRing = new TreeSet<>(comparing(TolkienCharacter::getName));79 fellowshipOfTheRing.add(TolkienCharacter.of("Frodo", 33, HOBBIT));80 fellowshipOfTheRing.add(TolkienCharacter.of("Sam", 38, HOBBIT));81 fellowshipOfTheRing.add(TolkienCharacter.of("Gandalf", 2020, MAIA));82 fellowshipOfTheRing.add(TolkienCharacter.of("Legolas", 1000, ELF));83 fellowshipOfTheRing.add(TolkienCharacter.of("Pippin", 28, HOBBIT));84 fellowshipOfTheRing.add(TolkienCharacter.of("Gimli", 139, DWARF));85 fellowshipOfTheRing.add(TolkienCharacter.of("Aragorn", 87, MAN));86 fellowshipOfTheRing.add(TolkienCharacter.of("Boromir", 37, MAN));87 setRemoveAssertJRelatedElementsFromStackTrace(false);88 }89 @Test90 void should_allow_assertions_on_property_values_extracted_from_given_iterable() {91 assertThat(jedis).extracting("age")92 .as("extract property backed by a private field")93 .containsOnly(800, 26);94 assertThat(jedis).extracting("adult")95 .as("extract pure property")96 .containsOnly(true, true);97 assertThat(jedis).extracting("name.first")98 .as("nested property")99 .containsOnly("Yoda", "Luke");100 assertThat(jedis).extracting("name")101 .as("extract field that is also a property")102 .containsOnly(new Name("Yoda"), new Name("Luke", "Skywalker"));103 assertThat(jedis).extracting("name", Name.class)104 .as("extract field that is also a property but specifying the extracted type")105 .containsOnly(new Name("Yoda"), new Name("Luke", "Skywalker"));106 }107 @Test108 void should_allow_assertions_on_null_property_values_extracted_from_given_iterable() {109 yoda.name.setFirst(null);110 assertThat(jedis).extracting("name.first")111 .as("not null property but null nested property")112 .containsOnly(null, "Luke");113 yoda.setName(null);114 assertThat(jedis).extracting("name.first")115 .as("extract nested property when top property is null")116 .containsOnly(null, "Luke");117 assertThat(jedis).extracting("name")118 .as("null property")119 .containsOnly(null, new Name("Luke", "Skywalker"));120 }121 @Test122 void should_allow_assertions_on_field_values_extracted_from_given_iterable() {123 assertThat(jedis).extracting("id")124 .as("extract field")125 .containsOnly(1L, 2L);126 assertThat(jedis).extracting("surname")127 .as("null field")128 .containsNull();129 assertThat(jedis).extracting("surname.first")130 .as("null nested field")131 .containsNull();132 yoda.surname = new Name();133 assertThat(jedis).extracting("surname.first")134 .as("not null field but null nested field")135 .containsNull();136 yoda.surname = new Name("Master");137 assertThat(jedis).extracting("surname.first")138 .as("nested field")139 .containsOnly("Master", null);140 assertThat(jedis).extracting("surname", Name.class)141 .as("extract field specifying the extracted type")142 .containsOnly(new Name("Master"), null);143 }144 @Test145 void should_allow_assertions_on_property_values_extracted_from_given_iterable_with_extracted_type_defined() {146 // extract field that is also a property and check generic for comparator.147 assertThat(jedis).extracting("name", Name.class)148 .usingElementComparator((o1, o2) -> o1.getFirst().compareTo(o2.getFirst()))149 .containsOnly(new Name("Yoda"), new Name("Luke", "Skywalker"));150 }151 @Test152 void should_throw_error_if_no_property_nor_field_with_given_name_can_be_extracted() {153 assertThatExceptionOfType(IntrospectionError.class).isThrownBy(() -> assertThat(jedis).extracting("unknown"));154 }155 @Test156 void should_allow_assertions_on_multiple_extracted_values_from_given_iterable() {157 assertThat(jedis).extracting("name.first", "age", "id").containsOnly(tuple("Yoda", 800, 1L),158 tuple("Luke", 26, 2L));159 }160 @Test161 void should_throw_error_if_one_property_or_field_can_not_be_extracted() {162 assertThatExceptionOfType(IntrospectionError.class).isThrownBy(() -> {163 assertThat(jedis).extracting("unknown", "age", "id")164 .containsOnly(tuple("Yoda", 800, 1L), tuple("Luke", 26, 2L));165 });166 }167 @Test168 void should_allow_extracting_single_values_using_extractor() {169 assertThat(jedis).extracting(firstName).containsOnly("Yoda", "Luke");170 assertThat(jedis).extracting(age).containsOnly(26, 800);171 }172 @SuppressWarnings("deprecation")173 @Test174 void should_allow_assertions_on_extractor_assertions_extracted_from_given_array_compatibility_runtimeexception() {175 assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> assertThat(jedis).extracting(new Extractor<Employee, String>() {176 @Override177 public String extract(Employee input) {178 if (input.getAge() > 100) {179 throw new RuntimeException("age > 100");180 }181 return input.getName().getFirst();182 }183 }));184 }185 @Test186 void should_allow_assertions_on_extractor_assertions_extracted_from_given_array() {187 assertThat(jedis).extracting(input -> input.getName().getFirst()).containsOnly("Yoda", "Luke");188 }189 @Test190 void should_rethrow_throwing_extractor_checked_exception_as_a_runtime_exception() {191 assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> assertThat(jedis).extracting(employee -> {192 if (employee.getAge() > 100) throw new Exception("age > 100");193 return employee.getName().getFirst();194 })).withMessage("java.lang.Exception: age > 100");195 }196 @Test197 void should_let_throwing_extractor_runtime_exception_bubble_up() {198 assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> assertThat(jedis).extracting(employee -> {199 if (employee.getAge() > 100) throw new RuntimeException("age > 100");200 return employee.getName().getFirst();201 })).withMessage("age > 100");202 }203 @Test204 void should_allow_extracting_with_throwing_extractor() {205 assertThat(jedis).extracting(employee -> {206 if (employee.getAge() < 20) throw new Exception("age < 20");207 return employee.getName().getFirst();208 }).containsOnly("Yoda", "Luke");209 }210 @Test211 void should_allow_extracting_with_anonymous_class_throwing_extractor() {212 assertThat(jedis).extracting(new ThrowingExtractor<Employee, Object, Exception>() {213 @Override214 public Object extractThrows(Employee employee) throws Exception {215 if (employee.getAge() < 20) throw new Exception("age < 20");216 return employee.getName().getFirst();217 }218 }).containsOnly("Yoda", "Luke");219 }220 @SuppressWarnings("deprecation")221 @Test222 void should_allow_extracting_multiple_values_using_extractor() {223 assertThat(jedis).extracting(new Extractor<Employee, Tuple>() {224 @Override225 public Tuple extract(Employee input) {226 return new Tuple(input.getName().getFirst(), input.getAge(), input.id);227 }228 }).containsOnly(tuple("Yoda", 800, 1L), tuple("Luke", 26, 2L));229 }230 @Test231 void should_allow_extracting_by_toString_method() {232 assertThat(jedis).extracting(Extractors.toStringMethod())233 .containsOnly("Employee[id=1, name=Name[first='Yoda', last='null'], age=800]",234 "Employee[id=2, name=Name[first='Luke', last='Skywalker'], age=26]");235 }236 @Test237 void should_allow_assertions_by_using_function_extracted_from_given_iterable() {238 assertThat(fellowshipOfTheRing).extracting(TolkienCharacter::getName)239 .contains("Boromir", "Gandalf", "Frodo")240 .doesNotContain("Sauron", "Elrond");241 }242 @Test243 void should_throw_error_if_function_fails() {244 RuntimeException thrown = new RuntimeException();245 assertThatThrownBy(() -> assertThat(fellowshipOfTheRing).extracting(e -> {246 throw thrown;247 }).isEqualTo(thrown));248 }249 @Test250 void should_allow_assertions_on_two_extracted_values_from_given_iterable_by_using_a_function() {251 assertThat(fellowshipOfTheRing).extracting(TolkienCharacter::getName,252 TolkienCharacter::getAge)253 .containsOnly(tuple("Frodo", 33),254 tuple("Sam", 38),255 tuple("Gandalf", 2020),256 tuple("Legolas", 1000),257 tuple("Pippin", 28),258 tuple("Gimli", 139),259 tuple("Aragorn", 87),260 tuple("Boromir", 37));261 }262 @Test263 void should_allow_assertions_on_three_extracted_values_from_given_iterable_by_using_a_function() {264 assertThat(fellowshipOfTheRing).extracting(TolkienCharacter::getName,265 TolkienCharacter::getAge,266 TolkienCharacter::getRace)267 .containsOnly(tuple("Frodo", 33, TolkienCharacter.Race.HOBBIT),268 tuple("Sam", 38, HOBBIT),269 tuple("Gandalf", 2020, MAIA),270 tuple("Legolas", 1000, ELF),271 tuple("Pippin", 28, HOBBIT),272 tuple("Gimli", 139, DWARF),273 tuple("Aragorn", 87, MAN),274 tuple("Boromir", 37, MAN));275 }276 @Test277 void should_allow_assertions_on_four_extracted_values_from_given_iterable_by_using_a_function() {278 assertThat(fellowshipOfTheRing).extracting(TolkienCharacter::getName,279 TolkienCharacter::getAge,280 TolkienCharacter::getRace,281 character -> character.name)282 .containsOnly(tuple("Frodo", 33, HOBBIT, "Frodo"),283 tuple("Sam", 38, HOBBIT, "Sam"),284 tuple("Gandalf", 2020, MAIA, "Gandalf"),285 tuple("Legolas", 1000, ELF, "Legolas"),286 tuple("Pippin", 28, HOBBIT, "Pippin"),287 tuple("Gimli", 139, DWARF, "Gimli"),288 tuple("Aragorn", 87, MAN, "Aragorn"),289 tuple("Boromir", 37, MAN, "Boromir"));290 }291 @Test292 void should_allow_assertions_on_five_extracted_values_from_given_iterable_by_using_a_function() {293 assertThat(fellowshipOfTheRing).extracting(TolkienCharacter::getName,294 TolkienCharacter::getAge,295 TolkienCharacter::getRace,296 character -> character.name,297 character -> character.age)298 .containsOnly(tuple("Frodo", 33, HOBBIT, "Frodo", 33),299 tuple("Sam", 38, HOBBIT, "Sam", 38),300 tuple("Gandalf", 2020, MAIA, "Gandalf", 2020),301 tuple("Legolas", 1000, ELF, "Legolas", 1000),302 tuple("Pippin", 28, HOBBIT, "Pippin", 28),303 tuple("Gimli", 139, DWARF, "Gimli", 139),304 tuple("Aragorn", 87, MAN, "Aragorn", 87),305 tuple("Boromir", 37, MAN, "Boromir", 37));306 }307 @Test308 void should_allow_assertions_on_more_than_five_extracted_values_from_given_iterable_by_using_a_function() {309 assertThat(fellowshipOfTheRing).extracting(TolkienCharacter::getName,310 TolkienCharacter::getAge,311 TolkienCharacter::getRace,312 character -> character.name,313 character -> character.age,314 character -> character.race)315 .containsOnly(tuple("Frodo", 33, HOBBIT, "Frodo", 33, HOBBIT),316 tuple("Sam", 38, HOBBIT, "Sam", 38, HOBBIT),317 tuple("Gandalf", 2020, MAIA, "Gandalf", 2020, MAIA),318 tuple("Legolas", 1000, ELF, "Legolas", 1000, ELF),319 tuple("Pippin", 28, HOBBIT, "Pippin", 28, HOBBIT),320 tuple("Gimli", 139, DWARF, "Gimli", 139, DWARF),321 tuple("Aragorn", 87, MAN, "Aragorn", 87, MAN),322 tuple("Boromir", 37, MAN, "Boromir", 37, MAN));323 }324 @Test325 void should_use_property_field_names_as_description_when_extracting_simple_value_list() {326 assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> assertThat(jedis).extracting("name.first").isEmpty()).withMessageContaining("[Extracted: name.first]");327 }328 @Test329 void should_use_property_field_names_as_description_when_extracting_typed_simple_value_list() {330 assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> assertThat(jedis).extracting("name.first", String.class).isEmpty()).withMessageContaining("[Extracted: name.first]");331 }332 @Test333 void should_use_property_field_names_as_description_when_extracting_tuples_list() {334 assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> assertThat(jedis).extracting("name.first",335 "name.last")336 .isEmpty())337 .withMessageContaining("[Extracted: name.first, name.last]");338 }339 @Test340 void should_keep_existing_description_if_set_when_extracting_typed_simple_value_list() {341 assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> assertThat(jedis).as("check employees first name")342 .extracting("name.first",343 String.class)344 .isEmpty())345 .withMessageContaining("[check employees first name]");346 }347 @Test348 void should_keep_existing_description_if_set_when_extracting_tuples_list() {349 assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> assertThat(jedis).as("check employees name")350 .extracting("name.first",351 "name.last")352 .isEmpty())353 .withMessageContaining("[check employees name]");354 }355 @Test356 void should_keep_existing_description_if_set_when_extracting_simple_value_list() {357 assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> assertThat(jedis).as("check employees first name")358 .extracting("name.first")359 .isEmpty())360 .withMessageContaining("[check employees first name]");361 }362 @SuppressWarnings("deprecation")363 @Test364 void should_keep_existing_description_if_set_when_extracting_using_extractor() {365 assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> assertThat(jedis).as("check employees first name")366 .extracting(new Extractor<Employee, String>() {367 @Override368 public String extract(Employee input) {369 return input.getName()370 .getFirst();371 }372 }).isEmpty())373 .withMessageContaining("[check employees first name]");374 }375 @Test376 void should_keep_existing_description_if_set_when_extracting_using_throwing_extractor() {377 assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> assertThat(jedis).as("expected exception")378 .extracting(throwingExtractor)379 .containsOnly("Luke"))380 .withMessageContaining("[expected exception]");381 }382 @Test383 void should_extract_tuples_according_to_given_functions() {384 assertThat(jedis).extracting(firstNameFunction, lastNameFunction)385 .contains(tuple("Yoda", null), tuple("Luke", "Skywalker"));386 }387 @Test388 void extracting_by_several_functions_should_keep_assertion_state() {389 // WHEN390 // not all comparators are used but we want to test that they are passed correctly after extracting391 AbstractListAssert<?, ?, ?, ?> assertion = assertThat(jedis).as("test description")392 .withFailMessage("error message")393 .withRepresentation(UNICODE_REPRESENTATION)394 .usingComparatorForElementFieldsWithNames(ALWAY_EQUALS_STRING,395 "foo")396 .usingComparatorForElementFieldsWithType(ALWAY_EQUALS_TIMESTAMP,397 Timestamp.class)398 .extracting(firstNameFunction, lastNameFunction)399 .usingComparatorForType(ALWAY_EQUALS_TUPLE, Tuple.class)400 .contains(tuple("YODA", null), tuple("Luke", "Skywalker"));401 // THEN402 assertThat(assertion.descriptionText()).isEqualTo("test description");403 assertThat(assertion.info.representation()).isEqualTo(UNICODE_REPRESENTATION);404 assertThat(assertion.info.overridingErrorMessage()).isEqualTo("error message");405 assertThat(comparatorsByTypeOf(assertion).get(Tuple.class)).isSameAs(ALWAY_EQUALS_TUPLE);406 assertThat(comparatorForElementFieldsWithTypeOf(assertion).get(Timestamp.class)).isSameAs(ALWAY_EQUALS_TIMESTAMP);407 assertThat(comparatorForElementFieldsWithNamesOf(assertion).get("foo")).isSameAs(ALWAY_EQUALS_STRING);408 }409 @Test410 void extracting_by_name_should_keep_assertion_state() {411 // WHEN412 // not all comparators are used but we want to test that they are passed correctly after extracting413 AbstractListAssert<?, ?, ?, ?> assertion = assertThat(jedis).as("test description")414 .withFailMessage("error message")415 .withRepresentation(UNICODE_REPRESENTATION)416 .usingComparatorForElementFieldsWithNames(ALWAY_EQUALS_STRING,417 "foo")418 .usingComparatorForElementFieldsWithType(ALWAY_EQUALS_TIMESTAMP,419 Timestamp.class)420 .extracting("name.first")421 .usingComparatorForType(ALWAY_EQUALS_STRING, String.class)422 .contains("YODA", "Luke");423 // THEN424 assertThat(assertion.descriptionText()).isEqualTo("test description");425 assertThat(assertion.info.representation()).isEqualTo(UNICODE_REPRESENTATION);426 assertThat(assertion.info.overridingErrorMessage()).isEqualTo("error message");427 assertThat(comparatorsByTypeOf(assertion).get(String.class)).isSameAs(ALWAY_EQUALS_STRING);428 assertThat(comparatorForElementFieldsWithTypeOf(assertion).get(Timestamp.class)).isSameAs(ALWAY_EQUALS_TIMESTAMP);429 assertThat(comparatorForElementFieldsWithNamesOf(assertion).get("foo")).isSameAs(ALWAY_EQUALS_STRING);430 }431 @Test432 void extracting_by_strongly_typed_name_should_keep_assertion_state() {433 // WHEN434 // not all comparators are used but we want to test that they are passed correctly after extracting435 AbstractListAssert<?, ?, ?, ?> assertion = assertThat(jedis).as("test description")436 .withFailMessage("error message")437 .withRepresentation(UNICODE_REPRESENTATION)438 .usingComparatorForElementFieldsWithNames(ALWAY_EQUALS_STRING,439 "foo")440 .usingComparatorForElementFieldsWithType(ALWAY_EQUALS_TIMESTAMP,441 Timestamp.class)442 .extracting("name.first", String.class)443 .usingComparatorForType(ALWAY_EQUALS_STRING, String.class)444 .contains("YODA", "Luke");445 // THEN446 assertThat(assertion.descriptionText()).isEqualTo("test description");447 assertThat(assertion.info.representation()).isEqualTo(UNICODE_REPRESENTATION);448 assertThat(assertion.info.overridingErrorMessage()).isEqualTo("error message");449 assertThat(comparatorsByTypeOf(assertion).get(String.class)).isSameAs(ALWAY_EQUALS_STRING);450 assertThat(comparatorForElementFieldsWithTypeOf(assertion).get(Timestamp.class)).isSameAs(ALWAY_EQUALS_TIMESTAMP);451 assertThat(comparatorForElementFieldsWithNamesOf(assertion).get("foo")).isSameAs(ALWAY_EQUALS_STRING);452 }453 @Test454 void extracting_by_multiple_names_should_keep_assertion_state() {455 // WHEN456 // not all comparators are used but we want to test that they are passed correctly after extracting457 AbstractListAssert<?, ?, ?, ?> assertion = assertThat(jedis).as("test description")458 .withFailMessage("error message")459 .withRepresentation(UNICODE_REPRESENTATION)460 .usingComparatorForElementFieldsWithNames(ALWAY_EQUALS_STRING,461 "foo")462 .usingComparatorForElementFieldsWithType(ALWAY_EQUALS_TIMESTAMP,463 Timestamp.class)464 .extracting("name.first", "name.last")465 .usingComparatorForType(ALWAY_EQUALS_TUPLE, Tuple.class)466 .contains(tuple("YODA", null), tuple("Luke", "Skywalker"));467 // THEN468 assertThat(assertion.descriptionText()).isEqualTo("test description");469 assertThat(assertion.info.representation()).isEqualTo(UNICODE_REPRESENTATION);470 assertThat(assertion.info.overridingErrorMessage()).isEqualTo("error message");471 assertThat(comparatorsByTypeOf(assertion).get(Tuple.class)).isSameAs(ALWAY_EQUALS_TUPLE);472 assertThat(comparatorForElementFieldsWithTypeOf(assertion).get(Timestamp.class)).isSameAs(ALWAY_EQUALS_TIMESTAMP);473 assertThat(comparatorForElementFieldsWithNamesOf(assertion).get("foo")).isSameAs(ALWAY_EQUALS_STRING);474 }475 @Test476 void extracting_by_single_extractor_should_keep_assertion_state() {477 // WHEN478 // not all comparators are used but we want to test that they are passed correctly after extracting479 AbstractListAssert<?, ?, ?, ?> assertion = assertThat(jedis).as("test description")480 .withFailMessage("error message")481 .withRepresentation(UNICODE_REPRESENTATION)482 .usingComparatorForElementFieldsWithNames(ALWAY_EQUALS_STRING,483 "foo")484 .usingComparatorForElementFieldsWithType(ALWAY_EQUALS_TIMESTAMP,485 Timestamp.class)486 .extracting(byName("name.first"))487 .usingComparatorForType(ALWAY_EQUALS_STRING, String.class)488 .contains("YODA", "Luke");489 // THEN490 assertThat(assertion.descriptionText()).isEqualTo("test description");491 assertThat(assertion.info.representation()).isEqualTo(UNICODE_REPRESENTATION);492 assertThat(assertion.info.overridingErrorMessage()).isEqualTo("error message");493 assertThat(comparatorsByTypeOf(assertion).get(String.class)).isSameAs(ALWAY_EQUALS_STRING);494 assertThat(comparatorForElementFieldsWithTypeOf(assertion).get(Timestamp.class)).isSameAs(ALWAY_EQUALS_TIMESTAMP);495 assertThat(comparatorForElementFieldsWithNamesOf(assertion).get("foo")).isSameAs(ALWAY_EQUALS_STRING);496 }497 @Test498 void extracting_by_throwing_extractor_should_keep_assertion_state() {499 // WHEN500 // not all comparators are used but we want to test that they are passed correctly after extracting501 AbstractListAssert<?, ?, ?, ?> assertion = assertThat(jedis).as("test description")502 .withFailMessage("error message")503 .withRepresentation(UNICODE_REPRESENTATION)504 .usingComparatorForElementFieldsWithNames(ALWAY_EQUALS_STRING,505 "foo")506 .usingComparatorForElementFieldsWithType(ALWAY_EQUALS_TIMESTAMP,507 Timestamp.class)508 .extracting(throwingFirstNameExtractor)509 .usingComparatorForType(ALWAY_EQUALS_STRING, String.class)510 .contains("YODA", "Luke");511 // THEN512 assertThat(assertion.descriptionText()).isEqualTo("test description");513 assertThat(assertion.info.representation()).isEqualTo(UNICODE_REPRESENTATION);514 assertThat(assertion.info.overridingErrorMessage()).isEqualTo("error message");515 assertThat(comparatorsByTypeOf(assertion).get(String.class)).isSameAs(ALWAY_EQUALS_STRING);516 assertThat(comparatorForElementFieldsWithTypeOf(assertion).get(Timestamp.class)).isSameAs(ALWAY_EQUALS_TIMESTAMP);517 assertThat(comparatorForElementFieldsWithNamesOf(assertion).get("foo")).isSameAs(ALWAY_EQUALS_STRING);518 }519 @Test520 void extracting_should_not_propagate_the_sorted_set_element_comparator() {521 // GIVEN522 SortedSet<Data> sortedSet = new TreeSet<>(comparing(Data::getValue));523 sortedSet.add(new Data("1"));524 sortedSet.add(new Data("2"));525 sortedSet.add(new Data("3"));526 // THEN527 assertThat(sortedSet).extracting(Data::getValue)528 .containsOnly("1", "2", "3");529 }530 @Test531 void extracting_should_fail_it_the_propagated_element_comparator_is_incompatible() {532 // GIVEN533 Iterable<Data> list = list(new Data("1"), new Data("2"), new Data("3"));534 // WHEN535 Throwable error = catchThrowable(() -> assertThat(list).usingElementComparator(comparing(Data::getValue))536 .extracting(Data::getValue)537 .containsOnly("1", "2", "3"));538 // THEN539 assertThat(error).isInstanceOf(ClassCastException.class);540 }541 private static class Data {542 private final String value;543 private Data(String value) {544 this.value = value;545 }546 private String getValue() {547 return value;548 }549 }550}...

Full Screen

Full Screen

extract

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.api.SoftAssertions;2import org.assertj.core.api.iterable.IterableAssert_extracting_with_SortedSet_Test;3import org.assertj.core.util.introspection.IntrospectionError;4public class IterableAssert_extracting_with_SortedSet_Test_extracting_with_SortedSet_Test {5 private IterableAssert_extracting_with_SortedSet_Test iterableAssert_extracting_with_SortedSet_Test = new IterableAssert_extracting_with_SortedSet_Test();6 public void test_extracting_with_SortedSet_Test() throws IntrospectionError {7 SoftAssertions softly = new SoftAssertions();8 iterableAssert_extracting_with_SortedSet_Test.test_extracting_with_SortedSet_Test(softly);9 softly.assertAll();10 }11}

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.

Most used method in IterableAssert_extracting_with_SortedSet_Test

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful