Skip to content

Commit ade9286

Browse files
committed
Upgrade mockito to 4.3.1 and remove Powermock
1 parent 4c304e8 commit ade9286

File tree

7 files changed

+37
-64
lines changed

7 files changed

+37
-64
lines changed

httpfixture/src/test/java/org/sonatype/goodies/httpfixture/validation/ValidatingBehaviourTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import org.junit.runner.RunWith;
1919
import org.mockito.ArgumentCaptor;
2020
import org.mockito.Captor;
21-
import org.mockito.runners.MockitoJUnitRunner;
21+
import org.mockito.junit.MockitoJUnitRunner;
2222

2323
import static org.hamcrest.MatcherAssert.assertThat;
2424
import static org.hamcrest.Matchers.equalTo;

httpfixture/src/test/java/org/sonatype/goodies/httpfixture/validation/ValidatingProxyServerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import org.mockito.ArgumentCaptor;
3434
import org.mockito.Captor;
3535
import org.mockito.Mock;
36-
import org.mockito.runners.MockitoJUnitRunner;
36+
import org.mockito.junit.MockitoJUnitRunner;
3737

3838
import static org.hamcrest.MatcherAssert.assertThat;
3939
import static org.hamcrest.Matchers.equalTo;

pom.xml

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454

5555
<slf4j.version>1.7.35</slf4j.version>
5656
<sisu-guice.version>3.2.5</sisu-guice.version>
57-
<powermock.version>1.6.1</powermock.version>
5857
<eclipse-sisu.version>0.3.1</eclipse-sisu.version>
5958
<eclipse-jetty.version>9.4.44.v20210927</eclipse-jetty.version>
6059

@@ -189,16 +188,22 @@
189188
<version>4.13.1</version>
190189
</dependency>
191190

191+
<dependency>
192+
<groupId>org.hamcrest</groupId>
193+
<artifactId>hamcrest</artifactId>
194+
<version>2.2</version>
195+
</dependency>
196+
192197
<dependency>
193198
<groupId>org.hamcrest</groupId>
194199
<artifactId>hamcrest-core</artifactId>
195-
<version>1.3</version>
200+
<version>2.2</version>
196201
</dependency>
197202

198203
<dependency>
199204
<groupId>org.hamcrest</groupId>
200205
<artifactId>hamcrest-library</artifactId>
201-
<version>1.3</version>
206+
<version>2.2</version>
202207
</dependency>
203208

204209
<dependency>
@@ -209,45 +214,15 @@
209214

210215
<dependency>
211216
<groupId>org.mockito</groupId>
212-
<artifactId>mockito-core</artifactId>
213-
<version>1.9.5</version>
214-
</dependency>
215-
216-
<dependency>
217-
<groupId>org.powermock</groupId>
218-
<artifactId>powermock-module-junit4</artifactId>
219-
<version>${powermock.version}</version>
220-
</dependency>
221-
222-
<dependency>
223-
<groupId>org.powermock</groupId>
224-
<artifactId>powermock-api-mockito</artifactId>
225-
<version>${powermock.version}</version>
226-
<exclusions>
227-
<exclusion>
228-
<groupId>org.mockito</groupId>
229-
<artifactId>mockito-all</artifactId>
230-
</exclusion>
231-
</exclusions>
232-
</dependency>
233-
234-
<dependency>
235-
<groupId>org.powermock</groupId>
236-
<artifactId>powermock-module-junit4-rule</artifactId>
237-
<version>${powermock.version}</version>
238-
</dependency>
239-
240-
<dependency>
241-
<groupId>org.powermock</groupId>
242-
<artifactId>powermock-classloading-xstream</artifactId>
243-
<version>${powermock.version}</version>
217+
<artifactId>mockito-inline</artifactId>
218+
<version>4.3.1</version>
244219
</dependency>
245220

246221
<!-- mockito-inline and powermock-reflect depend on different versions of objenesis, force newest -->
247222
<dependency>
248223
<groupId>org.objenesis</groupId>
249224
<artifactId>objenesis</artifactId>
250-
<version>1.3</version>
225+
<version>3.2</version>
251226
</dependency>
252227

253228
<dependency>

testsupport/pom.xml

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363

6464
<dependency>
6565
<groupId>org.hamcrest</groupId>
66-
<artifactId>hamcrest-core</artifactId>
66+
<artifactId>hamcrest</artifactId>
6767
</dependency>
6868

6969
<dependency>
@@ -93,27 +93,7 @@
9393

9494
<dependency>
9595
<groupId>org.mockito</groupId>
96-
<artifactId>mockito-core</artifactId>
97-
</dependency>
98-
99-
<dependency>
100-
<groupId>org.powermock</groupId>
101-
<artifactId>powermock-module-junit4</artifactId>
102-
</dependency>
103-
104-
<dependency>
105-
<groupId>org.powermock</groupId>
106-
<artifactId>powermock-api-mockito</artifactId>
107-
</dependency>
108-
109-
<dependency>
110-
<groupId>org.powermock</groupId>
111-
<artifactId>powermock-module-junit4-rule</artifactId>
112-
</dependency>
113-
114-
<dependency>
115-
<groupId>org.powermock</groupId>
116-
<artifactId>powermock-classloading-xstream</artifactId>
96+
<artifactId>mockito-inline</artifactId>
11797
</dependency>
11898

11999
<dependency>

testsupport/src/main/java/org/sonatype/goodies/testsupport/TestSupport.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import org.sonatype.gossip.Level;
1616

17+
import org.junit.After;
1718
import org.junit.Before;
1819
import org.junit.Rule;
1920
import org.mockito.MockitoAnnotations;
@@ -38,9 +39,18 @@ public class TestSupport
3839
@Rule
3940
public final TestTracer tracer = new TestTracer(this);
4041

42+
private AutoCloseable mocks;
43+
4144
@Before
4245
public void initMocks() {
43-
MockitoAnnotations.initMocks(this);
46+
mocks = MockitoAnnotations.openMocks(this);
47+
}
48+
49+
@After
50+
public void closeMocks() throws Exception {
51+
if (mocks != null) {
52+
mocks.close();
53+
}
4454
}
4555

4656
public Level getLogLevel() {

testsupport/src/main/java/org/sonatype/goodies/testsupport/inject/InjectedTestSupport.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,18 @@ public class InjectedTestSupport
6060
@Rule
6161
public final TestName testName = new TestName();
6262

63+
private AutoCloseable mocks;
64+
6365
@Before
6466
public void initMocks() {
65-
MockitoAnnotations.initMocks(this);
67+
mocks = MockitoAnnotations.openMocks(this);
68+
}
69+
70+
@After
71+
public void closeMocks() throws Exception {
72+
if (mocks != null) {
73+
mocks.close();
74+
}
6675
}
6776

6877
public Level getLogLevel() {

testsupport/src/main/java/org/sonatype/goodies/testsupport/mock/MockitoRule.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ public Statement apply(final Statement base, final Description description) {
5151
@Override
5252
public void evaluate() throws Throwable {
5353
Throwable throwable = null;
54-
try {
55-
MockitoAnnotations.initMocks(testClass);
54+
try (AutoCloseable mocks = MockitoAnnotations.openMocks(testClass)) {
5655
base.evaluate();
5756
}
5857
catch (final Throwable t) {

0 commit comments

Comments
 (0)