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

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

Source:BDDSoftAssertionsTest.java Github

copy

Full Screen

...86 private Function<Name, String> lastNameFunction;87 private Function<? super CartoonCharacter, ? extends Collection<CartoonCharacter>> childrenExtractor;88 @Test89 public void all_assertions_should_pass() {90 softly.then(1).isEqualTo(1);91 softly.then(Lists.newArrayList(1, 2)).containsOnly(1, 2);92 softly.assertAll();93 }94 @Test95 public void should_return_success_of_last_assertion() {96 softly.then(true).isFalse();97 softly.then(true).isEqualTo(true);98 Assertions.assertThat(softly.wasSuccess()).isTrue();99 }100 @Test101 public void should_return_success_of_last_assertion_with_nested_calls() {102 softly.then(true).isFalse();103 softly.then(true).isTrue();// isTrue() calls isEqualTo(true)104 Assertions.assertThat(softly.wasSuccess()).isTrue();105 }106 @Test107 public void should_return_failure_of_last_assertion() {108 softly.then(true).isTrue();109 softly.then(true).isEqualTo(false);110 Assertions.assertThat(softly.wasSuccess()).isFalse();111 }112 @Test113 public void should_return_failure_of_last_assertion_with_nested_calls() {114 softly.then(true).isTrue();115 softly.then(true).isFalse();// isFalse() calls isEqualTo(false)116 Assertions.assertThat(softly.wasSuccess()).isFalse();117 }118 @SuppressWarnings("unchecked")119 @Test120 public void should_be_able_to_catch_exceptions_thrown_by_map_assertions() {121 // GIVEN122 Map<String, String> map = Maps.mapOf(MapEntry.entry("54", "55"));123 // WHEN124 softly.then(map).contains(MapEntry.entry("1", "2")).isEmpty();125 // THEN126 List<Throwable> errors = softly.errorsCollected();127 Assertions.assertThat(errors).hasSize(2);128 Assertions.assertThat(errors.get(0)).hasMessageContaining(String.format(("Expecting:%n" + ((((" <{\"54\"=\"55\"}>%n" + "to contain:%n") + " <[MapEntry[key=\"1\", value=\"2\"]]>%n") + "but could not find:%n") + " <[MapEntry[key=\"1\", value=\"2\"]]>%n"))));129 Assertions.assertThat(errors.get(1)).hasMessageContaining(String.format("Expecting empty but was:<{\"54\"=\"55\"}>"));130 }131 @SuppressWarnings("unchecked")132 @Test133 public void should_be_able_to_catch_exceptions_thrown_by_all_proxied_methods() throws URISyntaxException {134 // GIVEN135 softly.then(BigDecimal.ZERO).isEqualTo(BigDecimal.ONE);136 softly.then(Boolean.FALSE).isTrue();137 softly.then(false).isTrue();138 softly.then(new boolean[]{ false }).isEqualTo(new boolean[]{ true });139 softly.then(new Byte(((byte) (0)))).isEqualTo(((byte) (1)));140 softly.then(((byte) (2))).inHexadecimal().isEqualTo(((byte) (3)));141 softly.then(new byte[]{ 4 }).isEqualTo(new byte[]{ 5 });142 softly.then(new Character(((char) (65)))).isEqualTo(new Character(((char) (66))));143 softly.then(((char) (67))).isEqualTo(((char) (68)));144 softly.then(new char[]{ 69 }).isEqualTo(new char[]{ 70 });145 softly.then(new StringBuilder("a")).isEqualTo(new StringBuilder("b"));146 softly.then(Object.class).isEqualTo(String.class);147 softly.then(DateUtil.parseDatetime("1999-12-31T23:59:59")).isEqualTo(DateUtil.parseDatetime("2000-01-01T00:00:01"));148 softly.then(new Double(6.0)).isEqualTo(new Double(7.0));149 softly.then(8.0).isEqualTo(9.0);150 softly.then(new double[]{ 10.0 }).isEqualTo(new double[]{ 11.0 });151 softly.then(new File("a")).overridingErrorMessage(String.format("%nExpecting:%n <File(a)>%nto be equal to:%n <File(b)>%nbut was not.")).isEqualTo(new File("b"));152 softly.then(new Float(12.0F)).isEqualTo(new Float(13.0F));153 softly.then(14.0F).isEqualTo(15.0F);154 softly.then(new float[]{ 16.0F }).isEqualTo(new float[]{ 17.0F });155 softly.then(new ByteArrayInputStream(new byte[]{ ((byte) (65)) })).hasSameContentAs(new ByteArrayInputStream(new byte[]{ ((byte) (66)) }));156 softly.then(new Integer(20)).isEqualTo(new Integer(21));157 softly.then(22).isEqualTo(23);158 softly.then(new int[]{ 24 }).isEqualTo(new int[]{ 25 });159 softly.then(((Iterable<String>) (Lists.newArrayList("26")))).isEqualTo(Lists.newArrayList("27"));160 softly.then(Lists.newArrayList("28").iterator()).isExhausted();161 softly.then(Lists.newArrayList("30")).isEqualTo(Lists.newArrayList("31"));162 softly.then(new Long(32L)).isEqualTo(new Long(33L));163 softly.then(34L).isEqualTo(35L);164 softly.then(new long[]{ 36L }).isEqualTo(new long[]{ 37L });165 softly.then(Maps.mapOf(MapEntry.entry("38", "39"))).isEqualTo(Maps.mapOf(MapEntry.entry("40", "41")));166 softly.then(new Short(((short) (42)))).isEqualTo(new Short(((short) (43))));167 softly.then(((short) (44))).isEqualTo(((short) (45)));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");890 }891 // the test would fail if any method was not proxyable as the assertion error would not be softly caught892 @SuppressWarnings("unchecked")893 @Test894 public void class_soft_assertions_should_report_errors_on_final_methods() {895 // GIVEN896 Class<ClassAssertBaseTest.AnnotatedClass> actual = ClassAssertBaseTest.AnnotatedClass.class;897 // WHEN898 softly.then(actual).hasAnnotations(ClassAssertBaseTest.MyAnnotation.class, ClassAssertBaseTest.AnotherAnnotation.class).hasAnnotations(SafeVarargs.class, VisibleForTesting.class);899 // THEN900 List<Throwable> errorsCollected = softly.errorsCollected();901 Assertions.assertThat(errorsCollected).hasSize(1);902 Assertions.assertThat(errorsCollected.get(0)).hasMessageContaining("SafeVarargs").hasMessageContaining("VisibleForTesting");903 }904 // the test would fail if any method was not proxyable as the assertion error would not be softly caught905 @SuppressWarnings("unchecked")906 @Test907 public void object_soft_assertions_should_report_errors_on_final_methods_and_methods_that_switch_the_object_under_test() {908 // GIVEN909 Name name = Name.name("John", "Doe");910 Object alphabet = "abcdefghijklmnopqrstuvwxyz";911 Object vowels = Arrays.asList("a", "e", "i", "o", "u");912 // WHEN913 softly.then(name).extracting("first", "last").contains("John").contains("gandalf");914 softly.then(name).extracting(Name::getFirst, Name::getLast).contains("John").contains("frodo");915 softly.then(alphabet).asString().startsWith("abc").startsWith("123");916 softly.then(vowels).asList().startsWith("a", "e").startsWith("1", "2");917 softly.then(name).as("extracting(Name::getFirst)").overridingErrorMessage("error message").extracting(Name::getFirst).isEqualTo("Jack");918 // THEN919 List<Throwable> errorsCollected = softly.errorsCollected();920 Assertions.assertThat(errorsCollected).hasSize(5);921 Assertions.assertThat(errorsCollected.get(0)).hasMessageContaining("gandalf");922 Assertions.assertThat(errorsCollected.get(1)).hasMessageContaining("frodo");923 Assertions.assertThat(errorsCollected.get(2)).hasMessageContaining("123");924 Assertions.assertThat(errorsCollected.get(3)).hasMessageContaining("\"1\", \"2\"");925 Assertions.assertThat(errorsCollected.get(4)).hasMessage("[extracting(Name::getFirst)] error message");926 }927 // the test would fail if any method was not proxyable as the assertion error would not be softly caught928 @SuppressWarnings("unchecked")929 @Test930 public void map_soft_assertions_should_report_errors_on_final_methods_and_methods_that_switch_the_object_under_test() {931 // GIVEN932 Map<String, String> map = Maps.mapOf(Assertions.entry("a", "1"), Assertions.entry("b", "2"), Assertions.entry("c", "3"));933 // WHEN934 softly.then(map).contains(Assertions.entry("abc", "ABC"), Assertions.entry("def", "DEF")).isEmpty();935 softly.then(map).containsAnyOf(Assertions.entry("gh", "GH"), Assertions.entry("ij", "IJ"));936 softly.then(map).containsExactly(Assertions.entry("kl", "KL"), Assertions.entry("mn", "MN"));937 softly.then(map).containsKeys("K1", "K2");938 softly.then(map).containsOnly(Assertions.entry("op", "OP"), Assertions.entry("qr", "QR"));939 softly.then(map).containsOnlyKeys("K3", "K4");940 softly.then(map).containsValues("V1", "V2");941 softly.then(map).doesNotContain(Assertions.entry("a", "1"), Assertions.entry("abc", "ABC"));942 softly.then(map).doesNotContainKeys("a", "b");943 softly.then(map).extracting("a", "b").contains("456");944 softly.then(iterableMap).flatExtracting("name", "job", "city", "rank").contains("Unexpected", "Builder", "Dover", "Boston", "Paris", 1, 2, 3);945 Map<String, String> exactlyEntriesMap = Maps.mapOf(Assertions.entry("kl", "KL"), Assertions.entry("mn", "MN"));946 softly.then(map).containsExactlyEntriesOf(exactlyEntriesMap);947 // softly.then(map).size().isGreaterThan(1000); not yet supported948 // THEN949 List<Throwable> errors = softly.errorsCollected();950 Assertions.assertThat(errors).hasSize(13);951 Assertions.assertThat(errors.get(0)).hasMessageContaining("MapEntry[key=\"abc\", value=\"ABC\"]");952 Assertions.assertThat(errors.get(1)).hasMessageContaining("empty");953 Assertions.assertThat(errors.get(2)).hasMessageContaining("gh").hasMessageContaining("IJ");954 Assertions.assertThat(errors.get(3)).hasMessageContaining("\"a\"=\"1\"");955 Assertions.assertThat(errors.get(4)).hasMessageContaining("K2");956 Assertions.assertThat(errors.get(5)).hasMessageContaining("OP");957 Assertions.assertThat(errors.get(6)).hasMessageContaining("K4");958 Assertions.assertThat(errors.get(7)).hasMessageContaining("V2");959 Assertions.assertThat(errors.get(8)).hasMessageContaining("ABC");960 Assertions.assertThat(errors.get(9)).hasMessageContaining("b");961 Assertions.assertThat(errors.get(10)).hasMessageContaining("456");962 Assertions.assertThat(errors.get(11)).hasMessageContaining("Unexpected");963 Assertions.assertThat(errors.get(12)).hasMessageContaining("\"a\"=\"1\"");964 }965 @Test966 public void map_soft_assertions_should_work_with_navigation_methods() {967 // GIVEN968 Map<String, String> map = Maps.mapOf(Assertions.entry("a", "1"), Assertions.entry("b", "2"), Assertions.entry("c", "3"));969 // WHEN970 softly.then(map).size().isGreaterThan(10);971 softly.then(map).size().isGreaterThan(1).returnToMap().as("returnToMap").isEmpty();972 softly.then(map).size().isGreaterThan(1).returnToMap().containsKey("nope").size().as("check size after navigating back").isLessThan(2);973 // THEN974 List<Throwable> errorsCollected = softly.errorsCollected();975 Assertions.assertThat(errorsCollected).hasSize(4);976 Assertions.assertThat(errorsCollected.get(0)).hasMessageContaining("10");977 Assertions.assertThat(errorsCollected.get(1)).hasMessageContaining("returnToMap");978 Assertions.assertThat(errorsCollected.get(2)).hasMessageContaining("nope");979 Assertions.assertThat(errorsCollected.get(3)).hasMessageContaining("check size after navigating back");980 }981 @SuppressWarnings("unchecked")982 @Test983 public void predicate_soft_assertions_should_report_errors_on_final_methods() {984 // GIVEN985 Predicate<MapEntry<String, String>> ballSportPredicate = ( sport) -> sport.value.contains("ball");986 // WHEN987 softly.then(ballSportPredicate).accepts(Assertions.entry("sport", "boxing"), Assertions.entry("sport", "marathon")).rejects(Assertions.entry("sport", "football"), Assertions.entry("sport", "basketball"));988 // THEN989 List<Throwable> errorsCollected = softly.errorsCollected();990 Assertions.assertThat(errorsCollected).hasSize(2);991 Assertions.assertThat(errorsCollected.get(0)).hasMessageContaining("boxing");992 Assertions.assertThat(errorsCollected.get(1)).hasMessageContaining("basketball");993 }994 @Test995 public void soft_assertions_should_work_with_satisfiesAnyOf() {996 // GIVEN997 TolkienCharacter legolas = TolkienCharacter.of("Legolas", 1000, ELF);998 Consumer<TolkienCharacter> isHobbit = ( tolkienCharacter) -> Assertions.assertThat(tolkienCharacter.getRace()).isEqualTo(HOBBIT);999 Consumer<TolkienCharacter> isMan = ( tolkienCharacter) -> Assertions.assertThat(tolkienCharacter.getRace()).isEqualTo(MAN);1000 // WHEN1001 softly.then(legolas).as("satisfiesAnyOf").satisfiesAnyOf(isHobbit, isMan);1002 // THEN1003 List<Throwable> errorsCollected = softly.errorsCollected();1004 Assertions.assertThat(errorsCollected).hasSize(1);1005 Assertions.assertThat(errorsCollected.get(0)).hasMessageContaining("[satisfiesAnyOf] ").hasMessageContaining("HOBBIT").hasMessageContaining("ELF").hasMessageContaining("MAN");1006 }1007 @Test1008 public void soft_assertions_should_work_with_thenObject() {1009 // GIVEN1010 TolkienCharacter legolas = TolkienCharacter.of("Legolas", 1000, ELF);1011 Deque<TolkienCharacter> characters = new LinkedList<>(Arrays.asList(legolas));1012 Consumer<Deque<TolkienCharacter>> isFirstHobbit = ( tolkienCharacters) -> Assertions.assertThat(tolkienCharacters.getFirst().getRace()).isEqualTo(HOBBIT);1013 Consumer<Deque<TolkienCharacter>> isFirstMan = ( tolkienCharacters) -> Assertions.assertThat(tolkienCharacters.getFirst().getRace()).isEqualTo(MAN);1014 // WHEN1015 softly.thenObject(characters).as("assertThatObject#satisfiesAnyOf").satisfiesAnyOf(isFirstHobbit, isFirstMan);1016 // THEN1017 List<Throwable> errorsCollected = softly.errorsCollected();1018 Assertions.assertThat(errorsCollected).hasSize(1);1019 Assertions.assertThat(errorsCollected.get(0)).hasMessageContaining("[assertThatObject#satisfiesAnyOf] ").hasMessageContaining("HOBBIT").hasMessageContaining("ELF").hasMessageContaining("MAN");1020 }1021 @Nested1022 class ExtractingFromEntries {1023 // GIVEN1024 Person aceVentura = new Person("ace ventura");1025 Person david = new Person("david");1026 Map<Person, List<Animal>> map = Maps.mapOf(MapEntry.entry(aceVentura, Lists.list(new Animal("spike"))), MapEntry.entry(david, Lists.list(new Animal("scoubi"), new Animal("peter"))));1027 @Test1028 @SuppressWarnings("unchecked")1029 void should_pass_when_using_extractingFromEntries_with_map() {1030 // WHEN1031 softly.then(map).extractingFromEntries(Map.Entry::getKey).containsExactlyInAnyOrder(aceVentura, david);1032 softly.then(map).extractingFromEntries(Map.Entry::getKey, ( entry) -> entry.getValue().size()).containsExactlyInAnyOrder(Assertions.tuple(aceVentura, 1), Assertions.tuple(david, 2));1033 // THEN1034 softly.assertAll();1035 }1036 @Test1037 @SuppressWarnings("unchecked")1038 void should_collect_errors_when_using_extractingFromEntries_with_map() {1039 // WHEN1040 softly.then(map).extractingFromEntries(Map.Entry::getKey).containsExactlyInAnyOrder(Assertions.tuple(aceVentura), Assertions.tuple(new Person("stranger")));1041 softly.then(map).overridingErrorMessage("overridingErrorMessage with extractingFromEntries").extractingFromEntries(( entry) -> entry.getKey().getName()).containsExactlyInAnyOrder(Assertions.tuple("ace ventura", Assertions.tuple("johnny")));1042 softly.then(map).extractingFromEntries(Map.Entry::getKey, ( entry) -> entry.getValue().size()).containsExactlyInAnyOrder(Assertions.tuple(aceVentura, 10), Assertions.tuple(david, 2));1043 // THEN1044 List<Throwable> errorsCollected = softly.errorsCollected();1045 Assertions.assertThat(errorsCollected).hasSize(3);1046 Assertions.assertThat(errorsCollected.get(0)).hasMessageFindingMatch("not found:.*stranger.*not expected:.*david");1047 Assertions.assertThat(errorsCollected.get(1)).hasMessage("overridingErrorMessage with extractingFromEntries");1048 Assertions.assertThat(errorsCollected.get(2)).hasMessageFindingMatch("not found:.*10.*not expected:.*1");1049 }1050 }1051}...

Full Screen

Full Screen

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

copy

Full Screen

...33 }34 35 @Test36 public void all_assertions_should_pass() {37 softly.then(1).isEqualTo(1);38 softly.then(Lists.newArrayList(1, 2)).containsOnly(1, 2);39 softly.assertAll();40 }41}...

Full Screen

Full Screen

then

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.api.BDDSoftAssertions;2import org.assertj.core.api.BDDSoftAssertionsTest;3import org.junit.jupiter.api.Test;4import org.junit.jupiter.api.extension.ExtendWith;5import org.junit.jupiter.api.extension.RegisterExtension;6import org.junit.jupiter.api.extension.TestExecutionExceptionHandler;7import org.junit.jupiter.api.extension.TestExtensionContext;8import org.junit.jupiter.api.extension.TestInstantiationException;9import org.junit.jupiter.api.extension.TestInstantiationException.TestInstantiationExceptionSupplier;10import org.junit.jupiter.api.extension.TestInstantiationException.TestInstant

Full Screen

Full Screen

then

Using AI Code Generation

copy

Full Screen

1package org.assertj.core.api;2import org.junit.jupiter.api.Test;3import org.junit.jupiter.api.extension.ExtendWith;4import org.junit.jupiter.api.extension.RegisterExtension;5import org.mockito.junit.jupiter.MockitoExtension;6import org.mockito.junit.jupiter.MockitoSettings;7import org.mockito.quality.Strictness;8import static org.assertj.core.api.BDDAssertions.then;9import static org.assertj.core.api.BDDSoftAssertionsTest.BDDSoftAssertionsExtension;10import static org.mockito.Mockito.mock;11import static org.mockito.Mockito.when;12@ExtendWith(MockitoExtension.class)13@MockitoSettings(strictness = Strictness.LENIENT)14class BDDSoftAssertionsTest {15 BDDSoftAssertionsExtension softAssertions = new BDDSoftAssertionsExtension();16 void should_work_with_mockito() {17 Person person = mock(Person.class);18 when(person.getName()).thenReturn("John");19 String name = person.getName();20 then(name).as("name").isEqualTo("John");21 }22 static class BDDSoftAssertionsExtension extends BDDSoftAssertions {23 }24 interface Person {25 String getName();26 }27}28package org.assertj.core.api;29import org.junit.jupiter.api.Test;30import static org.assertj.core.api.BDDAssertions.then;31class BDDSoftAssertionsTest {32 void should_work_with_mockito() {33 String name = "John";34 then(name).as("name").isEqualTo("John");35 }36}

Full Screen

Full Screen

then

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.api.BDDSoftAssertions;2import org.assertj.core.api.BDDSoftAssertionsTest;3public class Test1 {4 public static void main(String[] args) {5 BDDSoftAssertions softAssertions = new BDDSoftAssertions();6 BDDSoftAssertionsTest test = new BDDSoftAssertionsTest();7 test.then(softAssertions);8 }9}

Full Screen

Full Screen

then

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.api.BDDSoftAssertions;2import org.assertj.core.api.BDDSoftAssertionsTest;3import org.junit.Test;4public class BDDSoftAssertionsTest {5 public void test() {6 BDDSoftAssertions softly = new BDDSoftAssertions();7 softly.then(BDDSoftAssertionsTest.class).isNotNull();8 softly.then("test").isEqualTo("test");9 softly.assertAll();10 }11}12org.assertj.core.api.BDDSoftAssertionsTest > test() FAILED13 at org.assertj.core.api.BDDSoftAssertions.assertAll(BDDSoftAssertions.java:82)

Full Screen

Full Screen

then

Using AI Code Generation

copy

Full Screen

1public class 1 {2 public void test1() {3 BDDSoftAssertions softly = new BDDSoftAssertions();4 softly.then(1).isEqualTo(1);5 }6}7public class 2 {8 public void test2() {9 SoftAssertions softly = new SoftAssertions();10 softly.then(1).isEqualTo(1);11 }12}13public class 3 {14 public void test3() {15 BDDSoftAssertions softly = new BDDSoftAssertions();16 softly.then(1).isEqualTo(1);17 }18}19public class 4 {20 public void test4() {21 SoftAssertions softly = new SoftAssertions();22 softly.then(1).isEqualTo(1);23 }24}25public class 5 {26 public void test5() {27 BDDSoftAssertions softly = new BDDSoftAssertions();28 softly.then(1).isEqualTo(1);29 }30}31public class 6 {32 public void test6() {33 SoftAssertions softly = new SoftAssertions();34 softly.then(1).isEqualTo(1);35 }36}37public class 7 {38 public void test7() {39 BDDSoftAssertions softly = new BDDSoftAssertions();40 softly.then(1).isEqualTo(1);41 }42}43public class 8 {44 public void test8() {45 SoftAssertions softly = new SoftAssertions();46 softly.then(1).isEqualTo(1);47 }48}

Full Screen

Full Screen

then

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.api.BDDSoftAssertions;2import org.assertj.core.api.BDDSoftAssertionsTest;3import org.junit.jupiter.api.Test;4import static org.assertj.core.api.BDDSoftAssertionsTest.then;5public class BDDSoftAssertionsTest {6 void test() {7 BDDSoftAssertions softly = new BDDSoftAssertions();8 softly.then("foo").isEqualTo("bar");9 softly.then("foo").isEqualTo("foo");10 softly.then("foo").isNotEqualTo("foo");11 softly.then("foo").isNotEqualTo("bar");12 softly.then("foo").isEqualTo("bar");13 softly.assertAll();14 }15}

Full Screen

Full Screen

then

Using AI Code Generation

copy

Full Screen

1package org.assertj.core.api;2import org.assertj.core.api.BDDSoftAssertions;3import org.junit.jupiter.api.Test;4public class BDDSoftAssertionsTest {5public void test() {6BDDSoftAssertions softAssertions = new BDDSoftAssertions();7softAssertions.then("test").isNotEmpty();8softAssertions.assertAll();9}10}11at org.assertj.core.api.BDDSoftAssertionsTest.test(BDDSoftAssertionsTest.java:12)12at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)13at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)14at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)15at java.base/java.lang.reflect.Method.invoke(Method.java:566)16at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:686)17at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)18at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)19at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:149)20at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:140)21at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:84)22at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)23at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)24at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)25at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)26at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)27at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)28at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)29at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98)30at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:210)

