|
19 | 19 | import org.mockito.quality.Strictness;
|
20 | 20 | import org.testng.IInvokedMethod;
|
21 | 21 | import org.testng.IInvokedMethodListener;
|
22 |
| -import org.testng.ITestNGMethod; |
23 | 22 | import org.testng.ITestResult;
|
24 | 23 | import org.testng.annotations.Listeners;
|
25 | 24 |
|
|
30 | 29 | *
|
31 | 30 | * <ul>
|
32 | 31 | * <li>
|
33 |
| - * Before any TestNG method, either a <em>configuration method</em> (@BeforeMethod, @BeforeClass, etc) |
34 |
| - * or a <em>test</em> method MockitoSession is started by: |
| 32 | + * Before any <em>test</em> method or a <em>configuration method</em> <em>@BeforeMethod</em> |
| 33 | + * MockitoSession is started by: |
| 34 | + * |
35 | 35 | * <pre class="code"><code class="java">
|
36 | 36 | * Mockito.mockitoSession()
|
37 | 37 | * .initMocks(testInstance)
|
@@ -125,16 +125,11 @@ public void afterInvocation(IInvokedMethod method, ITestResult testResult) {
|
125 | 125 | }
|
126 | 126 |
|
127 | 127 | private boolean shouldBeRunBeforeInvocation(IInvokedMethod method, ITestResult testResult) {
|
128 |
| - return !isAfterConfigurationMethod(method) && hasMockitoTestNGListener(testResult); |
| 128 | + return (method.isTestMethod() || isBeforeMethod(method)) && hasMockitoTestNGListener(testResult); |
129 | 129 | }
|
130 | 130 |
|
131 |
| - private boolean isAfterConfigurationMethod(IInvokedMethod method) { |
132 |
| - ITestNGMethod testMethod = method.getTestMethod(); |
133 |
| - return testMethod.isAfterClassConfiguration() |
134 |
| - || testMethod.isAfterMethodConfiguration() |
135 |
| - || testMethod.isAfterGroupsConfiguration() |
136 |
| - || testMethod.isAfterTestConfiguration() |
137 |
| - || testMethod.isAfterSuiteConfiguration(); |
| 131 | + private boolean isBeforeMethod(IInvokedMethod method) { |
| 132 | + return method.getTestMethod().isBeforeMethodConfiguration(); |
138 | 133 | }
|
139 | 134 |
|
140 | 135 | private boolean shouldBeRunAfterInvocation(IInvokedMethod method, ITestResult testResult) {
|
|
0 commit comments