Skip to content

Commit 0c46b6f

Browse files
authored
chore: remove call to deprecated method (GoogleCloudPlatform#4119)
MockitoAnnotations.initMocks(Object) is deprecated and should be replaced with openMocks(Object) and a call to close() on the returned AutoClosable.
1 parent 68ba515 commit 0c46b6f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

functions/spanner/src/test/java/functions/HelloSpannerTest.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.io.IOException;
3434
import java.io.StringWriter;
3535
import java.util.logging.Logger;
36+
import org.junit.After;
3637
import org.junit.AfterClass;
3738
import org.junit.Before;
3839
import org.junit.BeforeClass;
@@ -44,6 +45,7 @@
4445

4546
@RunWith(JUnit4.class)
4647
public class HelloSpannerTest {
48+
private AutoCloseable mocks;
4749
@Mock private HttpRequest request;
4850
@Mock private HttpResponse response;
4951
@Mock private DatabaseClient client;
@@ -70,7 +72,7 @@ public static void restoreLogging() {
7072

7173
@Before
7274
public void beforeTest() throws IOException {
73-
MockitoAnnotations.initMocks(this);
75+
mocks = MockitoAnnotations.openMocks(this);
7476

7577
responseOut = new StringWriter();
7678
writerOut = new BufferedWriter(responseOut);
@@ -79,6 +81,13 @@ public void beforeTest() throws IOException {
7981
logHandler.clear();
8082
}
8183

84+
@After
85+
public void releaseMocks() throws Exception {
86+
if (mocks != null) {
87+
mocks.close();
88+
}
89+
}
90+
8291
private void setupSuccessfulMockQuery() {
8392
ReadContext readContext = mock(ReadContext.class);
8493
ResultSet resultSet = mock(ResultSet.class);

0 commit comments

Comments
 (0)