Skip to content

Commit

Permalink
handle top-level nested test classes
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinemeyer committed Apr 11, 2023
1 parent d0de2ad commit 03a60b7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Simply include the maven dependency (from central maven) to start using @MockInB
<dependency>
<groupId>com.teketik</groupId>
<artifactId>mock-in-bean</artifactId>
<version>boot2-v1.5.1</version>
<version>boot2-v1.5.2</version>
<scope>test</scope>
</dependency>
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ public void beforeTestClass(TestContext testContext) throws Exception {
public void beforeTestMethod(TestContext testContext) throws Exception {
final TestContext applicableTestContext = ROOT_TEST_CONTEXT_TRACKER
.get(resolveTestClass(testContext.getTestClass()));
if(applicableTestContext == null) {
return; // required to handle nested spring integration test classes that do not have any @MockInBean declarations
}
final Map<Definition, Object> mockOrSpys = new HashMap<>();
((LinkedList<FieldState>) applicableTestContext.getAttribute(ORIGINAL_VALUES_ATTRIBUTE_NAME))
.forEach(fieldState -> {
Expand Down Expand Up @@ -151,7 +148,8 @@ private Class<?> resolveTestClass(Class<?> candidate) {
}

private boolean isNestedTestClass(Class<?> candidate) {
return AnnotationUtils.isAnnotationDeclaredLocally(Nested.class, candidate);
return AnnotationUtils.isAnnotationDeclaredLocally(Nested.class, candidate)
&& candidate.getEnclosingClass() != null;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.teketik.test.mockinbean.test;

import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

@Nested
class NestedTopLevelTest extends BaseTest {

@Test
public void test() {
}

}

0 comments on commit 03a60b7

Please sign in to comment.