How to use StandardRepresentation method of org.assertj.core.presentation.StandardRepresentation_throwable_format_Test class

Best Assertj code snippet using org.assertj.core.presentation.StandardRepresentation_throwable_format_Test.StandardRepresentation

Source:Java6Assertions.java Github

copy

Full Screen

...55import org.assertj.core.data.Offset;56import org.assertj.core.data.Percentage;57import org.assertj.core.groups.Properties;58import org.assertj.core.groups.Tuple;59import org.assertj.core.presentation.StandardRepresentation;60import org.assertj.core.util.CanIgnoreReturnValue;61import org.assertj.core.util.CheckReturnValue;62import org.assertj.core.util.Files;63import org.assertj.core.util.URLs;64import org.assertj.core.util.introspection.FieldSupport;65/**66 * @deprecated For Android compatible assertions use the latest assertj 2.x version which is based on Java 7 only.67 * <p>68 * Assertions compatible with Android. Duplicated from {@link Assertions}.69 *70 * @see Assertions71 */72@CheckReturnValue73@Deprecated74public class Java6Assertions {75 /**76 * Create assertion for {@link AtomicBoolean}.77 *78 * @param actual the actual value.79 *80 * @return the created assertion object.81 * @since 2.7.0 / 3.7.082 */83 public static AtomicBooleanAssert assertThat(AtomicBoolean actual) {84 return new AtomicBooleanAssert(actual);85 }86 /**87 * Create assertion for {@link AtomicInteger}.88 *89 * @param actual the actual value.90 *91 * @return the created assertion object.92 * @since 2.7.0 / 3.7.093 */94 public static AtomicIntegerAssert assertThat(AtomicInteger actual) {95 return new AtomicIntegerAssert(actual);96 }97 /**98 * Create int[] assertion for {@link AtomicIntegerArray}.99 *100 * @param actual the actual value.101 *102 * @return the created assertion object.103 * @since 2.7.0 / 3.7.0104 */105 public static AtomicIntegerArrayAssert assertThat(AtomicIntegerArray actual) {106 return new AtomicIntegerArrayAssert(actual);107 }108 /**109 * Create assertion for {@link AtomicIntegerFieldUpdater}.110 *111 * @param actual the actual value.112 *113 * @param <OBJECT> the type of the object holding the updatable field.114 * @return the created assertion object.115 * @since 2.7.0 / 3.7.0116 */117 public static <OBJECT> AtomicIntegerFieldUpdaterAssert<OBJECT> assertThat(AtomicIntegerFieldUpdater<OBJECT> actual) {118 return new AtomicIntegerFieldUpdaterAssert<>(actual);119 }120 /**121 * Create assertion for {@link AtomicLong}.122 *123 * @param actual the actual value.124 *125 * @return the created assertion object.126 * @since 2.7.0 / 3.7.0127 */128 public static AtomicLongAssert assertThat(AtomicLong actual) {129 return new AtomicLongAssert(actual);130 }131 /**132 * Create assertion for {@link AtomicLongArray}.133 *134 * @param actual the actual value.135 *136 * @return the created assertion object.137 * @since 2.7.0 / 3.7.0138 */139 public static AtomicLongArrayAssert assertThat(AtomicLongArray actual) {140 return new AtomicLongArrayAssert(actual);141 }142 /**143 * Create assertion for {@link AtomicLongFieldUpdater}.144 *145 * @param actual the actual value.146 *147 * @param <OBJECT> the type of the object holding the updatable field.148 * @return the created assertion object.149 * @since 2.7.0 / 3.7.0150 */151 public static <OBJECT> AtomicLongFieldUpdaterAssert<OBJECT> assertThat(AtomicLongFieldUpdater<OBJECT> actual) {152 return new AtomicLongFieldUpdaterAssert<>(actual);153 }154 /**155 * Create assertion for {@link AtomicReference}.156 *157 * @param actual the actual value.158 * @param <VALUE> the type of the value contained in the {@link AtomicReference}.159 *160 * @return the created assertion object.161 * @since 2.7.0 / 3.7.0162 */163 public static <VALUE> AtomicReferenceAssert<VALUE> assertThat(AtomicReference<VALUE> actual) {164 return new AtomicReferenceAssert<>(actual);165 }166 /**167 * Create assertion for {@link AtomicReferenceArray}.168 *169 * @param actual the actual value.170 * @param <ELEMENT> the type of the value contained in the {@link AtomicReferenceArray}.171 *172 * @return the created assertion object.173 * @since 2.7.0 / 3.7.0174 */175 public static <ELEMENT> AtomicReferenceArrayAssert<ELEMENT> assertThat(AtomicReferenceArray<ELEMENT> actual) {176 return new AtomicReferenceArrayAssert<>(actual);177 }178 /**179 * Create assertion for {@link AtomicReferenceFieldUpdater}.180 *181 * @param actual the actual value.182 * @param <FIELD> the type of the field which gets updated by the {@link AtomicReferenceFieldUpdater}.183 * @param <OBJECT> the type of the object holding the updatable field.184 *185 * @return the created assertion object.186 * @since 2.7.0 / 3.7.0187 */188 public static <FIELD, OBJECT> AtomicReferenceFieldUpdaterAssert<FIELD, OBJECT> assertThat(AtomicReferenceFieldUpdater<OBJECT, FIELD> actual) {189 return new AtomicReferenceFieldUpdaterAssert<>(actual);190 }191 /**192 * Create assertion for {@link AtomicMarkableReference}.193 *194 * @param actual the actual value.195 * @param <VALUE> the type of the value contained in the {@link AtomicMarkableReference}.196 *197 * @return the created assertion object.198 * @since 2.7.0 / 3.7.0199 */200 public static <VALUE> AtomicMarkableReferenceAssert<VALUE> assertThat(AtomicMarkableReference<VALUE> actual) {201 return new AtomicMarkableReferenceAssert<>(actual);202 }203 /**204 * Create assertion for {@link AtomicStampedReference}.205 *206 * @param actual the actual value.207 * @param <VALUE> the type of the value contained in the {@link AtomicStampedReference}.208 *209 * @return the created assertion object.210 * @since 2.7.0 / 3.7.0211 */212 public static <VALUE> AtomicStampedReferenceAssert<VALUE> assertThat(AtomicStampedReference<VALUE> actual) {213 return new AtomicStampedReferenceAssert<>(actual);214 }215 /**216 * Creates a new instance of <code>{@link BigDecimalAssert}</code>.217 *218 * @param actual the actual value.219 * @return the created assertion object.220 */221 public static AbstractBigDecimalAssert<?> assertThat(BigDecimal actual) {222 return new BigDecimalAssert(actual);223 }224 /**225 * Creates a new instance of <code>{@link BigIntegerAssert}</code>.226 *227 * @param actual the actual value.228 * @return the created assertion object.229 * @since 2.7.0 / 3.7.0230 */231 public static AbstractBigIntegerAssert<?> assertThat(BigInteger actual) {232 return new BigIntegerAssert(actual);233 }234 /**235 * Creates a new instance of <code>{@link UriAssert}</code>.236 *237 * @param actual the actual value.238 * @return the created assertion object.239 */240 public static AbstractUriAssert<?> assertThat(URI actual) {241 return new UriAssert(actual);242 }243 /**244 * Creates a new instance of <code>{@link UrlAssert}</code>.245 *246 * @param actual the actual value.247 * @return the created assertion object.248 */249 public static AbstractUrlAssert<?> assertThat(URL actual) {250 return new UrlAssert(actual);251 }252 /**253 * Creates a new instance of <code>{@link BooleanAssert}</code>.254 *255 * @param actual the actual value.256 * @return the created assertion object.257 */258 public static AbstractBooleanAssert<?> assertThat(boolean actual) {259 return new BooleanAssert(actual);260 }261 /**262 * Creates a new instance of <code>{@link BooleanAssert}</code>.263 *264 * @param actual the actual value.265 * @return the created assertion object.266 */267 public static AbstractBooleanAssert<?> assertThat(Boolean actual) {268 return new BooleanAssert(actual);269 }270 /**271 * Creates a new instance of <code>{@link BooleanArrayAssert}</code>.272 *273 * @param actual the actual value.274 * @return the created assertion object.275 */276 public static AbstractBooleanArrayAssert<?> assertThat(boolean[] actual) {277 return new BooleanArrayAssert(actual);278 }279 /**280 * Creates a new instance of <code>{@link Boolean2DArrayAssert}</code>.281 *282 * @param actual the actual value.283 * @return the created assertion object.284 * @since 3.17.0285 */286 public static Boolean2DArrayAssert assertThat(boolean[][] actual) {287 return new Boolean2DArrayAssert(actual);288 }289 /**290 * Creates a new instance of <code>{@link ByteAssert}</code>.291 *292 * @param actual the actual value.293 * @return the created assertion object.294 */295 public static AbstractByteAssert<?> assertThat(byte actual) {296 return new ByteAssert(actual);297 }298 /**299 * Creates a new instance of <code>{@link ByteAssert}</code>.300 *301 * @param actual the actual value.302 * @return the created assertion object.303 */304 public static AbstractByteAssert<?> assertThat(Byte actual) {305 return new ByteAssert(actual);306 }307 /**308 * Creates a new instance of <code>{@link ByteArrayAssert}</code>.309 *310 * @param actual the actual value.311 * @return the created assertion object.312 */313 public static AbstractByteArrayAssert<?> assertThat(byte[] actual) {314 return new ByteArrayAssert(actual);315 }316 /**317 * Creates a new instance of <code>{@link Byte2DArrayAssert}</code>.318 *319 * @param actual the actual value.320 * @return the created assertion object.321 * @since 3.17.0322 */323 public static Byte2DArrayAssert assertThat(byte[][] actual) {324 return new Byte2DArrayAssert(actual);325 }326 /**327 * Creates a new instance of <code>{@link CharacterAssert}</code>.328 *329 * @param actual the actual value.330 * @return the created assertion object.331 */332 public static AbstractCharacterAssert<?> assertThat(char actual) {333 return new CharacterAssert(actual);334 }335 /**336 * Creates a new instance of <code>{@link CharArrayAssert}</code>.337 *338 * @param actual the actual value.339 * @return the created assertion object.340 */341 public static AbstractCharArrayAssert<?> assertThat(char[] actual) {342 return new CharArrayAssert(actual);343 }344 /**345 * Creates a new instance of <code>{@link Char2DArrayAssert}</code>.346 *347 * @param actual the actual value.348 * @return the created assertion object.349 * @since 3.17.0350 */351 public static Char2DArrayAssert assertThat(char[][] actual) {352 return new Char2DArrayAssert(actual);353 }354 /**355 * Creates a new instance of <code>{@link CharacterAssert}</code>.356 *357 * @param actual the actual value.358 * @return the created assertion object.359 */360 public static AbstractCharacterAssert<?> assertThat(Character actual) {361 return new CharacterAssert(actual);362 }363 /**364 * Creates a new instance of <code>{@link ClassAssert}</code>365 *366 * @param actual the actual value.367 * @return the created assertion object.368 */369 public static AbstractClassAssert<?> assertThat(Class<?> actual) {370 return new ClassAssert(actual);371 }372 /**373 * Creates a new instance of <code>{@link GenericComparableAssert}</code> with374 * standard comparison semantics.375 *376 * @param <T> the type of the actual value.377 * @param actual the actual value.378 * @return the created assertion object.379 */380 public static <T extends Comparable<? super T>> AbstractComparableAssert<?, T> assertThat(T actual) {381 return new GenericComparableAssert<>(actual);382 }383 /**384 * Creates a new instance of <code>{@link IterableAssert}</code>.385 *386 * @param <T> the actual elements type387 * @param actual the actual value.388 * @return the created assertion object.389 */390 public static <T> AbstractIterableAssert<?, Iterable<? extends T>, T, ObjectAssert<T>> assertThat(Iterable<? extends T> actual) {391 return new IterableAssert<>(actual);392 }393 /**394 * Creates a new instance of <code>{@link IteratorAssert}</code>.395 * <p>396 * <b>Breaking change in version 3.12.0:</b> this method does not return anymore an {@link IterableAssert} but an {@link IteratorAssert}.<br>397 * In order to access assertions from {@link IterableAssert}, use {@link IteratorAssert#toIterable()}.398 * <p>399 * {@link IteratorAssert} instances have limited assertions because it does not consume iterator's elements.400 * <p>401 * Examples:402 * <pre><code class='java'> Iterator&lt;String&gt; bestBasketBallPlayers = getBestBasketBallPlayers();403 *404 * assertThat(bestBasketBallPlayers).hasNext() // Iterator assertion405 * .toIterable() // switch to Iterable assertions406 * .contains("Jordan", "Magic", "Lebron"); // Iterable assertion </code></pre>407 *408 * @param <T> the type of elements.409 * @param actual the actual value.410 * @return the created assertion object.411 */412 public static <T> AbstractIteratorAssert<?, T> assertThat(Iterator<? extends T> actual) {413 return new IteratorAssert<>(actual);414 }415 /**416 * Creates a new instance of <code>{@link DoubleAssert}</code>.417 *418 * @param actual the actual value.419 * @return the created assertion object.420 */421 public static AbstractDoubleAssert<?> assertThat(double actual) {422 return new DoubleAssert(actual);423 }424 /**425 * Creates a new instance of <code>{@link DoubleAssert}</code>.426 *427 * @param actual the actual value.428 * @return the created assertion object.429 */430 public static AbstractDoubleAssert<?> assertThat(Double actual) {431 return new DoubleAssert(actual);432 }433 /**434 * Creates a new instance of <code>{@link DoubleArrayAssert}</code>.435 *436 * @param actual the actual value.437 * @return the created assertion object.438 */439 public static AbstractDoubleArrayAssert<?> assertThat(double[] actual) {440 return new DoubleArrayAssert(actual);441 }442 /**443 * Creates a new instance of <code>{@link Double2DArrayAssert}</code>.444 *445 * @param actual the actual value.446 * @return the created assertion object.447 * @since 3.17.0448 */449 public static Double2DArrayAssert assertThat(double[][] actual) {450 return new Double2DArrayAssert(actual);451 }452 /**453 * Creates a new instance of <code>{@link FileAssert}</code>.454 *455 * @param actual the actual value.456 * @return the created assertion object.457 */458 public static AbstractFileAssert<?> assertThat(File actual) {459 return new FileAssert(actual);460 }461 /**462 * Create assertion for {@link java.util.concurrent.Future}.463 *464 * @param <RESULT> the type of the value contained in the {@link java.util.concurrent.Future}.465 * @param actual the actual value.466 *467 * @return the created assertion object.468 * @since 2.7.0 / 3.7.0469 */470 public static <RESULT> AbstractFutureAssert<?, ? extends Future<? extends RESULT>, RESULT> assertThat(Future<RESULT> actual) {471 return new FutureAssert<>(actual);472 }473 /**474 * Creates a new instance of <code>{@link InputStreamAssert}</code>.475 *476 * @param actual the actual value.477 * @return the created assertion object.478 */479 public static AbstractInputStreamAssert<?, ? extends InputStream> assertThat(InputStream actual) {480 return new InputStreamAssert(actual);481 }482 /**483 * Creates a new instance of <code>{@link FloatAssert}</code>.484 *485 * @param actual the actual value.486 * @return the created assertion object.487 */488 public static AbstractFloatAssert<?> assertThat(float actual) {489 return new FloatAssert(actual);490 }491 /**492 * Creates a new instance of <code>{@link FloatAssert}</code>.493 *494 * @param actual the actual value.495 * @return the created assertion object.496 */497 public static AbstractFloatAssert<?> assertThat(Float actual) {498 return new FloatAssert(actual);499 }500 /**501 * Creates a new instance of <code>{@link FloatArrayAssert}</code>.502 *503 * @param actual the actual value.504 * @return the created assertion object.505 */506 public static AbstractFloatArrayAssert<?> assertThat(float[] actual) {507 return new FloatArrayAssert(actual);508 }509 /**510 * Creates a new instance of <code>{@link Float2DArrayAssert}</code>.511 *512 * @param actual the actual value.513 * @return the created assertion object.514 * @since 3.17.0515 */516 public static Float2DArrayAssert assertThat(float[][] actual) {517 return new Float2DArrayAssert(actual);518 }519 /**520 * Creates a new instance of <code>{@link IntegerAssert}</code>.521 *522 * @param actual the actual value.523 * @return the created assertion object.524 */525 public static AbstractIntegerAssert<?> assertThat(int actual) {526 return new IntegerAssert(actual);527 }528 /**529 * Creates a new instance of <code>{@link IntArrayAssert}</code>.530 *531 * @param actual the actual value.532 * @return the created assertion object.533 */534 public static AbstractIntArrayAssert<?> assertThat(int[] actual) {535 return new IntArrayAssert(actual);536 }537 /**538 * Creates a new instance of <code>{@link Int2DArrayAssert}</code>.539 *540 * @param actual the actual value.541 * @return the created assertion object.542 * @since 3.17.0543 */544 public static Int2DArrayAssert assertThat(int[][] actual) {545 return new Int2DArrayAssert(actual);546 }547 /**548 * Creates a new instance of <code>{@link IntegerAssert}</code>.549 *550 * @param actual the actual value.551 * @return the created assertion object.552 */553 public static AbstractIntegerAssert<?> assertThat(Integer actual) {554 return new IntegerAssert(actual);555 }556 /**557 * Creates a new instance of <code>{@link CollectionAssert}</code>.558 *559 * @param <T> the actual elements type560 * @param actual the actual value.561 * @return the created assertion object.562 * @since 3.21.0563 */564 public static <T> AbstractCollectionAssert<?, Collection<? extends T>, T, ObjectAssert<T>> assertThat(Collection<? extends T> actual) {565 return new CollectionAssert<>(actual);566 }567 /**568 * Creates a new instance of <code>{@link ListAssert}</code>.569 *570 * @param <T> the actual elements type571 * @param actual the actual value.572 * @return the created assertion object.573 */574 public static <T> AbstractListAssert<?, List<? extends T>, T, ObjectAssert<T>> assertThat(List<? extends T> actual) {575 return new ListAssert<>(actual);576 }577 /**578 * Creates a new instance of <code>{@link FactoryBasedNavigableIterableAssert}</code> allowing to navigate to any {@code Iterable} element579 * in order to perform assertions on it.580 * <p>581 * Navigational methods provided:<ul>582 * <li>{@link AbstractIterableAssert#first() first()}</li>583 * <li>{@link AbstractIterableAssert#last() last()}</li>584 * <li>{@link AbstractIterableAssert#element(int) element(index)}</li>585 * <li>{@link AbstractIterableAssert#elements(int...) elements(int...)}</li>586 * </ul>587 * <p>588 * The available assertions after navigating to an element depend on the {@code ELEMENT_ASSERT} parameter of the given589 * {@link AssertFactory AssertFactory&lt;ELEMENT, ELEMENT_ASSERT&gt;} (AssertJ can't figure it out because of Java type erasure).590 * <p>591 * Example with {@code String} element assertions:592 * <pre><code class='java'> Iterable&lt;String&gt; hobbits = newHashSet("frodo", "sam", "pippin");593 *594 * // build an AssertFactory for StringAssert (much nicer with Java 8 lambdas)595 * AssertFactory&lt;String, StringAssert&gt; stringAssertFactory = new AssertFactory&lt;String, StringAssert&gt;() {596 * {@literal @}Override597 * public StringAssert createAssert(String string) {598 * return new StringAssert(string);599 * }600 * };601 *602 * // assertion succeeds with String assertions chained after first()603 * assertThat(hobbits, stringAssertFactory).first()604 * .startsWith("fro")605 * .endsWith("do");</code></pre>606 *607 * @param <ACTUAL> The actual type608 * @param <ELEMENT> The actual elements type609 * @param <ELEMENT_ASSERT> The actual elements AbstractAssert type610 * @param actual the actual value.611 * @param assertFactory the factory used to create the elements assert instance.612 * @return the created assertion object.613 */614 //@format:off615 @SuppressWarnings({ "unchecked", "rawtypes" })616 public static <ACTUAL extends Iterable<? extends ELEMENT>, ELEMENT, ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT, ELEMENT>>617 FactoryBasedNavigableIterableAssert<?, ACTUAL, ELEMENT, ELEMENT_ASSERT> assertThat(Iterable<? extends ELEMENT> actual,618 AssertFactory<ELEMENT, ELEMENT_ASSERT> assertFactory) {619 return new FactoryBasedNavigableIterableAssert(actual, FactoryBasedNavigableIterableAssert.class, assertFactory);620 }621 /**622 * Creates a new instance of <code>{@link ClassBasedNavigableIterableAssert}</code> allowing to navigate to any {@code Iterable} element623 * in order to perform assertions on it.624 * <p>625 * Navigational methods provided:<ul>626 * <li>{@link AbstractIterableAssert#first() first()}</li>627 * <li>{@link AbstractIterableAssert#last() last()}</li>628 * <li>{@link AbstractIterableAssert#element(int) element(index)}</li>629 * <li>{@link AbstractIterableAssert#elements(int...) elements(int...)}</li>630 * </ul>631 * <p>632 * The available assertions after navigating to an element depend on the given {@code assertClass}633 * (AssertJ can't find the element assert type by itself because of Java type erasure).634 * <p>635 * Example with {@code String} element assertions:636 * <pre><code class='java'> Iterable&lt;String&gt; hobbits = newHashSet("frodo", "sam", "pippin");637 *638 * // assertion succeeds with String assertions chained after first()639 * assertThat(hobbits, StringAssert.class).first()640 * .startsWith("fro")641 * .endsWith("do");</code></pre>642 *643 * @param <ACTUAL> The actual type644 * @param <ELEMENT> The actual elements type645 * @param <ELEMENT_ASSERT> The actual elements AbstractAssert type646 * @param actual the actual value.647 * @param assertClass the class used to create the elements assert instance.648 * @return the created assertion object.649 */650 @SuppressWarnings({ "rawtypes", "unchecked" })651 public static <ACTUAL extends Iterable<? extends ELEMENT>, ELEMENT, ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT, ELEMENT>>652 ClassBasedNavigableIterableAssert<?, ACTUAL, ELEMENT, ELEMENT_ASSERT> assertThat(ACTUAL actual,653 Class<ELEMENT_ASSERT> assertClass) {654 return new ClassBasedNavigableIterableAssert(actual, ClassBasedNavigableIterableAssert.class, assertClass);655 }656 /**657 * Creates a new instance of <code>{@link FactoryBasedNavigableListAssert}</code> allowing to navigate to any {@code List} element658 * in order to perform assertions on it.659 * <p>660 * Navigational methods provided:<ul>661 * <li>{@link AbstractIterableAssert#first() first()}</li>662 * <li>{@link AbstractIterableAssert#last() last()}</li>663 * <li>{@link AbstractIterableAssert#element(int) element(index)}</li>664 * <li>{@link AbstractIterableAssert#elements(int...) elements(int...)}</li>665 * </ul>666 * <p>667 * The available assertions after navigating to an element depend on the {@code ELEMENT_ASSERT} parameter of the given668 * {@link AssertFactory AssertFactory&lt;ELEMENT, ELEMENT_ASSERT&gt;} (AssertJ can't figure it out because of Java type erasure).669 * <p>670 * Example with {@code String} element assertions:671 * <pre><code class='java'> List&lt;String&gt; hobbits = newArrayList("frodo", "sam", "pippin");672 *673 * // build an AssertFactory for StringAssert (much nicer with Java 8 lambdas)674 * AssertFactory&lt;String, StringAssert&gt; stringAssertFactory = new AssertFactory&lt;String, StringAssert&gt;() {675 * {@literal @}Override676 * public StringAssert createAssert(String string) {677 * return new StringAssert(string);678 * }679 * };680 *681 * // assertion succeeds with String assertions chained after first()682 * assertThat(hobbits, stringAssertFactory).first()683 * .startsWith("fro")684 * .endsWith("do");</code></pre>685 *686 * @param <ACTUAL> The actual type687 * @param <ELEMENT> The actual elements type688 * @param <ELEMENT_ASSERT> The actual elements AbstractAssert type689 * @param actual the actual value.690 * @param assertFactory the factory used to create the elements assert instance.691 * @return the created assertion object.692 */693 @SuppressWarnings({ "unchecked", "rawtypes" })694 public static <ACTUAL extends List<? extends ELEMENT>, ELEMENT, ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT, ELEMENT>>695 FactoryBasedNavigableListAssert<?, ACTUAL, ELEMENT, ELEMENT_ASSERT> assertThat(List<? extends ELEMENT> actual,696 AssertFactory<ELEMENT, ELEMENT_ASSERT> assertFactory) {697 return new FactoryBasedNavigableListAssert(actual, FactoryBasedNavigableListAssert.class, assertFactory);698 }699 /**700 * Creates a new instance of <code>{@link ClassBasedNavigableListAssert}</code> allowing to navigate to any {@code List} element701 * in order to perform assertions on it.702 * <p>703 * Navigational methods provided:<ul>704 * <li>{@link AbstractIterableAssert#first() first()}</li>705 * <li>{@link AbstractIterableAssert#last() last()}</li>706 * <li>{@link AbstractIterableAssert#element(int) element(index)}</li>707 * <li>{@link AbstractIterableAssert#elements(int...) elements(int...)}</li>708 * </ul>709 * <p>710 * The available assertions after navigating to an element depend on the given {@code assertClass}711 * (AssertJ can't find the element assert type by itself because of Java type erasure).712 * <p>713 * Example with {@code String} element assertions:714 * <pre><code class='java'> List&lt;String&gt; hobbits = newArrayList("frodo", "sam", "pippin");715 *716 * // assertion succeeds with String assertions chained after first()717 * assertThat(hobbits, StringAssert.class).first()718 * .startsWith("fro")719 * .endsWith("do");</code></pre>720 *721 * @param <ACTUAL> The actual type722 * @param <ELEMENT> The actual elements type723 * @param <ELEMENT_ASSERT> The actual elements AbstractAssert type724 * @param actual the actual value.725 * @param assertClass the class used to create the elements assert instance.726 * @return the created assertion object.727 */728 @SuppressWarnings({ "unchecked", "rawtypes" })729 public static <ELEMENT, ACTUAL extends List<? extends ELEMENT>, ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT, ELEMENT>>730 ClassBasedNavigableListAssert<?, ACTUAL, ELEMENT, ELEMENT_ASSERT> assertThat(List<? extends ELEMENT> actual,731 Class<ELEMENT_ASSERT> assertClass) {732 return new ClassBasedNavigableListAssert(actual, assertClass);733 }734 /**735 * Creates a new instance of <code>{@link LongAssert}</code>.736 *737 * @param actual the actual value.738 * @return the created assertion object.739 */740 public static AbstractLongAssert<?> assertThat(long actual) {741 return new LongAssert(actual);742 }743 /**744 * Creates a new instance of <code>{@link LongAssert}</code>.745 *746 * @param actual the actual value.747 * @return the created assertion object.748 */749 public static AbstractLongAssert<?> assertThat(Long actual) {750 return new LongAssert(actual);751 }752 /**753 * Creates a new instance of <code>{@link LongArrayAssert}</code>.754 *755 * @param actual the actual value.756 * @return the created assertion object.757 */758 public static AbstractLongArrayAssert<?> assertThat(long[] actual) {759 return new LongArrayAssert(actual);760 }761 /**762 * Creates a new instance of <code>{@link Long2DArrayAssert}</code>.763 *764 * @param actual the actual value.765 * @return the created assertion object.766 * @since 3.17.0767 */768 public static Long2DArrayAssert assertThat(long[][] actual) {769 return new Long2DArrayAssert(actual);770 }771 /**772 * Creates a new instance of <code>{@link ObjectAssert}</code>.773 *774 * @param <T> the actual type775 * @param actual the actual value.776 * @return the created assertion object.777 */778 public static <T> AbstractObjectAssert<?, T> assertThat(T actual) {779 return new ObjectAssert<>(actual);780 }781 /**782 * Returns the given assertion. This method improves code readability by surrounding the given assertion with783 * <code>assertThat</code>.784 * <p>785 * Consider for example the following MyButton and MyButtonAssert classes:786 * <pre><code class='java'> public class MyButton extends JButton {787 *788 * private boolean blinking;789 *790 * public boolean isBlinking() { return this.blinking; }791 *792 * public void setBlinking(boolean blink) { this.blinking = blink; }793 *794 * }795 *796 * private static class MyButtonAssert implements AssertDelegateTarget {797 *798 * private MyButton button;799 * MyButtonAssert(MyButton button) { this.button = button; }800 *801 * void isBlinking() {802 * // standard assertion from core Assertions.assertThat803 * assertThat(button.isBlinking()).isTrue();804 * }805 *806 * void isNotBlinking() {807 * // standard assertion from core Assertions.assertThat808 * assertThat(button.isBlinking()).isFalse();809 * }810 * }</code></pre>811 *812 * As MyButtonAssert implements AssertDelegateTarget, you can use <code>assertThat(buttonAssert).isBlinking();</code>813 * instead of <code>buttonAssert.isBlinking();</code> to have easier to read assertions:814 * <pre><code class='java'> {@literal @}Test815 * public void AssertDelegateTarget_example() {816 *817 * MyButton button = new MyButton();818 * MyButtonAssert buttonAssert = new MyButtonAssert(button);819 *820 * // you can encapsulate MyButtonAssert assertions methods within assertThat821 * assertThat(buttonAssert).isNotBlinking(); // same as : buttonAssert.isNotBlinking();822 *823 * button.setBlinking(true);824 *825 * assertThat(buttonAssert).isBlinking(); // same as : buttonAssert.isBlinking();826 * }</code></pre>827 *828 * @param <T> the generic type of the user-defined assert.829 * @param assertion the assertion to return.830 * @return the given assertion.831 */832 public static <T extends AssertDelegateTarget> T assertThat(T assertion) {833 return assertion;834 }835 /**836 * Delegates the creation of the {@link Assert} to the {@link AssertProvider#assertThat()} of the given component.837 *838 * <p>839 * Read the comments on {@link AssertProvider} for an example of its usage.840 * </p>841 *842 * @param <T> the generic type of the assert provided by the component.843 * @param component844 * the component that creates its own assert845 * @return the associated {@link Assert} of the given component846 */847 public static <T> T assertThat(final AssertProvider<T> component) {848 return component.assertThat();849 }850 /**851 * Creates a new instance of <code>{@link ObjectArrayAssert}</code>.852 *853 * @param <T> the actual elements type854 * @param actual the actual value.855 * @return the created assertion object.856 */857 public static <T> AbstractObjectArrayAssert<?, T> assertThat(T[] actual) {858 return new ObjectArrayAssert<>(actual);859 }860 /**861 * Creates a new instance of <code>{@link Object2DArrayAssert}</code>.862 *863 * @param <T> the actual elements type864 * @param actual the actual value.865 * @return the created assertion object.866 * @since 3.17.0867 */868 public static <T> Object2DArrayAssert<T> assertThat(T[][] actual) {869 return new Object2DArrayAssert<>(actual);870 }871 /**872 * Creates a new instance of <code>{@link MapAssert}</code>.873 * <p>874 * Returned type is {@link MapAssert} as it overrides method to annotate them with {@link SafeVarargs} avoiding875 * annoying warnings.876 *877 * @param <K> the type of keys in the map.878 * @param <V> the type of values in the map.879 * @param actual the actual value.880 * @return the created assertion object.881 */882 public static <K, V> MapAssert<K, V> assertThat(Map<K, V> actual) {883 return new MapAssert<>(actual);884 }885 /**886 * Creates a new instance of <code>{@link ShortAssert}</code>.887 *888 * @param actual the actual value.889 * @return the created assertion object.890 */891 public static AbstractShortAssert<?> assertThat(short actual) {892 return new ShortAssert(actual);893 }894 /**895 * Creates a new instance of <code>{@link ShortAssert}</code>.896 *897 * @param actual the actual value.898 * @return the created assertion object.899 */900 public static AbstractShortAssert<?> assertThat(Short actual) {901 return new ShortAssert(actual);902 }903 /**904 * Creates a new instance of <code>{@link ShortArrayAssert}</code>.905 *906 * @param actual the actual value.907 * @return the created assertion object.908 */909 public static AbstractShortArrayAssert<?> assertThat(short[] actual) {910 return new ShortArrayAssert(actual);911 }912 /**913 * Creates a new instance of <code>{@link Short2DArrayAssert}</code>.914 *915 * @param actual the actual value.916 * @return the created assertion object.917 * @since 3.17.0918 */919 public static Short2DArrayAssert assertThat(short[][] actual) {920 return new Short2DArrayAssert(actual);921 }922 /**923 * Creates a new instance of <code>{@link CharSequenceAssert}</code>.924 *925 * @param actual the actual value.926 * @return the created assertion object.927 */928 public static AbstractCharSequenceAssert<?, ? extends CharSequence> assertThat(CharSequence actual) {929 return new CharSequenceAssert(actual);930 }931 /**932 * Creates a new instance of <code>{@link CharSequenceAssert}</code> from a {@link StringBuilder}.933 *934 * @param actual the actual value.935 * @return the created assertion object.936 * @since 3.11.0937 */938 public static AbstractCharSequenceAssert<?, ? extends CharSequence> assertThat(StringBuilder actual) {939 return new CharSequenceAssert(actual);940 }941 /**942 * Creates a new instance of <code>{@link CharSequenceAssert}</code> from a {@link StringBuffer}.943 *944 * @param actual the actual value.945 * @return the created assertion object.946 * @since 3.11.0947 */948 public static AbstractCharSequenceAssert<?, ? extends CharSequence> assertThat(StringBuffer actual) {949 return new CharSequenceAssert(actual);950 }951 /**952 * Creates a new instance of <code>{@link StringAssert}</code>.953 *954 * @param actual the actual value.955 * @return the created assertion object.956 */957 public static AbstractStringAssert<?> assertThat(String actual) {958 return new StringAssert(actual);959 }960 /**961 * Creates a new instance of <code>{@link DateAssert}</code>.962 *963 * @param actual the actual value.964 * @return the created assertion object.965 */966 public static AbstractDateAssert<?> assertThat(Date actual) {967 return new DateAssert(actual);968 }969 /**970 * Creates a new instance of <code>{@link ThrowableAssert}</code>.971 *972 * @param <T> the type of the actual throwable.973 * @param actual the actual value.974 * @return the created {@link ThrowableAssert}.975 */976 public static <T extends Throwable> AbstractThrowableAssert<?, T> assertThat(T actual) {977 return new ThrowableAssert<>(actual);978 }979 /**980 * Allows to capture and then assert on a {@link Throwable} more easily when used with Java 8 lambdas.981 *982 * <p>983 * Java 8 example :984 * <pre><code class='java'> {@literal @}Test985 * public void testException() {986 * assertThatThrownBy(() -&gt; { throw new Exception("boom!"); }).isInstanceOf(Exception.class)987 * .hasMessageContaining("boom");988 * }</code></pre>989 *990 * <p>991 * Java 7 example :992 * <pre><code class='java'> assertThatThrownBy(new ThrowingCallable() {993 *994 * {@literal @}Override995 * public void call() throws Exception {996 * throw new Exception("boom!");997 * }998 *999 * }).isInstanceOf(Exception.class)1000 * .hasMessageContaining("boom");</code></pre>1001 *1002 * If the provided {@link ThrowingCallable} does not raise an exception, an error is immediately thrown,1003 * in that case the test description provided with {@link AbstractAssert#as(String, Object...) as(String, Object...)} is not honored.<br>1004 * To use a test description, use {@link #catchThrowable(ThrowableAssert.ThrowingCallable)} as shown below.1005 * <pre><code class='java'> // assertion will fail but "display me" won't appear in the error1006 * assertThatThrownBy(() -&gt; {}).as("display me")1007 * .isInstanceOf(Exception.class);1008 *1009 * // assertion will fail AND "display me" will appear in the error1010 * Throwable thrown = catchThrowable(() -&gt; {});1011 * assertThat(thrown).as("display me")1012 * .isInstanceOf(Exception.class); </code></pre>1013 *1014 * @param shouldRaiseThrowable The {@link ThrowingCallable} or lambda with the code that should raise the throwable.1015 * @return The captured exception or <code>null</code> if none was raised by the callable.1016 */1017 @CanIgnoreReturnValue1018 public static AbstractThrowableAssert<?, ? extends Throwable> assertThatThrownBy(ThrowingCallable shouldRaiseThrowable) {1019 return new ThrowableAssert<>(catchThrowable(shouldRaiseThrowable)).hasBeenThrown();1020 }1021 /**1022 * Allows to capture and then assert on a {@link Throwable} like {@code assertThatThrownBy(ThrowingCallable)} but this method1023 * let you set the assertion description the same way you do with {@link AbstractAssert#as(String, Object...) as(String, Object...)}.1024 * <p>1025 * Example:1026 * <pre><code class='java'> {@literal @}Test1027 * public void testException() {1028 * // if this assertion failed (but it doesn't), the error message would start with [Test explosive code]1029 * assertThatThrownBy(() -&gt; { throw new IOException("boom!") }, "Test explosive code")1030 * .isInstanceOf(IOException.class)1031 * .hasMessageContaining("boom");1032 * }</code></pre>1033 *1034 * If the provided {@link ThrowingCallable ThrowingCallable} does not raise an exception, an error is immediately thrown.1035 * <p>1036 * The test description provided is honored but not the one with {@link AbstractAssert#as(String, Object...) as(String, Object...)}, example:1037 * <pre><code class='java'> // assertion will fail but "display me" won't appear in the error message1038 * assertThatThrownBy(() -&gt; {}).as("display me")1039 * .isInstanceOf(Exception.class);1040 *1041 * // assertion will fail AND "display me" will appear in the error message1042 * assertThatThrownBy(() -&gt; {}, "display me")1043 * .isInstanceOf(Exception.class);</code></pre>1044 *1045 * @param shouldRaiseThrowable The {@link ThrowingCallable} or lambda with the code that should raise the throwable.1046 * @param description the new description to set.1047 * @param args optional parameter if description is a format String.1048 *1049 * @return the created {@link ThrowableAssert}.1050 *1051 * @since 3.9.01052 */1053 @CanIgnoreReturnValue1054 public static AbstractThrowableAssert<?, ? extends Throwable> assertThatThrownBy(ThrowingCallable shouldRaiseThrowable,1055 String description, Object... args) {1056 return assertThat(catchThrowable(shouldRaiseThrowable)).as(description, args).hasBeenThrown();1057 }1058 /**1059 * Allows to capture and then assert on a {@link Throwable}.1060 *1061 * <p>1062 * Example :1063 * </p>1064 *1065 * <pre><code class='java'> ThrowingCallable callable = new ThrowingCallable() {1066 * {@literal @}Override1067 * public void call() throws Throwable {1068 * throw new Exception("boom!");1069 * }1070 * };1071 *1072 * // assertion succeeds1073 * assertThatCode(callable).isInstanceOf(Exception.class)1074 * .hasMessageContaining("boom");1075 *1076 * // assertion fails1077 * assertThatCode(callable).doesNotThrowAnyException();</code></pre>1078 *1079 * If the provided {@link ThrowingCallable} does not validate against next assertions, an error is immediately raised,1080 * in that case the test description provided with {@link AbstractAssert#as(String, Object...) as(String, Object...)} is not honored.<br>1081 * To use a test description, use {@link #catchThrowable(ThrowableAssert.ThrowingCallable)} as shown below.1082 *1083 * <pre><code class='java'> ThrowingCallable doNothing = new ThrowingCallable() {1084 * {@literal @}Override1085 * public void call() throws Throwable {1086 * // do nothing1087 * }1088 * };1089 *1090 * // assertion fails and "display me" appears in the assertion error1091 * assertThatCode(doNothing).as("display me")1092 * .isInstanceOf(Exception.class);1093 *1094 * // assertion will fail AND "display me" will appear in the error1095 * Throwable thrown = catchThrowable(doNothing);1096 * assertThatCode(thrown).as("display me")1097 * .isInstanceOf(Exception.class); </code></pre>1098 * <p>1099 * This method was not named {@code assertThat} because the java compiler reported it ambiguous when used directly with a lambda :(1100 *1101 * @param shouldRaiseOrNotThrowable The {@link ThrowingCallable} or lambda with the code that should raise the throwable.1102 * @return The captured exception or <code>null</code> if none was raised by the callable.1103 * @since 3.7.01104 */1105 public static AbstractThrowableAssert<?, ? extends Throwable> assertThatCode(ThrowingCallable shouldRaiseOrNotThrowable) {1106 return assertThat(catchThrowable(shouldRaiseOrNotThrowable));1107 }1108 /**1109 * Creates a new instance of <code>{@link ObjectAssert}</code> for any object.1110 * <p>1111 * This overload is useful, when an overloaded method of assertThat(...) takes precedence over the generic {@link #assertThat(Object)}.1112 * <p>1113 * Example:1114 * <p>1115 * Cast necessary because {@link #assertThat(List)} "forgets" actual type:1116 * <pre>{@code assertThat(new LinkedList<>(asList("abc"))).matches(list -> ((Deque<String>) list).getFirst().equals("abc")); }</pre>1117 * No cast needed, but also no additional list assertions:1118 * <pre>{@code assertThatObject(new LinkedList<>(asList("abc"))).matches(list -> list.getFirst().equals("abc")); }</pre>1119 *1120 * @param <T> the type of the actual value.1121 * @param actual the actual value.1122 * @return the created assertion object.1123 * @since 3.12.01124 */1125 public <T> AbstractObjectAssert<?, T> assertThatObject(T actual) {1126 return assertThat(actual);1127 }1128 /**1129 * Allows to catch an {@link Throwable} more easily when used with Java 8 lambdas.1130 *1131 * <p>1132 * This caught {@link Throwable} can then be asserted.1133 * </p>1134 *1135 * <p>1136 * Java 8 example:1137 * <pre><code class='java'> {@literal @}Test1138 * public void testException() {1139 * // when1140 * Throwable thrown = catchThrowable(() -&gt; { throw new Exception("boom!"); });1141 *1142 * // then1143 * assertThat(thrown).isInstanceOf(Exception.class)1144 * .hasMessageContaining("boom");1145 * }</code></pre>1146 *1147 * <p>1148 * Java 7 example:1149 * <pre><code class='java'> {@literal @}Test1150 * public void testException() {1151 * // when1152 * Throwable thrown = catchThrowable(new ThrowingCallable() {1153 *1154 * {@literal @}Override1155 * public void call() throws Exception {1156 * throw new Exception("boom!");1157 * }1158 *1159 * })1160 * // then1161 * assertThat(thrown).isInstanceOf(Exception.class)1162 * .hasMessageContaining("boom");1163 * }</code></pre>1164 *1165 * @param shouldRaiseThrowable The lambda with the code that should raise the exception.1166 * @return The captured exception or <code>null</code> if none was raised by the callable.1167 */1168 public static Throwable catchThrowable(ThrowingCallable shouldRaiseThrowable) {1169 return ThrowableAssert.catchThrowable(shouldRaiseThrowable);1170 }1171 /**1172 * Allows catching a {@link Throwable} of a specific type.1173 * <p>1174 * A call is made to {@code catchThrowable(ThrowingCallable)}, if no exception is thrown {@code catchThrowableOfType} returns null,1175 * otherwise it checks that the caught {@link Throwable} has the specified type then casts it to it before returning it,1176 * making it convenient to perform subtype-specific assertions on the result.1177 * <p>1178 * Example:1179 * <pre><code class='java'> class CustomParseException extends Exception {1180 * int line;1181 * int column;1182 *1183 * public CustomParseException(String msg, int l, int c) {1184 * super(msg);1185 * line = l;1186 * column = c;1187 * }1188 * }1189 *1190 * CustomParseException e = catchThrowableOfType(() -&gt; { throw new CustomParseException("boom!", 1, 5); },1191 * CustomParseException.class);1192 * // assertions pass1193 * assertThat(e).hasMessageContaining("boom");1194 * assertThat(e.line).isEqualTo(1);1195 * assertThat(e.column).isEqualTo(5);1196 *1197 * // fails as CustomParseException is not a RuntimeException1198 * catchThrowableOfType(() -&gt; { throw new CustomParseException("boom!", 1, 5); },1199 * RuntimeException.class);</code></pre>1200 *1201 * @param <THROWABLE> the {@link Throwable} type.1202 * @param shouldRaiseThrowable The lambda with the code that should raise the exception.1203 * @param type The type of exception that the code is expected to raise.1204 * @return The captured exception or <code>null</code> if none was raised by the callable.1205 * @see #catchThrowable(ThrowableAssert.ThrowingCallable)1206 * @since 3.9.01207 */1208 public static <THROWABLE extends Throwable> THROWABLE catchThrowableOfType(ThrowingCallable shouldRaiseThrowable, Class<THROWABLE> type) {1209 return ThrowableAssert.catchThrowableOfType(shouldRaiseThrowable, type);1210 }1211 // -------------------------------------------------------------------------------------------------1212 // fail methods : not assertions but here to have a single entry point to all AssertJ features.1213 // -------------------------------------------------------------------------------------------------1214 /**1215 * Throws an {@link AssertionError} with the given message.1216 *1217 * @param failureMessage error message.1218 * @throws AssertionError with the given message.1219 */1220 public static void fail(String failureMessage) {1221 Fail.fail(failureMessage);1222 }1223 /**1224 * Throws an {@link AssertionError} with the given message built as {@link String#format(String, Object...)}.1225 *1226 * @param failureMessage error message.1227 * @param args Arguments referenced by the format specifiers in the format string.1228 * @throws AssertionError with the given built message.1229 */1230 public static void fail(String failureMessage, Object... args) {1231 Fail.fail(failureMessage, args);1232 }1233 /**1234 * Throws an {@link AssertionError} with the given message and with the {@link Throwable} that caused the failure.1235 * @param failureMessage the description of the failed assertion. It can be {@code null}.1236 * @param realCause cause of the error.1237 * @throws AssertionError with the given message and with the {@link Throwable} that caused the failure.1238 */1239 public static void fail(String failureMessage, Throwable realCause) {1240 Fail.fail(failureMessage, realCause);1241 }1242 /**1243 * Throws an {@link AssertionError} with a message explaining that a {@link Throwable} of given class was expected to be thrown1244 * but had not been.1245 * <p>1246 * {@link Assertions#shouldHaveThrown(Class)} can be used as a replacement.1247 * <p>1248 * @param throwableClass the Throwable class that was expected to be thrown.1249 * @throws AssertionError with a message explaining that a {@link Throwable} of given class was expected to be thrown but had1250 * not been.1251 *1252 */1253 public static void failBecauseExceptionWasNotThrown(Class<? extends Throwable> throwableClass) {1254 Fail.shouldHaveThrown(throwableClass);1255 }1256 /**1257 * Throws an {@link AssertionError} with a message explaining that a {@link Throwable} of given class was expected to be thrown1258 * but had not been.1259 * @param throwableClass the Throwable class that was expected to be thrown.1260 * @throws AssertionError with a message explaining that a {@link Throwable} of given class was expected to be thrown but had1261 * not been.1262 */1263 public static void shouldHaveThrown(Class<? extends Throwable> throwableClass) {1264 Fail.shouldHaveThrown(throwableClass);1265 }1266 /**1267 * In error messages, sets the threshold when iterable/array formatting will on one line (if their String description1268 * is less than this parameter) or it will be formatted with one element per line.1269 * <p>1270 * The following array will be formatted on one line as its length &lt; 80:1271 * <pre><code class='java'> String[] greatBooks = array("A Game of Thrones", "The Lord of the Rings", "Assassin's Apprentice");1272 *1273 * // formatted as:1274 *1275 * ["A Game of Thrones", "The Lord of the Rings", "Assassin's Apprentice"]</code></pre>1276 *1277 * whereas this array is formatted on multiple lines (one element per line):1278 * <pre><code class='java'> String[] greatBooks = array("A Game of Thrones", "The Lord of the Rings", "Assassin's Apprentice", "Guards! Guards! (Discworld)");1279 *1280 * // formatted as:1281 *1282 * ["A Game of Thrones",1283 * "The Lord of the Rings",1284 * "Assassin's Apprentice",1285 * "Guards! Guards! (Discworld)"]</code></pre>1286 *1287 * @param maxLengthForSingleLineDescription the maximum length for an iterable/array to be displayed on one line1288 */1289 public static void setMaxLengthForSingleLineDescription(int maxLengthForSingleLineDescription) {1290 StandardRepresentation.setMaxLengthForSingleLineDescription(maxLengthForSingleLineDescription);1291 }1292 /**1293 * In error messages, sets the threshold for how many elements from one iterable/array/map will be included in the1294 * in the description.1295 *1296 * E.q. When this method is called with a value of {@code 3}.1297 * <p>1298 * The following array will be formatted entirely as it's length is &lt;= 3:1299 * <pre><code class='java'> String[] greatBooks = array("A Game of Thrones", "The Lord of the Rings", "Assassin's Apprentice");1300 *1301 * // formatted as:1302 *1303 * ["A Game of Thrones", "The Lord of the Rings", "Assassin's Apprentice"]</code></pre>1304 *1305 * whereas this array is formatted only with it's first 3 elements, followed by {@code ...}:1306 * <pre><code class='java'> String[] greatBooks = array("A Game of Thrones", "The Lord of the Rings", "Assassin's Apprentice", "Guards! Guards!");1307 *1308 * // formatted as:1309 *1310 * ["A Game of Thrones", "The Lord of the Rings", "Assassin's Apprentice", ...]</code></pre>1311 *1312 * @param maxElementsForPrinting the maximum elements that would be printed from one iterable/array/map1313 * @since 2.6.0 / 3.6.01314 */1315 public static void setMaxElementsForPrinting(int maxElementsForPrinting) {1316 StandardRepresentation.setMaxElementsForPrinting(maxElementsForPrinting);1317 }1318 /**1319 * Sets how many stacktrace elements are included in {@link Throwable} representation (by default this set to 3).1320 * <p>1321 * Examples:1322 * <pre><code class='java'> static class Test1 {1323 *1324 * static void boom() {1325 * Test2.boom2();1326 * }1327 *1328 * static class Test2 {1329 * static void boom2() {1330 * throw new RuntimeException();1331 * }1332 * }1333 * }</code></pre>1334 *1335 * {@code Test1.boom()} exception should be represented like this in error messages:1336 * <pre><code class='text'> java.lang.RuntimeException1337 * at org.assertj.core.presentation.Test1$Test2.boom2(StandardRepresentation_throwable_format_Test.java:35)1338 * at org.assertj.core.presentation.Test1.boom(StandardRepresentation_throwable_format_Test.java:40);java.lang.RuntimeException1339 * at org.assertj.core.presentation.Test1.lambda$1(StandardRepresentation_throwable_format_Test.java:63)org.assertj.core.util.Throwables_Description_Test$test1$test2.exception_layer_2(Throwables_Description_Test.java:24)1340 * ...(69 remaining lines not displayed - this can be changed with Assertions.setMaxStackTraceElementsDisplayed)org.assertj.core.util.Throwables_Description_Test$test1.exception_layer_1(Throwables_Description_Test.java:30)</code></pre>1341 *1342 * @param maxStackTraceElementsDisplayed the maximum number of lines for a stacktrace to be displayed on one throw.1343 * @since 3.19.01344 * @see Configuration1345 */1346 public static void setMaxStackTraceElementsDisplayed (int maxStackTraceElementsDisplayed ) {1347 StandardRepresentation.setMaxStackTraceElementsDisplayed (maxStackTraceElementsDisplayed );1348 }1349 // ------------------------------------------------------------------------------------------------------1350 // properties methods : not assertions but here to have a single entry point to all AssertJ features.1351 // ------------------------------------------------------------------------------------------------------1352 /**1353 * Only delegate to {@link Properties#extractProperty(String)} so that Assertions offers a full feature entry point1354 * to1355 * all AssertJ features (but you can use {@link Properties} if you prefer).1356 * <p>1357 * Typical usage is to chain <code>extractProperty</code> with <code>from</code> method, see examples below :1358 * <pre><code class='java'> // extract simple property values having a java standard type (here String)1359 * assertThat(extractProperty(&quot;name&quot;, String.class).from(fellowshipOfTheRing)).contains(&quot;1360 * Boromir&quot;, &quot;Gandalf&quot;, &quot;Frodo&quot;,1361 * &quot;Legolas&quot;).doesNotContain(&quot;Sauron&quot;, &quot;Elrond&quot;);...

Full Screen

Full Screen

Source:StandardRepresentation_throwable_format_Test.java Github

copy

Full Screen

...20import org.assertj.core.configuration.Configuration;21import org.assertj.core.test.MutatesGlobalConfiguration;22import org.junit.jupiter.api.Test;23/**24 * Tests for <code>{@link StandardRepresentation#toStringOf(Throwable)}</code>.25 *26 * @author XiaoMingZHM Eveneko27 */28@MutatesGlobalConfiguration29class StandardRepresentation_throwable_format_Test {30 private static final Representation REPRESENTATION = new StandardRepresentation();31 // Just to make sure the stack trace is long enough.32 static class Test1 {33 static class Test2 {34 static void boom2() {35 throw new RuntimeException();36 }37 }38 static void boom() {39 Test2.boom2();40 }41 }42 @Test43 void should_not_display_stacktrace_if_maxStackTraceElementsDisplayed_is_zero() {44 // GIVEN45 Configuration configuration = new Configuration();46 configuration.setMaxStackTraceElementsDisplayed(0);47 configuration.apply();48 // WHEN49 String toString = REPRESENTATION.toStringOf(catchThrowable(Test1::boom));50 // THEN51 then(toString).isEqualTo("java.lang.RuntimeException");52 }53 @Test54 void should_display_the_configured_number_of_stacktrace_elements() {55 // GIVEN56 Configuration configuration = new Configuration();57 // configuration.setMaxStackTraceElementsDisplayed(3);58 configuration.apply();59 // WHEN60 String toString = REPRESENTATION.toStringOf(catchThrowable(Test1::boom));61 // THEN62 then(toString).matches("java\\.lang\\.RuntimeException\\R" +63 "\\tat org\\.assertj\\.core\\.presentation\\.StandardRepresentation_throwable_format_Test\\$Test1\\$Test2\\.boom2\\(StandardRepresentation_throwable_format_Test\\.java:\\d+\\)\\R"64 +65 "\\tat org\\.assertj\\.core\\.presentation\\.StandardRepresentation_throwable_format_Test\\$Test1\\.boom\\(StandardRepresentation_throwable_format_Test\\.java:\\d+\\)\\R"66 +67 "\\tat org\\.assertj\\.core\\.api\\.ThrowableAssert\\.catchThrowable\\(ThrowableAssert\\.java:\\d+\\)\\R"68 +69 "\\t\\.{3}\\(\\d+ remaining lines not displayed - this can be changed with Assertions\\.setMaxStackTraceElementsDisplayed\\)");70 }71 @Test72 void should_display_the_full_stacktrace() {73 // GIVEN74 Configuration configuration = new Configuration();75 configuration.setMaxStackTraceElementsDisplayed(100);76 configuration.apply();77 // WHEN78 String toString = REPRESENTATION.toStringOf(catchThrowable(Test1::boom));79 // THEN80 then(toString).startsWith(format("java.lang.RuntimeException%n"81 + "\tat org.assertj.core.presentation.StandardRepresentation_throwable_format_Test$Test1$Test2.boom2(StandardRepresentation_throwable_format_Test.java"))82 .doesNotContain("remaining lines not displayed");83 }84 @Test85 void should_display_toString_when_null_stack() {86 // GIVEN87 Throwable throwable = mock(Throwable.class);88 when(throwable.toString()).thenReturn("throwable string");89 // WHEN90 String actual = REPRESENTATION.toStringOf(throwable);91 // THEN92 then(actual).isEqualTo("throwable string");93 }94}...

Full Screen

Full Screen

StandardRepresentation

Using AI Code Generation

copy

Full Screen

1public class StandardRepresentation_throwable_format_Test {2 public static void main(String[] args) {3 StandardRepresentation_throwable_format_Test standardRepresentation_throwable_format_Test = new StandardRepresentation_throwable_format_Test();4 standardRepresentation_throwable_format_Test.testThrowableFormat();5 }6 public void testThrowableFormat() {7 org.assertj.core.presentation.StandardRepresentation standardRepresentation = new org.assertj.core.presentation.StandardRepresentation();8 Object o_3_0 = standardRepresentation.toStringOf(new java.lang.Throwable("test"));9 Object o_7_0 = standardRepresentation.toStringOf(new java.lang.Throwable("test"));10 }11}

Full Screen

Full Screen

StandardRepresentation

Using AI Code Generation

copy

Full Screen

1package org.assertj.core.presentation;2import org.assertj.core.api.Assertions;3import org.junit.Test;4public class StandardRepresentation_throwable_format_Test {5 public void test() {6 Assertions.assertThat(new StandardRepresentation().toStringOf(new RuntimeException("message"))).isEqualTo("java.lang.RuntimeException: message");7 }8}9 at org.assertj.core.presentation.StandardRepresentation_throwable_format_Test.test(StandardRepresentation_throwable_format_Test.java:10)10The bug is in the toStringOf(Throwable) method, which is defined as follows:11public String toStringOf(Throwable throwable) {12 return throwable.toString();13}14The bug is that the toString method of the Throwable class does not return the exception message. It returns the exception type and the exception class name. The correct implementation of the toStringOf(Throwable) method should be:15public String toStringOf(Throwable throwable) {16 return throwable.getClass().getName() + ": " + throwable.getMessage();17}

Full Screen

Full Screen

StandardRepresentation

Using AI Code Generation

copy

Full Screen

1public class StandardRepresentation_throwable_format_Test {2 public static void main(String[] args) {3 StandardRepresentation standardRepresentation = new StandardRepresentation();4 Throwable throwable = new Throwable();5 String format = standardRepresentation.format(throwable);6 System.out.println(format);7 }8}9public class StandardRepresentation_throwable_format_Test {10 public static void main(String[] args) {11 StandardRepresentation standardRepresentation = new StandardRepresentation();12 Throwable throwable = new Throwable("Hello");13 String format = standardRepresentation.format(throwable);14 System.out.println(format);15 }16}17public class StandardRepresentation_throwable_format_Test {18 public static void main(String[] args) {19 StandardRepresentation standardRepresentation = new StandardRepresentation();20 Throwable throwable = new Throwable("Hello", new RuntimeException("Hello"));21 String format = standardRepresentation.format(throwable);22 System.out.println(format);23 }24}25public class StandardRepresentation_throwable_format_Test {26 public static void main(String[] args) {27 StandardRepresentation standardRepresentation = new StandardRepresentation();28 Throwable throwable = new Throwable(new RuntimeException("Hello"));29 String format = standardRepresentation.format(throwable);30 System.out.println(format);31 }32}33public class StandardRepresentation_throwable_format_Test {34 public static void main(String[] args) {35 StandardRepresentation standardRepresentation = new StandardRepresentation();36 Throwable throwable = new Throwable(new RuntimeException("Hello", new RuntimeException("Hello")));37 String format = standardRepresentation.format(throwable);38 System.out.println(format);39 }40}

Full Screen

Full Screen

StandardRepresentation

Using AI Code Generation

copy

Full Screen

1package org.assertj.core.presentation;2import org.junit.Test;3public class StandardRepresentation_throwable_format_Test {4 public void test() {5 StandardRepresentation standardRepresentation = new StandardRepresentation();6 Throwable throwable = new Throwable();7 standardRepresentation.throwableFormat(throwable);8 }9}

Full Screen

Full Screen

StandardRepresentation

Using AI Code Generation

copy

Full Screen

1public class StandardRepresentation_throwable_format_Test {2 public void test1() {3 StandardRepresentation standardRepresentation = new StandardRepresentation();4 Throwable throwable = new Throwable();5 System.out.println(standardRepresentation.toStringOf(throwable));6 }7}8 at StandardRepresentation_throwable_format_Test.test1(StandardRepresentation_throwable_format_Test.java:9)9public class StandardRepresentation_throwable_format_Test {10 public void test2() {11 StandardRepresentation standardRepresentation = new StandardRepresentation();12 Throwable throwable = new Throwable();13 System.out.println(standardRepresentation.toStringOf(throwable));14 }15}16 at StandardRepresentation_throwable_format_Test.test2(StandardRepresentation_throwable_format_Test.java:9)17public class StandardRepresentation_throwable_format_Test {18 public void test3() {19 StandardRepresentation standardRepresentation = new StandardRepresentation();20 Throwable throwable = new Throwable();21 System.out.println(standardRepresentation.toStringOf(throwable));22 }23}24 at StandardRepresentation_throwable_format_Test.test3(StandardRepresentation_throwable_format_Test.java:9)25public class StandardRepresentation_throwable_format_Test {26 public void test4() {27 StandardRepresentation standardRepresentation = new StandardRepresentation();28 Throwable throwable = new Throwable();29 System.out.println(standardRepresentation.toStringOf(throwable));30 }31}32 at StandardRepresentation_throwable_format_Test.test4(StandardRepresentation_throwable_format_Test.java:9)33public class StandardRepresentation_throwable_format_Test {34 public void test5() {35 StandardRepresentation standardRepresentation = new StandardRepresentation();36 Throwable throwable = new Throwable();37 System.out.println(standardRepresentation.toStringOf(throwable));38 }39}

Full Screen

Full Screen

StandardRepresentation

Using AI Code Generation

copy

Full Screen

1public class StandardRepresentation_throwable_format_Test {2 public void test1() {3 StandardRepresentation standardRepresentation = new StandardRepresentation();4 Throwable throwable = new Throwable("test");5 String result = standardRepresentation.toStringOf(throwable);6 System.out.println(result);7 }8}9public class StandardRepresentation_throwable_format_Test {10 public void test1() {11 StandardRepresentation standardRepresentation = new StandardRepresentation();12 Throwable throwable = new Throwable("test");13 String result = standardRepresentation.toStringOf(throwable);14 System.out.println(result);15 }16}17public class StandardRepresentation_throwable_format_Test {18 public void test1() {19 StandardRepresentation standardRepresentation = new StandardRepresentation();20 Throwable throwable = new Throwable("test");21 String result = standardRepresentation.toStringOf(throwable);22 System.out.println(result);23 }24}25public class StandardRepresentation_throwable_format_Test {26 public void test1() {27 StandardRepresentation standardRepresentation = new StandardRepresentation();28 Throwable throwable = new Throwable("test");29 String result = standardRepresentation.toStringOf(throwable);30 System.out.println(result);31 }32}33public class StandardRepresentation_throwable_format_Test {34 public void test1() {35 StandardRepresentation standardRepresentation = new StandardRepresentation();36 Throwable throwable = new Throwable("test");37 String result = standardRepresentation.toStringOf(throwable);38 System.out.println(result);39 }40}41public class StandardRepresentation_throwable_format_Test {42 public void test1() {43 StandardRepresentation standardRepresentation = new StandardRepresentation();44 Throwable throwable = new Throwable("test");45 String result = standardRepresentation.toStringOf(throwable);46 System.out.println(result);47 }48}

Full Screen

Full Screen

StandardRepresentation

Using AI Code Generation

copy

Full Screen

1public class StandardRepresentation_throwable_format_Test {2 public void test1() {3 StandardRepresentation standardRepresentation = new StandardRepresentation();4 Throwable throwable = new Throwable();5 String string1 = standardRepresentation.toStringOf(throwable);6 String string2 = standardRepresentation.toStringOf(throwable);7 String string3 = standardRepresentation.toStringOf(throwable);8 String string4 = standardRepresentation.toStringOf(throwable);9 String string5 = standardRepresentation.toStringOf(throwable);10 String string6 = standardRepresentation.toStringOf(throwable);11 String string7 = standardRepresentation.toStringOf(throwable);12 String string8 = standardRepresentation.toStringOf(throwable);13 String string9 = standardRepresentation.toStringOf(throwable);14 String string10 = standardRepresentation.toStringOf(throwable);15 String string11 = standardRepresentation.toStringOf(throwable);16 String string12 = standardRepresentation.toStringOf(throwable);17 String string13 = standardRepresentation.toStringOf(throwable);18 String string14 = standardRepresentation.toStringOf(throwable);19 String string15 = standardRepresentation.toStringOf(throwable);20 String string16 = standardRepresentation.toStringOf(throwable);21 String string17 = standardRepresentation.toStringOf(throwable);22 String string18 = standardRepresentation.toStringOf(throwable);23 String string19 = standardRepresentation.toStringOf(throwable);24 String string20 = standardRepresentation.toStringOf(throwable);25 String string21 = standardRepresentation.toStringOf(throwable);26 String string22 = standardRepresentation.toStringOf(throwable);27 String string23 = standardRepresentation.toStringOf(throwable);28 String string24 = standardRepresentation.toStringOf(throwable);29 String string25 = standardRepresentation.toStringOf(throwable);30 String string26 = standardRepresentation.toStringOf(throwable);

Full Screen

Full Screen

StandardRepresentation

Using AI Code Generation

copy

Full Screen

1package org.assertj.core.presentation;2import static org.assertj.core.api.Assertions.assertThat;3import org.assertj.core.presentation.StandardRepresentation;4import org.junit.jupiter.api.Test;5class StandardRepresentation_throwable_format_Test {6 void should_format_throwable() {7 Throwable throwable = new Throwable("boom!");8 StandardRepresentation representation = new StandardRepresentation();9 String format = representation.format(throwable);10 assertThat(format).isEqualTo("java.lang.Throwable: boom!");11 }12}13package org.assertj.core.presentation;14import static org.assertj.core.api.Assertions.assertThat;15import org.assertj.core.presentation.StandardRepresentation;16import org.junit.jupiter.api.Test;17class StandardRepresentation_throwable_format_Test {18 void should_format_throwable() {19 Throwable throwable = new Throwable("boom!");20 StandardRepresentation representation = new StandardRepresentation();21 String format = representation.format(throwable);22 assertThat(format).isEqualTo("java.lang.Throwable: boom!");23 }24}25package org.assertj.core.presentation;26import static org.assertj.core.api.Assertions.assertThat;27import org.assertj.core.presentation.StandardRepresentation;28import org.junit.jupiter.api.Test;29class StandardRepresentation_throwable_format_Test {30 void should_format_throwable() {31 Throwable throwable = new Throwable("boom!");32 StandardRepresentation representation = new StandardRepresentation();33 String format = representation.format(throwable);34 assertThat(format).isEqualTo("java.lang.Throwable: boom!");35 }36}37package org.assertj.core.presentation;38import static org.assertj.core.api.Assertions.assertThat;39import org.assertj.core.presentation.StandardRepresentation;40import org.junit.jupiter.api.Test;41class StandardRepresentation_throwable_format_Test {

Full Screen

Full Screen

StandardRepresentation

Using AI Code Generation

copy

Full Screen

1public class Test{2 public void test(){3 Throwable throwable = new Exception("boom");4 StandardRepresentation representation = new StandardRepresentation();5 String result = representation.toStringOf(throwable);6 System.out.println(result);7 }8}9 at Test.test(Test.java:6)10public class Test{11 public void test(){12 Throwable throwable = new Exception("boom");13 StandardRepresentation representation = new StandardRepresentation();

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Assertj automation tests on LambdaTest cloud grid

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

Most used method in StandardRepresentation_throwable_format_Test

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful