Skip to content

Commit

Permalink
Fix IntelliJ flaky test due to JUnit upgrade to version 5.7
Browse files Browse the repository at this point in the history
  • Loading branch information
scordio committed Feb 7, 2021
1 parent 61e1143 commit fff48ca
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
package org.assertj.core.presentation;

import static java.lang.String.format;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.assertj.core.api.BDDAssertions.then;

import org.assertj.core.configuration.Configuration;
import org.junit.jupiter.api.Test;
Expand All @@ -25,6 +25,7 @@
* @author XiaoMingZHM Eveneko
*/
class StandardRepresentation_throwable_format_Test {

private static final Representation REPRESENTATION = new StandardRepresentation();

// Just to make sure the stack trace is long enough.
Expand All @@ -48,9 +49,9 @@ void should_not_display_stacktrace_if_maxStackTraceElementsDisplayed_is_zero() {
configuration.setMaxStackTraceElementsDisplayed(0);
configuration.apply();
// WHEN
String toString = REPRESENTATION.toStringOf(catchThrowable(() -> Test1.boom()));
String toString = REPRESENTATION.toStringOf(catchThrowable(Test1::boom));
// THEN
assertThat(toString).isEqualTo("java.lang.RuntimeException");
then(toString).isEqualTo("java.lang.RuntimeException");
}

@Test
Expand All @@ -60,13 +61,17 @@ void should_display_the_configured_number_of_stacktrace_elements() {
// configuration.setMaxStackTraceElementsDisplayed(3);
configuration.apply();
// WHEN
String toString = REPRESENTATION.toStringOf(catchThrowable(() -> Test1.boom()));
String toString = REPRESENTATION.toStringOf(catchThrowable(Test1::boom));
// THEN
assertThat(toString).containsSubsequence(format("java.lang.RuntimeException%n"),
format("\tat org.assertj.core.presentation.StandardRepresentation_throwable_format_Test$Test1$Test2.boom2(StandardRepresentation_throwable_format_Test.java:"),
format("\tat org.assertj.core.presentation.StandardRepresentation_throwable_format_Test$Test1.boom(StandardRepresentation_throwable_format_Test.java"),
format("\tat org.assertj.core.presentation.StandardRepresentation_throwable_format_Test.lambda"),
format("\t...(71 remaining lines not displayed - this can be changed with Assertions.setMaxStackTraceElementsDisplayed)"));
then(toString).matches("java\\.lang\\.RuntimeException\\R"
+
"\\tat org\\.assertj\\.core\\.presentation\\.StandardRepresentation_throwable_format_Test\\$Test1\\$Test2\\.boom2\\(StandardRepresentation_throwable_format_Test\\.java:36\\)\\R"
+
"\\tat org\\.assertj\\.core\\.presentation\\.StandardRepresentation_throwable_format_Test\\$Test1\\.boom\\(StandardRepresentation_throwable_format_Test\\.java:41\\)\\R"
+
"\\tat org\\.assertj\\.core\\.api\\.ThrowableAssert\\.catchThrowable\\(ThrowableAssert\\.java:62\\)\\R"
+
"\\t\\.{3}\\(\\d+ remaining lines not displayed - this can be changed with Assertions\\.setMaxStackTraceElementsDisplayed\\)");
}

@Test
Expand All @@ -76,11 +81,11 @@ void should_display_the_full_stacktrace() {
configuration.setMaxStackTraceElementsDisplayed(100);
configuration.apply();
// WHEN
String toString = REPRESENTATION.toStringOf(catchThrowable(() -> Test1.boom()));
String toString = REPRESENTATION.toStringOf(catchThrowable(Test1::boom));
// THEN
assertThat(toString).startsWith(format("java.lang.RuntimeException%n"
+ "\tat org.assertj.core.presentation.StandardRepresentation_throwable_format_Test$Test1$Test2.boom2(StandardRepresentation_throwable_format_Test.java"))
.doesNotContain("remaining lines not displayed");
then(toString).startsWith(format("java.lang.RuntimeException%n"
+ "\tat org.assertj.core.presentation.StandardRepresentation_throwable_format_Test$Test1$Test2.boom2(StandardRepresentation_throwable_format_Test.java"))
.doesNotContain("remaining lines not displayed");
}

}
10 changes: 5 additions & 5 deletions verify.bndrun
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
-runbundles: \
assertj-core;version='[3.19.1,3.19.2)',\
assertj-core-tests;version='[3.19.1,3.19.2)',\
junit-jupiter-api;version='[5.6.3,5.6.4)',\
junit-jupiter-engine;version='[5.6.3,5.6.4)',\
junit-platform-commons;version='[1.6.3,1.6.4)',\
junit-platform-engine;version='[1.6.3,1.6.4)',\
junit-platform-launcher;version='[1.6.3,1.6.4)',\
junit-jupiter-api;version='[5.7.1,5.7.2)',\
junit-jupiter-engine;version='[5.7.1,5.7.2)',\
junit-platform-commons;version='[1.7.1,1.7.2)',\
junit-platform-engine;version='[1.7.1,1.7.2)',\
junit-platform-launcher;version='[1.7.1,1.7.2)',\
org.opentest4j;version='[1.2.0,1.2.1)'

0 comments on commit fff48ca

Please sign in to comment.