Skip to content

Commit

Permalink
(issue 20): Handle top-level nested test classes (#22)
Browse files Browse the repository at this point in the history
* (issue 20): fix issue where spring integration tests that do not declare any @MockInBean fields throw an exception due to applicableTestContext being null

* handle top-level nested test classes

---------

Co-authored-by: jamesforward <[email protected]>
  • Loading branch information
antoinemeyer and jamfor352 authored Apr 12, 2023
1 parent 17f5f3d commit f223fa8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.teketik</groupId>
<artifactId>mock-in-bean</artifactId>
<version>boot2-v1.5.1</version>
<version>boot2-v1.5.2</version>
<name>Mock in Bean</name>
<description>Surgically Inject Mockito Mock/Spy in Spring Beans</description>
<url>https://github.com/antoinemeyer/mock-in-bean</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,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 f223fa8

Please sign in to comment.