Full Screen

Full Screen

then

Using AI Code Generation

copy

Full Screen

1import org.junit.Test;2import static org.assertj.core.api.BDDAssertions.then;3public class 1 {4public void test() {5int a = 1;6int b = 2;7then(a).isLessThan(b);8}9}

Full Screen

Full Screen

then

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.api.BDDSoftAssertions;2import org.assertj.core.api.BDDSoftAssertionsTest;3import org.junit.jupiter.api.Test;4import org.mockito.internal.util.reflection.Whitebox;5public class Main {6 public void test() {7 BDDSoftAssertions softly = new BDDSoftAssertions();8 BDDSoftAssertionsTest softlyTest = new BDDSoftAssertionsTest();9 Runnable runnable = (Runnable) Whitebox.getInternalState(softlyTest, "runnable");10 softly.then(runnable).isNotNull();11 }12}13import org.assertj.core.api.BDDSoftAssertions;14import org.junit.jupiter.api.Test;15public class Main {16 public void test() {17 BDDSoftAssertions softly = new BDDSoftAssertions();18 softly.then((Runnable) () -> {19 }).isNotNull();20 }21}22import org.assertj.core.api.BDDSoftAssertions;23import org.junit.jupiter.api.Test;24public class Main {25 public void test() {26 BDDSoftAssertions softly = new BDDSoftAssertions();27 softly.then((Runnable) () -> {28 }).isNotNull();29 }30}31import org.assertj.core.api.BDDSoftAssertions;32import org.junit.jupiter.api.Test;33public class Main {34 public void test() {35 BDDSoftAssertions softly = new BDDSoftAssertions();36 softly.then((Runnable) () -> {37 }).isNotNull();38 }39}40import org.assertj.core.api.BDDSoftAssertions;41import org.junit.jupiter.api.Test;42public class Main {43 public void test() {44 BDDSoftAssertions softly = new BDDSoftAssertions();45 softly.then((Runnable) () -> {46 }).isNotNull();47 }48}49import org.assertj.core.api.BDDSoftAssertions;50import org.junit.jupiter.api.Test;51public class Main {52 public void test() {53 BDDSoftAssertions softly = new BDDSoftAssertions();54 softly.then((Runnable) () -> {55 }).isNotNull();56 }57}58import org.assertj.core.api.BDDSoftAssertions;59import org.junit.jupiter.api.Test;60public class Main {61 public void test() {

Full Screen

Full Screen

then

Using AI Code Generation

copy

Full Screen

1package org.assertj.core.api;2import static org.assertj.core.api.BDDAssertions.then;3import org.junit.Test;4public class BDDSoftAssertionsTest {5 public void bddSoftAssertionsTest() {6 then("foo").isEqualTo("foo");7 then("bar").isEqualTo("bar");8 }9}10package org.assertj.core.api;11import static org.assertj.core.api.BDDAssertions.then;12import org.junit.Test;13public class BDDSoftAssertionsTest {14 public void bddSoftAssertionsTest() {15 then("foo").isEqualTo("foo");16 then("bar").isEqualTo("bar");17 }18}19package org.assertj.core.api;20import static org.assertj.core.api.BDDAssertions.then;21import org.junit.Test;22public class BDDSoftAssertionsTest {23 public void bddSoftAssertionsTest() {24 then("foo").isEqualTo("foo");25 then("bar").isEqualTo("bar");26 }27}28package org.assertj.core.api;29import static org.assertj.core.api.BDDAssertions.then;30import org.junit.Test;31public class BDDSoftAssertionsTest {32 public void bddSoftAssertionsTest() {33 then("foo").isEqualTo("foo");34 then("bar").isEqualTo("bar");35 }36}37package org.assertj.core.api;38import static org.assertj.core.api.BDDAssertions.then;39import org.junit.Test;40at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)41at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)42at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)43at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)44at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)45at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)46at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98)47at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:210)

