How to use toString method of org.assertj.core.api.BDDSoftAssertionsTest class

Best Assertj code snippet using org.assertj.core.api.BDDSoftAssertionsTest.toString

Source:BDDSoftAssertionsTest.java Github

copy

Full Screen

...168 softly.then(new short[]{ ((short) (46)) }).isEqualTo(new short[]{ ((short) (47)) });169 softly.then("48").isEqualTo("49");170 softly.then(new Object() {171 @Override172 public String toString() {173 return "50";174 }175 }).isEqualTo(new Object() {176 @Override177 public String toString() {178 return "51";179 }180 });181 softly.then(new Object[]{ new Object() {182 @Override183 public String toString() {184 return "52";185 }186 } }).isEqualTo(new Object[]{ new Object() {187 @Override188 public String toString() {189 return "53";190 }191 } });192 final IllegalArgumentException illegalArgumentException = new IllegalArgumentException("IllegalArgumentException message");193 softly.then(illegalArgumentException).hasMessage("NullPointerException message");194 softly.thenThrownBy(() -> {195 throw new Exception("something was wrong");196 }).hasMessage("something was good");197 softly.then(Maps.mapOf(MapEntry.entry("54", "55"))).contains(MapEntry.entry("1", "2"));198 softly.then(LocalTime.of(12, 0)).isEqualTo(LocalTime.of(13, 0));199 softly.then(OffsetTime.of(12, 0, 0, 0, ZoneOffset.UTC)).isEqualTo(OffsetTime.of(13, 0, 0, 0, ZoneOffset.UTC));200 softly.then(Optional.of("not empty")).isEqualTo("empty");201 softly.then(OptionalInt.of(0)).isEqualTo(1);202 softly.then(OptionalDouble.of(0.0)).isEqualTo(1.0);203 softly.then(OptionalLong.of(0L)).isEqualTo(1L);204 softly.then(new URI("http://assertj.org")).hasPort(8888);205 softly.then(CompletableFuture.completedFuture("done")).hasFailed();206 softly.then(((Predicate<String>) (( s) -> s.equals("something")))).accepts("something else");207 softly.then(((IntPredicate) (( s) -> s == 1))).accepts(2);208 softly.then(((LongPredicate) (( s) -> s == 1))).accepts(2);209 softly.then(((DoublePredicate) (( s) -> s == 1))).accepts(2);210 // WHEN211 MultipleFailuresError error = Assertions.catchThrowableOfType(() -> softly.assertAll(), MultipleFailuresError.class);212 // THEN213 List<String> errors = error.getFailures().stream().map(Object::toString).collect(Collectors.toList());214 Assertions.assertThat(errors).hasSize(52);215 Assertions.assertThat(errors.get(0)).contains(String.format("%nExpecting:%n <0>%nto be equal to:%n <1>%nbut was not."));216 Assertions.assertThat(errors.get(1)).contains(String.format("%nExpecting:%n <false>%nto be equal to:%n <true>%nbut was not."));217 Assertions.assertThat(errors.get(2)).contains(String.format("%nExpecting:%n <false>%nto be equal to:%n <true>%nbut was not."));218 Assertions.assertThat(errors.get(3)).contains(String.format("%nExpecting:%n <[false]>%nto be equal to:%n <[true]>%nbut was not."));219 Assertions.assertThat(errors.get(4)).contains(String.format("%nExpecting:%n <0>%nto be equal to:%n <1>%nbut was not."));220 Assertions.assertThat(errors.get(5)).contains(String.format("%nExpecting:%n <0x02>%nto be equal to:%n <0x03>%nbut was not."));221 Assertions.assertThat(errors.get(6)).contains(String.format("%nExpecting:%n <[4]>%nto be equal to:%n <[5]>%nbut was not."));222 Assertions.assertThat(errors.get(7)).contains(String.format("%nExpecting:%n <'A'>%nto be equal to:%n <'B'>%nbut was not."));223 Assertions.assertThat(errors.get(8)).contains(String.format("%nExpecting:%n <'C'>%nto be equal to:%n <'D'>%nbut was not."));224 Assertions.assertThat(errors.get(9)).contains(String.format("%nExpecting:%n <['E']>%nto be equal to:%n <['F']>%nbut was not."));225 Assertions.assertThat(errors.get(10)).contains(String.format("%nExpecting:%n <a>%nto be equal to:%n <b>%nbut was not."));226 Assertions.assertThat(errors.get(11)).contains(String.format("%nExpecting:%n <java.lang.Object>%nto be equal to:%n <java.lang.String>%nbut was not."));227 Assertions.assertThat(errors.get(12)).contains(String.format("%nExpecting:%n <1999-12-31T23:59:59.000>%nto be equal to:%n <2000-01-01T00:00:01.000>%nbut was not."));228 Assertions.assertThat(errors.get(13)).contains(String.format("%nExpecting:%n <6.0>%nto be equal to:%n <7.0>%nbut was not."));229 Assertions.assertThat(errors.get(14)).contains(String.format("%nExpecting:%n <8.0>%nto be equal to:%n <9.0>%nbut was not."));230 Assertions.assertThat(errors.get(15)).contains(String.format("%nExpecting:%n <[10.0]>%nto be equal to:%n <[11.0]>%nbut was not."));231 Assertions.assertThat(errors.get(16)).contains(String.format("%nExpecting:%n <File(a)>%nto be equal to:%n <File(b)>%nbut was not."));232 Assertions.assertThat(errors.get(17)).contains(String.format("%nExpecting:%n <12.0f>%nto be equal to:%n <13.0f>%nbut was not."));233 Assertions.assertThat(errors.get(18)).contains(String.format("%nExpecting:%n <14.0f>%nto be equal to:%n <15.0f>%nbut was not."));234 Assertions.assertThat(errors.get(19)).contains(String.format("%nExpecting:%n <[16.0f]>%nto be equal to:%n <[17.0f]>%nbut was not."));235 Assertions.assertThat(errors.get(20)).contains(String.format(("%nInputStreams do not have same content:%n%n" + (((("Changed content at line 1:%n" + "expecting:%n") + " [\"B\"]%n") + "but was:%n") + " [\"A\"]%n"))));236 Assertions.assertThat(errors.get(21)).contains(String.format("%nExpecting:%n <20>%nto be equal to:%n <21>%nbut was not."));237 Assertions.assertThat(errors.get(22)).contains(String.format("%nExpecting:%n <22>%nto be equal to:%n <23>%nbut was not."));238 Assertions.assertThat(errors.get(23)).contains(String.format("%nExpecting:%n <[24]>%nto be equal to:%n <[25]>%nbut was not."));239 Assertions.assertThat(errors.get(24)).contains(String.format("%nExpecting:%n <[\"26\"]>%nto be equal to:%n <[\"27\"]>%nbut was not."));240 Assertions.assertThat(errors.get(25)).contains(String.format("Expecting the iterator under test to be exhausted"));241 Assertions.assertThat(errors.get(26)).contains(String.format("%nExpecting:%n <[\"30\"]>%nto be equal to:%n <[\"31\"]>%nbut was not."));242 Assertions.assertThat(errors.get(27)).contains(String.format("%nExpecting:%n <32L>%nto be equal to:%n <33L>%nbut was not."));243 Assertions.assertThat(errors.get(28)).contains(String.format("%nExpecting:%n <34L>%nto be equal to:%n <35L>%nbut was not."));244 Assertions.assertThat(errors.get(29)).contains(String.format("%nExpecting:%n <[36L]>%nto be equal to:%n <[37L]>%nbut was not."));245 Assertions.assertThat(errors.get(30)).contains(String.format("%nExpecting:%n <{\"38\"=\"39\"}>%nto be equal to:%n <{\"40\"=\"41\"}>%nbut was not."));246 Assertions.assertThat(errors.get(31)).contains(String.format("%nExpecting:%n <42>%nto be equal to:%n <43>%nbut was not."));247 Assertions.assertThat(errors.get(32)).contains(String.format("%nExpecting:%n <44>%nto be equal to:%n <45>%nbut was not."));248 Assertions.assertThat(errors.get(33)).contains(String.format("%nExpecting:%n <[46]>%nto be equal to:%n <[47]>%nbut was not."));249 Assertions.assertThat(errors.get(34)).contains(String.format("%nExpecting:%n <\"48\">%nto be equal to:%n <\"49\">%nbut was not."));250 Assertions.assertThat(errors.get(35)).contains(String.format("%nExpecting:%n <50>%nto be equal to:%n <51>%nbut was not."));251 Assertions.assertThat(errors.get(36)).contains(String.format("%nExpecting:%n <[52]>%nto be equal to:%n <[53]>%nbut was not."));252 Assertions.assertThat(errors.get(37)).contains(String.format(("%nExpecting message:%n" + ((" <\"NullPointerException message\">%n" + "but was:%n") + " <\"IllegalArgumentException message\">"))));253 Assertions.assertThat(errors.get(38)).contains(String.format(("%nExpecting message:%n" + ((" <\"something was good\">%n" + "but was:%n") + " <\"something was wrong\">"))));254 Assertions.assertThat(errors.get(39)).contains(String.format(("%nExpecting:%n" + ((((" <{\"54\"=\"55\"}>%n" + "to contain:%n") + " <[MapEntry[key=\"1\", value=\"2\"]]>%n") + "but could not find:%n") + " <[MapEntry[key=\"1\", value=\"2\"]]>%n"))));255 Assertions.assertThat(errors.get(40)).contains(String.format("%nExpecting:%n <12:00>%nto be equal to:%n <13:00>%nbut was not."));256 Assertions.assertThat(errors.get(41)).contains(String.format("%nExpecting:%n <12:00Z>%nto be equal to:%n <13:00Z>%nbut was not."));257 Assertions.assertThat(errors.get(42)).contains(String.format("%nExpecting:%n <Optional[not empty]>%nto be equal to:%n <\"empty\">%nbut was not."));258 Assertions.assertThat(errors.get(43)).contains(String.format("%nExpecting:%n <OptionalInt[0]>%nto be equal to:%n <1>%nbut was not."));259 Assertions.assertThat(errors.get(44)).contains(String.format("%nExpecting:%n <OptionalDouble[0.0]>%nto be equal to:%n <1.0>%nbut was not."));260 Assertions.assertThat(errors.get(45)).contains(String.format("%nExpecting:%n <OptionalLong[0]>%nto be equal to:%n <1L>%nbut was not."));261 Assertions.assertThat(errors.get(46)).contains("Expecting port of");262 Assertions.assertThat(errors.get(47)).contains("to have failed");263 Assertions.assertThat(errors.get(48)).contains(String.format(("%nExpecting:%n <given predicate>%n" + "to accept <\"something else\"> but it did not.")));264 Assertions.assertThat(errors.get(49)).contains(String.format(("%nExpecting:%n <given predicate>%n" + "to accept <2> but it did not.")));265 Assertions.assertThat(errors.get(50)).contains(String.format(("%nExpecting:%n <given predicate>%n" + "to accept <2L> but it did not.")));266 Assertions.assertThat(errors.get(51)).contains(String.format(("%nExpecting:%n <given predicate>%n" + "to accept <2.0> but it did not.")));267 }268 @SuppressWarnings("unchecked")269 @Test270 public void should_pass_when_using_extracting_with_object() {271 // GIVEN272 Name name = Name.name("John", "Doe");273 // WHEN274 softly.then(name).extracting("first", "last").contains("John", "Doe");275 softly.then(name).extracting(Name::getFirst, Name::getLast).contains("John", "Doe");276 softly.then(name).extracting(Name::getFirst).isEqualTo("John");277 // THEN278 Assertions.assertThat(softly.errorsCollected()).isEmpty();279 }280 @Test281 public void should_pass_when_using_extracting_with_list() {282 // GIVEN283 List<Name> names = Arrays.asList(Name.name("John", "Doe"), Name.name("Jane", "Doe"));284 // WHEN285 softly.then(names).extracting("first").as("using extracting()").contains("John").contains("Jane").contains("Foo1");286 softly.then(names).extracting(Name::getFirst).as("using extracting(Extractor)").contains("John").contains("Jane").contains("Foo2");287 softly.then(names).extracting("first", String.class).as("using extracting(..., Class)").contains("John").contains("Jane").contains("Foo3");288 softly.then(names).extracting("first", "last").as("using extracting(...)").contains(Assertions.tuple("John", "Doe")).contains(Assertions.tuple("Jane", "Doe")).contains(Assertions.tuple("Foo", "4"));289 softly.then(names).extractingResultOf("getFirst", String.class).as("using extractingResultOf(method, Class)").contains("John").contains("Jane").contains("Foo5");290 softly.then(names).extractingResultOf("getFirst").as("using extractingResultOf(method)").contains("John").contains("Jane").contains("Foo6");291 // THEN292 List<Throwable> errorsCollected = softly.errorsCollected();293 Assertions.assertThat(errorsCollected).hasSize(6);294 Assertions.assertThat(errorsCollected.get(0)).hasMessageContaining("Foo1");295 Assertions.assertThat(errorsCollected.get(1)).hasMessageContaining("Foo2");296 Assertions.assertThat(errorsCollected.get(2)).hasMessageContaining("Foo3");297 Assertions.assertThat(errorsCollected.get(3)).hasMessageContaining("Foo").hasMessageContaining("4");298 Assertions.assertThat(errorsCollected.get(4)).hasMessageContaining("Foo5");299 Assertions.assertThat(errorsCollected.get(5)).hasMessageContaining("Foo6");300 }301 @Test302 public void should_pass_when_using_extracting_with_iterable() {303 Iterable<Name> names = Arrays.asList(Name.name("John", "Doe"), Name.name("Jane", "Doe"));304 try (AutoCloseableBDDSoftAssertions softly = new AutoCloseableBDDSoftAssertions()) {305 softly.then(names).extracting("first").as("using extracting()").contains("John").contains("Jane");306 softly.then(names).extracting(Name::getFirst).as("using extracting(Extractor)").contains("John").contains("Jane");307 softly.then(names).extracting("first", String.class).as("using extracting(..., Class)").contains("John").contains("Jane");308 softly.then(names).extracting("first", "last").as("using extracting(...)").contains(Assertions.tuple("John", "Doe")).contains(Assertions.tuple("Jane", "Doe"));309 softly.then(names).extractingResultOf("getFirst", String.class).as("using extractingResultOf(method, Class)").contains("John").contains("Jane");310 softly.then(names).extractingResultOf("getFirst").as("using extractingResultOf(method)").contains("John").contains("Jane");311 }312 }313 @Test314 public void should_work_when_using_extracting_with_array() {315 Name[] namesAsArray = new Name[]{ Name.name("John", "Doe"), Name.name("Jane", "Doe") };316 try (AutoCloseableBDDSoftAssertions softly = new AutoCloseableBDDSoftAssertions()) {317 softly.then(namesAsArray).extracting("first").as("using extracting()").contains("John").contains("Jane");318 softly.then(namesAsArray).extracting(Name::getFirst).as("using extracting(Extractor)").contains("John").contains("Jane");319 softly.then(namesAsArray).extracting("first", String.class).as("using extracting(..., Class)").contains("John").contains("Jane");320 softly.then(namesAsArray).extracting("first", "last").as("using extracting(...)").contains(Assertions.tuple("John", "Doe")).contains(Assertions.tuple("Jane", "Doe"));321 softly.then(namesAsArray).extractingResultOf("getFirst", String.class).as("using extractingResultOf(method, Class)").contains("John").contains("Jane");322 softly.then(namesAsArray).extractingResultOf("getFirst").as("using extractingResultOf(method)").contains("John").contains("Jane");323 }324 }325 @Test326 public void should_work_with_flat_extracting() {327 // GIVEN328 List<CartoonCharacter> characters = Arrays.asList(homer, fred);329 CartoonCharacter[] charactersAsArray = characters.toArray(new CartoonCharacter[characters.size()]);330 // WHEN331 softly.then(characters).flatExtracting(CartoonCharacter::getChildren).as("using flatExtracting on Iterable").containsAnyOf(homer, fred).hasSize(123);332 softly.then(charactersAsArray).flatExtracting(CartoonCharacter::getChildren).as("using flatExtracting on array").containsAnyOf(homer, fred).hasSize(456);333 // THEN334 List<Throwable> errorsCollected = softly.errorsCollected();335 Assertions.assertThat(errorsCollected).hasSize(4);336 Assertions.assertThat(errorsCollected.get(0)).hasMessageContaining(homer.toString());337 Assertions.assertThat(errorsCollected.get(1)).hasMessageContaining("123");338 Assertions.assertThat(errorsCollected.get(2)).hasMessageContaining(fred.toString());339 Assertions.assertThat(errorsCollected.get(3)).hasMessageContaining("456");340 }341 @Test342 public void should_collect_all_errors_when_using_extracting() {343 // GIVEN344 List<Name> names = Arrays.asList(Name.name("John", "Doe"), Name.name("Jane", "Doe"));345 // WHEN346 softly.then(names).extracting("first").overridingErrorMessage("error 1").contains("gandalf").overridingErrorMessage("error 2").contains("frodo");347 softly.then(names).extracting("last").overridingErrorMessage("error 3").isEmpty();348 // THEN349 Assertions.assertThat(softly.errorsCollected()).extracting(Throwable::getMessage).containsExactly("error 1", "error 2", "error 3");350 }351 @Test352 public void should_collect_all_errors_when_using_flat_extracting() {353 // GIVEN354 List<CartoonCharacter> characters = Arrays.asList(homer, fred);355 // WHEN356 softly.then(characters).flatExtracting(CartoonCharacter::getChildren).overridingErrorMessage("error 1").hasSize(0).overridingErrorMessage("error 2").isEmpty();357 // THEN358 Assertions.assertThat(softly.errorsCollected()).extracting(Throwable::getMessage).containsExactly("error 1", "error 2");359 }360 @Test361 public void should_collect_all_errors_when_using_filtering() {362 // GIVEN363 LinkedHashSet<CartoonCharacter> dads = Sets.newLinkedHashSet(homer, fred);364 // WHEN365 softly.then(dads).filteredOn("name", "Homer Simpson").hasSize(10).isEmpty();366 // THEN367 List<Throwable> errorsCollected = softly.errorsCollected();368 Assertions.assertThat(errorsCollected).hasSize(2);369 Assertions.assertThat(errorsCollected.get(0)).hasMessageStartingWith(String.format("%nExpected size:<10> but was:<1> in:%n<[CartoonCharacter [name=Homer Simpson]]>"));370 Assertions.assertThat(errorsCollected.get(1)).hasMessageStartingWith(String.format("%nExpecting empty but was:<[CartoonCharacter [name=Homer Simpson]]>"));371 }372 @Test373 public void should_collect_all_errors_when_using_predicate_filtering() {374 // GIVEN375 LinkedHashSet<CartoonCharacter> dads = Sets.newLinkedHashSet(homer, fred);376 // WHEN377 softly.then(dads).filteredOn(( c) -> c.getName().equals("Homer Simpson")).hasSize(10).isEmpty();378 // THEN379 List<Throwable> errorsCollected = softly.errorsCollected();380 Assertions.assertThat(errorsCollected).hasSize(2);381 Assertions.assertThat(errorsCollected.get(0)).hasMessageStartingWith(String.format("%nExpected size:<10> but was:<1> in:%n<[CartoonCharacter [name=Homer Simpson]]>"));382 Assertions.assertThat(errorsCollected.get(1)).hasMessageStartingWith(String.format("%nExpecting empty but was:<[CartoonCharacter [name=Homer Simpson]]>"));383 }384 @Test385 public void should_work_with_comparable() {386 // GIVEN387 ComparableExample example1 = new ComparableExample(0);388 ComparableExample example2 = new ComparableExample(0);389 ComparableExample example3 = new ComparableExample(123);390 // WHEN391 softly.then(example1).isEqualByComparingTo(example2);392 softly.then(example1).isEqualByComparingTo(example3);393 // THEN394 List<Throwable> errorsCollected = softly.errorsCollected();395 Assertions.assertThat(errorsCollected).hasSize(1);396 Assertions.assertThat(errorsCollected.get(0)).hasMessageContaining("123");397 }398 @Test399 public void should_work_with_stream() {400 // WHEN401 softly.then(Stream.of("a", "b", "c")).contains("a", "foo");402 softly.then(IntStream.of(1, 2, 3)).contains(2, 4, 6);403 softly.then(LongStream.of(1, 2, 3)).contains((-1L), (-2L), (-3L));404 softly.then(DoubleStream.of(1, 2, 3)).contains(10.0, 20.0, 30.0);405 // THEN406 List<Throwable> errorsCollected = softly.errorsCollected();407 Assertions.assertThat(errorsCollected).hasSize(4);408 Assertions.assertThat(errorsCollected.get(0)).hasMessageContaining("foo");409 Assertions.assertThat(errorsCollected.get(1)).hasMessageContaining("6");410 Assertions.assertThat(errorsCollected.get(2)).hasMessageContaining("-3");411 Assertions.assertThat(errorsCollected.get(3)).hasMessageContaining("30.0");412 }413 @Test414 public void should_work_with_CompletionStage() {415 // GIVEN416 CompletionStage<String> completionStage = CompletableFuture.completedFuture("done");417 // WHEN418 softly.then(completionStage).isDone();419 softly.then(completionStage).hasNotFailed();420 softly.then(completionStage).isCancelled();421 completionStage = null;422 softly.then(completionStage).isNull();423 // THEN424 Assertions.assertThat(softly.errorsCollected()).hasSize(1);425 Assertions.assertThat(softly.errorsCollected().get(0)).hasMessageContaining("cancelled");426 }427 @Test428 public void should_work_with_predicate() {429 // GIVEN430 Predicate<String> lowercasePredicate = ( s) -> s.equals(s.toLowerCase());431 // WHEN432 softly.then(lowercasePredicate).accepts("a", "b", "c");433 softly.then(lowercasePredicate).accepts("a", "b", "C");434 // THEN435 Assertions.assertThat(softly.errorsCollected()).hasSize(1);436 Assertions.assertThat(softly.errorsCollected().get(0)).hasMessageContaining("C");437 }438 @Test439 public void should_work_with_optional() {440 // GIVEN441 Optional<String> optional = Optional.of("Gandalf");442 // WHEN443 softly.then(optional).contains("Gandalf");444 // THEN445 softly.assertAll();446 }447 @Test448 public void should_work_with_optional_chained_with_map() {449 // GIVEN450 Optional<String> optional = Optional.of("Gandalf");451 // WHEN452 softly.then(optional).contains("Gandalf").map(String::length).contains(7);453 // THEN454 softly.assertAll();455 }456 @Test457 public void should_collect_all_errors_when_using_map() {458 // GIVEN459 Optional<String> optional = Optional.of("Gandalf");460 // WHEN461 softly.then(optional).contains("Sauron");462 softly.then(optional).contains("Gandalf").map(String::length).contains(1);463 // THEN464 Assertions.assertThat(softly.errorsCollected()).hasSize(2);465 }466 @Test467 public void should_collect_all_errors_when_using_flatMap() {468 // GIVEN469 Optional<String> optional = Optional.of("Gandalf");470 // WHEN471 softly.then(optional).contains("Sauron");472 softly.then(optional).flatMap(( s) -> Optional.of(s.length())).contains(1);473 // THEN474 Assertions.assertThat(softly.errorsCollected()).hasSize(2);475 }476 @Test477 public void should_propagate_AssertionError_from_nested_proxied_calls() {478 // the nested proxied call to isNotEmpty() throw an Assertion error that must be propagated to the caller.479 softly.then(Arrays.asList()).first();480 // nested proxied call to throwAssertionError when checking that is optional is present481 softly.then(Optional.empty()).contains("Foo");482 // nested proxied call to isNotNull483 softly.then(((Predicate<String>) (null))).accepts("a", "b", "c");484 // nested proxied call to isCompleted485 softly.then(new CompletableFuture<String>()).isCompletedWithValue("done");486 // it must be caught by softly.assertAll()487 Assertions.assertThat(softly.errorsCollected()).hasSize(4);488 }489 // bug #447490 public class TolkienHeroe {491 String name;492 int age;493 }494 @Test495 public void check_477_bugfix() {496 // GIVEN497 BDDSoftAssertionsTest.TolkienHeroe frodo = new BDDSoftAssertionsTest.TolkienHeroe();498 BDDSoftAssertionsTest.TolkienHeroe samnullGamgee = null;499 BDDSoftAssertionsTest.TolkienSoftAssertions softly = new BDDSoftAssertionsTest.TolkienSoftAssertions();500 // WHEN501 softly.then(frodo).hasAge(10);// Expect failure - age will be 0 due to not being initialized.502 softly.then(samnullGamgee).hasAge(11);// Expect failure - argument is null.503 // THEN504 Assertions.assertThat(errorsCollected()).hasSize(2);505 }506 public static class TolkienHeroesAssert extends AbstractAssert<BDDSoftAssertionsTest.TolkienHeroesAssert, BDDSoftAssertionsTest.TolkienHeroe> {507 public TolkienHeroesAssert(BDDSoftAssertionsTest.TolkienHeroe actual) {508 super(actual, BDDSoftAssertionsTest.TolkienHeroesAssert.class);509 }510 public static BDDSoftAssertionsTest.TolkienHeroesAssert assertThat(BDDSoftAssertionsTest.TolkienHeroe actual) {511 return new BDDSoftAssertionsTest.TolkienHeroesAssert(actual);512 }513 // 4 - a specific assertion !514 public BDDSoftAssertionsTest.TolkienHeroesAssert hasName(String name) {515 // check that actual TolkienCharacter we want to make assertions on is not null.516 isNotNull();517 // check condition518 if (!(Objects.equals(name, name))) {519 failWithMessage("Expected character's name to be <%s> but was <%s>", name, name);520 }521 // return the current assertion for method chaining522 return this;523 }524 // 4 - another specific assertion !525 public BDDSoftAssertionsTest.TolkienHeroesAssert hasAge(int age) {526 // check that actual TolkienCharacter we want to make assertions on is not null.527 isNotNull();528 // check condition529 if ((age) != age) {530 failWithMessage("Expected character's age to be <%s> but was <%s>", age, actual.age);531 }532 // return the current assertion for method chaining533 return this;534 }535 }536 public static class TolkienSoftAssertions extends SoftAssertions {537 public BDDSoftAssertionsTest.TolkienHeroesAssert then(BDDSoftAssertionsTest.TolkienHeroe actual) {538 return proxy(BDDSoftAssertionsTest.TolkienHeroesAssert.class, BDDSoftAssertionsTest.TolkienHeroe.class, actual);539 }540 }541 @Test542 public void should_return_failure_after_fail() {543 // GIVEN544 String failureMessage = "Should not reach here";545 // WHEN546 softly.fail(failureMessage);547 // THEN548 Assertions.assertThat(softly.wasSuccess()).isFalse();549 Assertions.assertThat(softly.errorsCollected()).hasSize(1);550 Assertions.assertThat(softly.errorsCollected().get(0)).hasMessageStartingWith(failureMessage);551 }552 @Test553 public void should_return_failure_after_fail_with_parameters() {554 // GIVEN555 String failureMessage = "Should not reach %s or %s";556 // WHEN557 softly.fail(failureMessage, "here", "here");558 // THEN559 Assertions.assertThat(softly.wasSuccess()).isFalse();560 Assertions.assertThat(softly.errorsCollected()).hasSize(1);561 Assertions.assertThat(softly.errorsCollected().get(0)).hasMessageStartingWith("Should not reach here or here");562 }563 @Test564 public void should_return_failure_after_fail_with_throwable() {565 // GIVEN566 String failureMessage = "Should not reach here";567 IllegalStateException realCause = new IllegalStateException();568 // WHEN569 softly.fail(failureMessage, realCause);570 // THEN571 Assertions.assertThat(softly.wasSuccess()).isFalse();572 List<Throwable> errorsCollected = softly.errorsCollected();573 Assertions.assertThat(errorsCollected).hasSize(1);574 Assertions.assertThat(errorsCollected.get(0)).hasMessageStartingWith(failureMessage);575 Assertions.assertThat(errorsCollected.get(0).getCause()).isEqualTo(realCause);576 }577 @Test578 public void should_return_failure_after_shouldHaveThrown() {579 // WHEN580 softly.shouldHaveThrown(IllegalArgumentException.class);581 // THEN582 Assertions.assertThat(softly.wasSuccess()).isFalse();583 List<Throwable> errorsCollected = softly.errorsCollected();584 Assertions.assertThat(errorsCollected).hasSize(1);585 Assertions.assertThat(errorsCollected.get(0)).hasMessageStartingWith("IllegalArgumentException should have been thrown");586 }587 @Test588 public void should_assert_using_assertSoftly() {589 Assertions.assertThatThrownBy(() -> {590 assertSoftly(( assertions) -> {591 assertions.assertThat(true).isFalse();592 assertions.assertThat(42).isEqualTo("meaning of life");593 assertions.assertThat("red").isEqualTo("blue");594 });595 }).as("it should call assertAll() and fail with multiple validation errors").hasMessageContaining("meaning of life").hasMessageContaining("blue");596 }597 @Test598 public void should_work_with_atomic() {599 // WHEN600 // simple atomic value601 softly.then(new AtomicBoolean(true)).isTrue().isFalse();602 softly.then(new AtomicInteger(1)).hasValueGreaterThan(0).hasNegativeValue();603 softly.then(new AtomicLong(1L)).hasValueGreaterThan(0L).hasNegativeValue();604 softly.then(new AtomicReference("abc")).hasValue("abc").hasValue("def");605 // atomic array value606 softly.then(new AtomicIntegerArray(new int[]{ 1, 2, 3 })).containsExactly(1, 2, 3).isEmpty();607 softly.then(new AtomicLongArray(new long[]{ 1L, 2L, 3L })).containsExactly(1L, 2L, 3L).contains(0);608 softly.then(new java.util.concurrent.atomic.AtomicReferenceArray(org.assertj.core.util.Arrays.array("a", "b", "c"))).containsExactly("a", "b", "c").contains("123");609 // THEN610 List<Throwable> errorsCollected = softly.errorsCollected();611 Assertions.assertThat(errorsCollected).hasSize(7);612 Assertions.assertThat(errorsCollected.get(0)).hasMessageContaining("false");613 Assertions.assertThat(errorsCollected.get(1)).hasMessageContaining("0");614 Assertions.assertThat(errorsCollected.get(2)).hasMessageContaining("0L");615 Assertions.assertThat(errorsCollected.get(3)).hasMessageContaining("def");616 Assertions.assertThat(errorsCollected.get(4)).hasMessageContaining("empty");617 Assertions.assertThat(errorsCollected.get(5)).hasMessageContaining("0");618 Assertions.assertThat(errorsCollected.get(6)).hasMessageContaining("123");619 }620 @Test621 public void should_fix_bug_1146() {622 // GIVEN623 Map<String, String> numbers = Maps.mapOf(Assertions.entry("one", "1"), Assertions.entry("two", "2"), Assertions.entry("three", "3"));624 // THEN625 try (final AutoCloseableBDDSoftAssertions softly = new AutoCloseableBDDSoftAssertions()) {626 softly.then(numbers).extracting("one", "two").containsExactly("1", "2");627 softly.then(numbers).extracting("one").containsExactly("1");628 }629 }630 @Test631 public void iterable_soft_assertions_should_work_with_navigation_methods() {632 // GIVEN633 Iterable<Name> names = Arrays.asList(Name.name("John", "Doe"), Name.name("Jane", "Doe"));634 // WHEN635 softly.then(names).size().isGreaterThan(10);636 softly.then(names).size().isGreaterThan(22).returnToIterable().isEmpty();637 softly.then(names).first().as("first element").isNull();638 softly.then(names).element(0).as("element(0)").isNull();639 softly.then(names).last().as("last element").isNull();640 // THEN641 List<Throwable> errorsCollected = softly.errorsCollected();642 Assertions.assertThat(errorsCollected).hasSize(6);643 Assertions.assertThat(errorsCollected.get(0)).hasMessageContaining("10");644 Assertions.assertThat(errorsCollected.get(1)).hasMessageContaining("22");645 Assertions.assertThat(errorsCollected.get(2)).hasMessageContaining("empty");646 Assertions.assertThat(errorsCollected.get(3)).hasMessageContaining("first element");647 Assertions.assertThat(errorsCollected.get(4)).hasMessageContaining("element(0)");648 Assertions.assertThat(errorsCollected.get(5)).hasMessageContaining("last element");649 }650 @Test651 public void list_soft_assertions_should_work_with_navigation_methods() {652 // GIVEN653 List<Name> names = Arrays.asList(Name.name("John", "Doe"), Name.name("Jane", "Doe"));654 // WHEN655 softly.then(names).size().isGreaterThan(10);656 softly.then(names).size().isGreaterThan(22).returnToIterable().isEmpty();657 softly.then(names).first().as("first element").isNull();658 softly.then(names).element(0).as("element(0)").isNull();659 softly.then(names).last().as("last element").isNull();660 // THEN661 List<Throwable> errorsCollected = softly.errorsCollected();662 Assertions.assertThat(errorsCollected).hasSize(6);663 Assertions.assertThat(errorsCollected.get(0)).hasMessageContaining("10");664 Assertions.assertThat(errorsCollected.get(1)).hasMessageContaining("22");665 Assertions.assertThat(errorsCollected.get(2)).hasMessageContaining("empty");666 Assertions.assertThat(errorsCollected.get(3)).hasMessageContaining("first element");667 Assertions.assertThat(errorsCollected.get(4)).hasMessageContaining("element(0)");668 Assertions.assertThat(errorsCollected.get(5)).hasMessageContaining("last element");669 }670 // the test would fail if any method was not proxyable as the assertion error would not be softly caught671 @SuppressWarnings("unchecked")672 @Test673 public void iterable_soft_assertions_should_report_errors_on_final_methods_and_methods_that_switch_the_object_under_test() {674 // GIVEN675 Iterable<Name> names = Arrays.asList(Name.name("John", "Doe"), Name.name("Jane", "Doe"));676 Iterable<CartoonCharacter> characters = Arrays.asList(homer, fred);677 softly.then(names).extracting(throwingFirstNameExtractor).contains("gandalf").contains("frodo");678 softly.then(names).extracting("last").containsExactly("foo", "bar");679 softly.then(characters).flatExtracting(childrenExtractor).as("using flatExtracting on Iterable").hasSize(1).containsAnyOf(homer, fred);680 softly.then(characters).flatExtracting(CartoonCharacter::getChildrenWithException).as("using flatExtracting on Iterable with exception").containsExactlyInAnyOrder(homer, fred);681 softly.then(characters).containsOnly(bart);682 softly.then(characters).containsOnlyOnce(maggie, bart);683 softly.then(characters).containsSequence(homer, bart);684 softly.then(characters).containsSubsequence(homer, maggie);685 softly.then(characters).doesNotContain(homer, maggie);686 softly.then(characters).doesNotContainSequence(fred);687 softly.then(characters).doesNotContainSubsequence(homer, fred);688 softly.then(characters).isSubsetOf(homer, bart);689 softly.then(characters).startsWith(fred);690 softly.then(characters).endsWith(bart);691 softly.then(names).extracting(firstNameFunction, lastNameFunction).contains(Assertions.tuple("John", "Doe")).contains(Assertions.tuple("Frodo", "Baggins"));692 softly.then(names).extracting("first", "last").contains(Assertions.tuple("John", "Doe")).contains(Assertions.tuple("Bilbo", "Baggins"));693 softly.then(names).extracting(firstNameFunction).contains("John").contains("sam");694 softly.then(names).extracting("first", String.class).contains("John").contains("Aragorn");695 softly.then(names).filteredOn(( name) -> name.first.startsWith("Jo")).hasSize(123);696 softly.then(names).filteredOn(( name) -> name.first.startsWith("Jo")).extracting(firstNameFunction).contains("Sauron");697 softly.then(names).flatExtracting(firstNameFunction, lastNameFunction).as("flatExtracting with multiple Extractors").contains("John", "Jane", "Doe").contains("Sauron");698 softly.then(names).flatExtracting(throwingFirstNameExtractor, throwingLastNameExtractor).as("flatExtracting with multiple ThrowingExtractors").contains("John", "Jane", "Doe").contains("Sauron");699 softly.then(names).extractingResultOf("getFirst").contains("John", "Jane").contains("Sam", "Aragorn");700 softly.then(names).extractingResultOf("getFirst", String.class).contains("John", "Jane").contains("Messi", "Ronaldo");701 softly.then(names).filteredOn(new Condition(( name) -> name.first.startsWith("Jo"), "startsWith Jo")).as("filteredOn with condition").hasSize(5);702 softly.then(names).filteredOn("first", Assertions.in("John", "Frodo")).as("filteredOn firstName in {John, Frodo}").isEmpty();703 softly.then(names).filteredOn("first", "John").as("filteredOn firstName = John").isEmpty();704 softly.then(names).filteredOnNull("first").as("filteredOn firstName = null").isNotEmpty();705 softly.then(names).flatExtracting("first", "last").as("using flatExtracting(String... fieldOrPropertyNames)").contains("John", "Jane", "Doe").contains("Sauron");706 softly.then(characters).flatExtracting("children").as("using flatExtracting(String fieldOrPropertyName)").contains(bart, maggie).contains("Sauron");707 softly.then(names).filteredOnAssertions(( name) -> assertThat(name.first).startsWith("Jo")).as("filteredOn with consumer").hasSize(5);708 // THEN709 List<Throwable> errorsCollected = softly.errorsCollected();710 Assertions.assertThat(errorsCollected).hasSize(33);711 Assertions.assertThat(errorsCollected.get(0)).hasMessageContaining("gandalf");712 Assertions.assertThat(errorsCollected.get(1)).hasMessageContaining("frodo");713 Assertions.assertThat(errorsCollected.get(2)).hasMessageContaining("foo").hasMessageContaining("bar");714 Assertions.assertThat(errorsCollected.get(3)).hasMessageContaining("size");715 Assertions.assertThat(errorsCollected.get(4)).hasMessageContaining(fred.toString());716 Assertions.assertThat(errorsCollected.get(5)).hasMessageContaining(homer.toString());717 Assertions.assertThat(errorsCollected.get(6)).hasMessageContaining(bart.toString());718 Assertions.assertThat(errorsCollected.get(7)).hasMessageContaining(maggie.toString());719 Assertions.assertThat(errorsCollected.get(8)).hasMessageContaining(bart.toString());720 Assertions.assertThat(errorsCollected.get(9)).hasMessageContaining(maggie.toString());721 Assertions.assertThat(errorsCollected.get(10)).hasMessageContaining(homer.toString());722 Assertions.assertThat(errorsCollected.get(11)).hasMessageContaining(fred.toString());723 Assertions.assertThat(errorsCollected.get(12)).hasMessageContaining(homer.toString());724 Assertions.assertThat(errorsCollected.get(13)).hasMessageContaining(bart.toString());725 Assertions.assertThat(errorsCollected.get(14)).hasMessageContaining(fred.toString());726 Assertions.assertThat(errorsCollected.get(15)).hasMessageContaining(bart.toString());727 Assertions.assertThat(errorsCollected.get(16)).hasMessageContaining("Baggins");728 Assertions.assertThat(errorsCollected.get(17)).hasMessageContaining("Bilbo");729 Assertions.assertThat(errorsCollected.get(18)).hasMessageContaining("sam");730 Assertions.assertThat(errorsCollected.get(19)).hasMessageContaining("Aragorn");731 Assertions.assertThat(errorsCollected.get(20)).hasMessageContaining("123");732 Assertions.assertThat(errorsCollected.get(21)).hasMessageContaining("Sauron");733 Assertions.assertThat(errorsCollected.get(22)).hasMessageContaining("flatExtracting with multiple Extractors");734 Assertions.assertThat(errorsCollected.get(23)).hasMessageContaining("flatExtracting with multiple ThrowingExtractors");735 Assertions.assertThat(errorsCollected.get(24)).hasMessageContaining("Sam");736 Assertions.assertThat(errorsCollected.get(25)).hasMessageContaining("Ronaldo");737 Assertions.assertThat(errorsCollected.get(26)).hasMessageContaining("filteredOn with condition");738 Assertions.assertThat(errorsCollected.get(27)).hasMessageContaining("filteredOn firstName in {John, Frodo}");739 Assertions.assertThat(errorsCollected.get(28)).hasMessageContaining("filteredOn firstName = John");740 Assertions.assertThat(errorsCollected.get(29)).hasMessageContaining("filteredOn firstName = null");741 Assertions.assertThat(errorsCollected.get(30)).hasMessageContaining("using flatExtracting(String... fieldOrPropertyNames)");742 Assertions.assertThat(errorsCollected.get(31)).hasMessageContaining("using flatExtracting(String fieldOrPropertyName)");743 Assertions.assertThat(errorsCollected.get(32)).hasMessageContaining("filteredOn with consumer");744 }745 // the test would fail if any method was not proxyable as the assertion error would not be softly caught746 @SuppressWarnings("unchecked")747 @Test748 public void list_soft_assertions_should_report_errors_on_final_methods_and_methods_that_switch_the_object_under_test() {749 // GIVEN750 List<Name> names = Arrays.asList(Name.name("John", "Doe"), Name.name("Jane", "Doe"));751 List<CartoonCharacter> characters = Arrays.asList(homer, fred);752 // WHEN753 softly.then(names).extracting(Name::getFirst).contains("gandalf").contains("frodo");754 softly.then(names).extracting("last").containsExactly("foo", "bar");755 softly.then(characters).flatExtracting(CartoonCharacter::getChildren).as("using flatExtracting on Iterable").hasSize(1).containsAnyOf(homer, fred);756 softly.then(characters).flatExtracting(CartoonCharacter::getChildrenWithException).as("using flatExtracting on Iterable with exception").containsExactlyInAnyOrder(homer, fred);757 softly.then(characters).containsOnly(bart);758 softly.then(characters).containsOnlyOnce(maggie, bart);759 softly.then(characters).containsSequence(homer, bart);760 softly.then(characters).containsSubsequence(homer, maggie);761 softly.then(characters).doesNotContain(homer, maggie);762 softly.then(characters).doesNotContainSequence(fred);763 softly.then(characters).doesNotContainSubsequence(homer, fred);764 softly.then(characters).isSubsetOf(homer, bart);765 softly.then(characters).startsWith(fred);766 softly.then(characters).endsWith(bart);767 softly.then(names).extracting(Name::getFirst, Name::getLast).contains(Assertions.tuple("John", "Doe")).contains(Assertions.tuple("Frodo", "Baggins"));768 softly.then(names).extracting("first", "last").contains(Assertions.tuple("John", "Doe")).contains(Assertions.tuple("Bilbo", "Baggins"));769 softly.then(names).extracting(firstNameFunction).contains("John").contains("sam");770 softly.then(names).extracting("first", String.class).contains("John").contains("Aragorn");771 softly.then(names).filteredOn(( name) -> name.first.startsWith("Jo")).hasSize(123);772 softly.then(names).filteredOn(( name) -> name.first.startsWith("Jo")).extracting(firstNameFunction).contains("Sauron");773 softly.then(names).flatExtracting(firstNameFunction, lastNameFunction).as("flatExtracting with multiple Extractors").contains("John", "Jane", "Doe").contains("Sauron");774 softly.then(names).flatExtracting(throwingFirstNameExtractor, throwingLastNameExtractor).as("flatExtracting with multiple ThrowingExtractors").contains("John", "Jane", "Doe").contains("Sauron");775 softly.then(names).extractingResultOf("getFirst").contains("John", "Jane").contains("Sam", "Aragorn");776 softly.then(names).extractingResultOf("getFirst", String.class).contains("John", "Jane").contains("Messi", "Ronaldo");777 softly.then(names).filteredOn(new Condition(( name) -> name.first.startsWith("Jo"), "startsWith Jo")).as("filteredOn with condition").hasSize(5);778 softly.then(names).filteredOn("first", Assertions.in("John", "Frodo")).as("filteredOn firstName in {John, Frodo}").isEmpty();779 softly.then(names).filteredOn("first", "John").as("filteredOn firstName = John").isEmpty();780 softly.then(names).filteredOnNull("first").as("filteredOn firstName = null").isNotEmpty();781 softly.then(names).flatExtracting("first", "last").as("using flatExtracting(String... fieldOrPropertyNames)").contains("John", "Jane", "Doe").contains("Sauron");782 softly.then(characters).flatExtracting("children").as("using flatExtracting(String fieldOrPropertyName)").contains(bart, maggie).contains("Sauron");783 softly.then(names).filteredOnAssertions(( name) -> assertThat(name.first).startsWith("Jo")).as("filteredOn with consumer").hasSize(5);784 // THEN785 List<Throwable> errorsCollected = softly.errorsCollected();786 Assertions.assertThat(errorsCollected).hasSize(33);787 Assertions.assertThat(errorsCollected.get(0)).hasMessageContaining("gandalf");788 Assertions.assertThat(errorsCollected.get(1)).hasMessageContaining("frodo");789 Assertions.assertThat(errorsCollected.get(2)).hasMessageContaining("foo").hasMessageContaining("bar");790 Assertions.assertThat(errorsCollected.get(3)).hasMessageContaining("size");791 Assertions.assertThat(errorsCollected.get(4)).hasMessageContaining(fred.toString());792 Assertions.assertThat(errorsCollected.get(5)).hasMessageContaining(homer.toString());793 Assertions.assertThat(errorsCollected.get(6)).hasMessageContaining(bart.toString());794 Assertions.assertThat(errorsCollected.get(7)).hasMessageContaining(maggie.toString());795 Assertions.assertThat(errorsCollected.get(8)).hasMessageContaining(bart.toString());796 Assertions.assertThat(errorsCollected.get(9)).hasMessageContaining(maggie.toString());797 Assertions.assertThat(errorsCollected.get(10)).hasMessageContaining(homer.toString());798 Assertions.assertThat(errorsCollected.get(11)).hasMessageContaining(fred.toString());799 Assertions.assertThat(errorsCollected.get(12)).hasMessageContaining(homer.toString());800 Assertions.assertThat(errorsCollected.get(13)).hasMessageContaining(bart.toString());801 Assertions.assertThat(errorsCollected.get(14)).hasMessageContaining(fred.toString());802 Assertions.assertThat(errorsCollected.get(15)).hasMessageContaining(bart.toString());803 Assertions.assertThat(errorsCollected.get(16)).hasMessageContaining("Baggins");804 Assertions.assertThat(errorsCollected.get(17)).hasMessageContaining("Bilbo");805 Assertions.assertThat(errorsCollected.get(18)).hasMessageContaining("sam");806 Assertions.assertThat(errorsCollected.get(19)).hasMessageContaining("Aragorn");807 Assertions.assertThat(errorsCollected.get(20)).hasMessageContaining("123");808 Assertions.assertThat(errorsCollected.get(21)).hasMessageContaining("Sauron");809 Assertions.assertThat(errorsCollected.get(22)).hasMessageContaining("flatExtracting with multiple Extractors");810 Assertions.assertThat(errorsCollected.get(23)).hasMessageContaining("flatExtracting with multiple ThrowingExtractors");811 Assertions.assertThat(errorsCollected.get(24)).hasMessageContaining("Sam");812 Assertions.assertThat(errorsCollected.get(25)).hasMessageContaining("Ronaldo");813 Assertions.assertThat(errorsCollected.get(26)).hasMessageContaining("filteredOn with condition");814 Assertions.assertThat(errorsCollected.get(27)).hasMessageContaining("filteredOn firstName in {John, Frodo}");815 Assertions.assertThat(errorsCollected.get(28)).hasMessageContaining("filteredOn firstName = John");816 Assertions.assertThat(errorsCollected.get(29)).hasMessageContaining("filteredOn firstName = null");817 Assertions.assertThat(errorsCollected.get(30)).hasMessageContaining("using flatExtracting(String... fieldOrPropertyNames)");818 Assertions.assertThat(errorsCollected.get(31)).hasMessageContaining("using flatExtracting(String fieldOrPropertyName)");819 Assertions.assertThat(errorsCollected.get(32)).hasMessageContaining("filteredOn with consumer");820 }821 // the test would fail if any method was not proxyable as the assertion error would not be softly caught822 @SuppressWarnings("unchecked")823 @Test824 public void object_array_soft_assertions_should_report_errors_on_final_methods_and_methods_that_switch_the_object_under_test() {825 // GIVEN826 Name[] names = org.assertj.core.util.Arrays.array(Name.name("John", "Doe"), Name.name("Jane", "Doe"));827 CartoonCharacter[] characters = array(homer, fred);828 // WHEN829 softly.then(names).extracting(Name::getFirst).contains("gandalf").contains("frodo");830 softly.then(names).extracting("last").containsExactly("foo", "bar");831 softly.then(characters).flatExtracting(CartoonCharacter::getChildren).as("using flatExtracting on Iterable").hasSize(1).containsAnyOf(homer, fred);832 softly.then(characters).flatExtracting(CartoonCharacter::getChildrenWithException).as("using flatExtracting on Iterable with exception").containsExactlyInAnyOrder(homer, fred);833 softly.then(characters).containsOnly(bart);834 softly.then(characters).containsOnlyOnce(maggie, bart);835 softly.then(characters).containsSequence(homer, bart);836 softly.then(characters).containsSubsequence(homer, maggie);837 softly.then(characters).doesNotContain(homer, maggie);838 softly.then(characters).doesNotContainSequence(fred);839 softly.then(characters).doesNotContainSubsequence(homer, fred);840 softly.then(characters).isSubsetOf(homer, bart);841 softly.then(characters).startsWith(fred);842 softly.then(characters).endsWith(bart);843 softly.then(names).extracting(Name::getFirst, Name::getLast).contains(Assertions.tuple("John", "Doe")).contains(Assertions.tuple("Frodo", "Baggins"));844 softly.then(names).extracting("first", "last").contains(Assertions.tuple("John", "Doe")).contains(Assertions.tuple("Bilbo", "Baggins"));845 softly.then(names).extracting(firstNameFunction).contains("John").contains("sam");846 softly.then(names).extracting("first", String.class).contains("John").contains("Aragorn");847 softly.then(names).filteredOn(( name) -> name.first.startsWith("Jo")).hasSize(123);848 softly.then(names).filteredOn(( name) -> name.first.startsWith("Jo")).extracting(firstNameFunction).contains("Sauron");849 softly.then(names).extractingResultOf("getFirst").contains("John", "Jane").contains("Sam", "Aragorn");850 softly.then(names).extractingResultOf("getFirst", String.class).contains("John", "Jane").contains("Messi", "Ronaldo");851 softly.then(names).filteredOn(new Condition(( name) -> name.first.startsWith("Jo"), "startsWith Jo")).as("filteredOn with condition").hasSize(5);852 softly.then(names).filteredOn("first", Assertions.in("John", "Frodo")).as("filteredOn firstName in {John, Frodo}").isEmpty();853 softly.then(names).filteredOn("first", "John").as("filteredOn firstName = John").isEmpty();854 softly.then(names).filteredOnNull("first").as("filteredOn firstName = null").isNotEmpty();855 softly.then(characters).flatExtracting("children").as("using flatExtracting(String fieldOrPropertyName)").contains(bart, maggie).contains("Sauron");856 softly.then(names).filteredOnAssertions(( name) -> assertThat(name.first).startsWith("Jo")).as("filteredOn with consumer").hasSize(5);857 // THEN858 List<Throwable> errorsCollected = softly.errorsCollected();859 Assertions.assertThat(errorsCollected).hasSize(30);860 Assertions.assertThat(errorsCollected.get(0)).hasMessageContaining("gandalf");861 Assertions.assertThat(errorsCollected.get(1)).hasMessageContaining("frodo");862 Assertions.assertThat(errorsCollected.get(2)).hasMessageContaining("foo").hasMessageContaining("bar");863 Assertions.assertThat(errorsCollected.get(3)).hasMessageContaining("size");864 Assertions.assertThat(errorsCollected.get(4)).hasMessageContaining(fred.toString());865 Assertions.assertThat(errorsCollected.get(5)).hasMessageContaining(homer.toString());866 Assertions.assertThat(errorsCollected.get(6)).hasMessageContaining(bart.toString());867 Assertions.assertThat(errorsCollected.get(7)).hasMessageContaining(maggie.toString());868 Assertions.assertThat(errorsCollected.get(8)).hasMessageContaining(bart.toString());869 Assertions.assertThat(errorsCollected.get(9)).hasMessageContaining(maggie.toString());870 Assertions.assertThat(errorsCollected.get(10)).hasMessageContaining(homer.toString());871 Assertions.assertThat(errorsCollected.get(11)).hasMessageContaining(fred.toString());872 Assertions.assertThat(errorsCollected.get(12)).hasMessageContaining(homer.toString());873 Assertions.assertThat(errorsCollected.get(13)).hasMessageContaining(bart.toString());874 Assertions.assertThat(errorsCollected.get(14)).hasMessageContaining(fred.toString());875 Assertions.assertThat(errorsCollected.get(15)).hasMessageContaining(bart.toString());876 Assertions.assertThat(errorsCollected.get(16)).hasMessageContaining("Baggins");877 Assertions.assertThat(errorsCollected.get(17)).hasMessageContaining("Bilbo");878 Assertions.assertThat(errorsCollected.get(18)).hasMessageContaining("sam");879 Assertions.assertThat(errorsCollected.get(19)).hasMessageContaining("Aragorn");880 Assertions.assertThat(errorsCollected.get(20)).hasMessageContaining("123");881 Assertions.assertThat(errorsCollected.get(21)).hasMessageContaining("Sauron");882 Assertions.assertThat(errorsCollected.get(22)).hasMessageContaining("Sam");883 Assertions.assertThat(errorsCollected.get(23)).hasMessageContaining("Ronaldo");884 Assertions.assertThat(errorsCollected.get(24)).hasMessageContaining("filteredOn with condition");885 Assertions.assertThat(errorsCollected.get(25)).hasMessageContaining("filteredOn firstName in {John, Frodo}");886 Assertions.assertThat(errorsCollected.get(26)).hasMessageContaining("filteredOn firstName = John");887 Assertions.assertThat(errorsCollected.get(27)).hasMessageContaining("filteredOn firstName = null");888 Assertions.assertThat(errorsCollected.get(28)).hasMessageContaining("using flatExtracting(String fieldOrPropertyName)");889 Assertions.assertThat(errorsCollected.get(29)).hasMessageContaining("filteredOn with consumer");...

