Skip to content

Commit

Permalink
v1.5.1 handle multiple layers of nested test classes (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximilianWiedemann authored Nov 3, 2022
1 parent e9565bc commit 342c540
Show file tree
Hide file tree
Showing 4 changed files with 16 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</version>
<version>boot2-v1.5.1</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</version>
<version>boot2-v1.5.1</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 @@ -142,7 +142,7 @@ private Class<?> extractClass(Definition definition) {

private Class<?> resolveTestClass(Class<?> candidate) {
if (isNestedTestClass(candidate)) {
return candidate.getEnclosingClass();
return resolveTestClass(candidate.getEnclosingClass());
}
return candidate;
}
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/com/teketik/test/mockinbean/test/NestedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ public void test2() {
Mockito.when(expensiveProcessor.returnSomethingExpensive()).thenThrow(RuntimeException.class);
Assertions.assertThrows(RuntimeException.class, () -> myService.doSomething());
}

@Nested
class NestedInner1 {

@Test
void resultReturnMockedValue() {
final Object somethingExpensive = new Object();
Mockito.when(expensiveProcessor.returnSomethingExpensive()).thenReturn(somethingExpensive);
myService.doSomething();
Mockito.verify(thirdPartyApiService).doSomethingOnThirdPartyApi(somethingExpensive);
}

}
}

@Nested
Expand Down

0 comments on commit 342c540

Please sign in to comment.