Full Screen

Full Screen

then

Using AI Code Generation

copy

Full Screen

1import org.junit.Test;2import static org.assertj.core.api.BDDAssertions.then;3public class 1 {4public void test() {5int a = 1;6int b = 2;7then(a).isLessThan(b);8}9}

Full Screen

Full Screen

then

Using AI Code Generation

copy

Full Screen

1package org.assertj.core.api;2import static org.assertj.core.api.BDDAssertions.then;3import org.junit.Test;4public class BDDSoftAssertionsTest {5 public void bddSoftAssertionsTest() {6 then("foo").isEqualTo("foo");7 then("bar").isEqualTo("bar");8 }9}10package org.assertj.core.api;11import static org.assertj.core.api.BDDAssertions.then;12import org.junit.Test;13public class BDDSoftAssertionsTest {14 public void bddSoftAssertionsTest() {15 then("foo").isEqualTo("foo");16 then("bar").isEqualTo("bar");17 }18}19package org.assertj.core.api;20import static org.assertj.core.api.BDDAssertions.then;21import org.junit.Test;22public class BDDSoftAssertionsTest {23 public void bddSoftAssertionsTest() {24 then("foo").isEqualTo("foo");25 then("bar").isEqualTo("bar");26 }27}28package org.assertj.core.api;29import static org.assertj.core.api.BDDAssertions.then;30import org.junit.Test;31public class BDDSoftAssertionsTest {32 public void bddSoftAssertionsTest() {33 then("foo").isEqualTo("foo");34 then("bar").isEqualTo("bar");35 }36}37package org.assertj.core.api;38import static org.assertj.core.api.BDDAssertions.then;39import org.junit.Test;

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