Full Screen

Full Screen

Source:org.assertj.core.api.BDDSoftAssertionsTest-should_be_able_to_catch_exceptions_thrown_by_all_proxied_methods.java Github

copy

Full Screen

...74 softly.then(new short[] { (short) 46 }).isEqualTo(new short[] { (short) 47 });75 softly.then("48").isEqualTo("49");76 softly.then(new Object() {77 @Override78 public String toString() {79 return "50";80 }81 }).isEqualTo(new Object() {82 @Override83 public String toString() {84 return "51";85 }86 });87 softly.then(new Object[] { new Object() {88 @Override89 public String toString() {90 return "52";91 }92 } }).isEqualTo(new Object[] { new Object() {93 @Override94 public String toString() {95 return "53";96 }97 } });98 final IllegalArgumentException illegalArgumentException = new IllegalArgumentException99 ("IllegalArgumentException message");100 softly.then(illegalArgumentException).hasMessage("NullPointerException message");101 softly.thenThrownBy(new ThrowingCallable() {102 @Override103 public void call() throws Exception {104 throw new Exception("something was wrong");105 }106 }).hasMessage("something was good");107 softly.assertAll();108 fail("Should not reach here");...

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.api.BDDSoftAssertionsTest;2public class Test {3 public static void main(String[] args) {4 BDDSoftAssertionsTest obj = new BDDSoftAssertionsTest();5 System.out.println(obj.toString());6 }7}8public class Test {9 public static void main(String[] args) {10 BDDSoftAssertionsTest obj = new BDDSoftAssertionsTest();11 System.out.println(obj);12 }13}

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1package org.assertj.core.api;2import static org.assertj.core.api.BDDAssertions.then;3import static org.assertj.core.api.BDDSoftAssertions.assertSoftly;4import org.junit.jupiter.api.Test;5public class BDDSoftAssertionsTest {6 void should_use_toString_method() {7 String string = assertSoftly(softly -> {8 softly.then(1).isEqualTo(1);9 softly.then(2).isEqualTo(2);10 }).toString();11 then(string).isEqualTo("Soft assertions failed:\n"12 + "but was not.");13 }14}15package org.assertj.core.api;16import static org.assertj.core.api.BDDAssertions.then;17import static org.assertj.core.api.SoftAssertions.assertSoftly;18import org.junit.jupiter.api.Test;19public class SoftAssertionsTest {20 void should_use_toString_method() {21 String string = assertSoftly(softly -> {22 softly.then(1).isEqualTo(1);23 softly.then(2).isEqualTo(2);24 }).toString();25 then(string).isEqualTo("Soft assertions failed:\n"26 + "but was not.");27 }28}29package org.assertj.core.api;30import static org.assertj.core.api.BDDAssertions.then;31import static

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.api.BDDSoftAssertions;2import org.assertj.core.api.BDDSoftAssertionsTest;3public class BDDSoftAssertionsTestToString {4 public static void main(String[] args) {5 BDDSoftAssertions softAssertions = new BDDSoftAssertions();6 BDDSoftAssertionsTest softAssertionsTest = new BDDSoftAssertionsTest();7 softAssertionsTest.should_collect_errors();8 System.out.println(softAssertions.toString());9 }10}

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.api.BDDSoftAssertions;2import org.assertj.core.api.BDDSoftAssertionsTest;3import org.assertj.core.api.SoftAssertions;4import org.junit.Test;5public class BDDSoftAssertionsTest1 {6 public void test1() {7 BDDSoftAssertions softly = new BDDSoftAssertions();

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1package org.assertj.core.api;2import java.io.*;3{4 public String toString()5 {6 return "BDDSoftAssertionsTest";7 }8}9{10 public static void main(String[] args)11 {12 BDDSoftAssertionsTest obj = new BDDSoftAssertionsTest();13 System.out.println(obj);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.

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