-
-
Notifications
You must be signed in to change notification settings - Fork 683
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove stack trace elements coming from AssertJ in addition to Assert…
…J elements. Fix #3449
- Loading branch information
1 parent
2b01a78
commit a8b2a53
Showing
7 changed files
with
147 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 0 additions & 53 deletions
53
...rc/test/java/org/assertj/core/api/fail/Fail_fest_elements_stack_trace_filtering_Test.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
assertj-core/src/test/java/org/example/test/Remove_assertJ_stacktrace_elements_Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* | ||
* Copyright 2012-2024 the original author or authors. | ||
*/ | ||
package org.example.test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.setRemoveAssertJRelatedElementsFromStackTrace; | ||
import static org.assertj.core.api.BDDAssertions.then; | ||
import static org.assertj.core.util.AssertionsUtil.expectAssertionError; | ||
import static org.assertj.core.util.StackTraceUtils.checkNoAssertjStackTraceElementIn; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import org.assertj.core.api.ThrowableAssert.ThrowingCallable; | ||
import org.assertj.core.internal.Failures; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
public class Remove_assertJ_stacktrace_elements_Test { | ||
|
||
private boolean initialRemoveAssertJRelatedElementsFromStackTraceValue; | ||
|
||
@BeforeEach | ||
public void beforeTest() { | ||
initialRemoveAssertJRelatedElementsFromStackTraceValue = Failures.instance().isRemoveAssertJRelatedElementsFromStackTrace(); | ||
setRemoveAssertJRelatedElementsFromStackTrace(true); | ||
} | ||
|
||
@AfterEach | ||
public void afterTest() { | ||
setRemoveAssertJRelatedElementsFromStackTrace(initialRemoveAssertJRelatedElementsFromStackTraceValue); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource | ||
void stacktrace_should_not_include_assertj_elements_nor_elements_coming_from_assertj(ThrowingCallable throwingCallable) { | ||
// WHEN | ||
AssertionError assertionError = expectAssertionError(throwingCallable); | ||
// THEN | ||
checkNoAssertjStackTraceElementIn(assertionError); | ||
// since we remove assertj elements, there is no easy way to check we have removed elements before/above assertj | ||
// -> we check that the first element is the test class itself. | ||
then(assertionError.getStackTrace()[0].toString()).contains("Remove_assertJ_stacktrace_elements_Test"); | ||
|
||
} | ||
|
||
static Stream<ThrowingCallable> stacktrace_should_not_include_assertj_elements_nor_elements_coming_from_assertj() { | ||
return Stream.of(() -> assertThat(0).isEqualTo(1), | ||
() -> assertThat(0).satisfies(x -> assertThat(x).isEqualTo(1))); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters