You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bookkeeper.apache.org by ni...@apache.org on 2022/03/30 23:10:31 UTC

[bookkeeper] branch master updated: use mockito.any instead of deprecated mockito.anyObject

This is an automated email from the ASF dual-hosted git repository.

nicoloboschi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git


The following commit(s) were added to refs/heads/master by this push:
     new ba2dede  use mockito.any instead of deprecated mockito.anyObject
ba2dede is described below

commit ba2dede103458f6ba64a8fa90e83ac27034cf13c
Author: ZhangJian He <sh...@gmail.com>
AuthorDate: Thu Mar 31 07:10:25 2022 +0800

    use mockito.any instead of deprecated mockito.anyObject
    
    ### Changes
    use mockito.any instead of deprecated mockito.anyObject
    
    
    Reviewers: Andrey Yegorov <None>, Nicolò Boschi <bo...@gmail.com>
    
    This closes #3152 from Shoothzj/use-mockito-any-instead-of-anyObject
---
 .../bookie/datainteg/CookieValidationTest.java     | 14 ++---
 .../bookie/datainteg/DataIntegrityCheckTest.java   | 10 ++--
 .../bookie/datainteg/EntryCopierTest.java          | 62 +++++++++++-----------
 3 files changed, 43 insertions(+), 43 deletions(-)

diff --git a/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/datainteg/CookieValidationTest.java b/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/datainteg/CookieValidationTest.java
index a424d00..35651fa 100644
--- a/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/datainteg/CookieValidationTest.java
+++ b/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/datainteg/CookieValidationTest.java
@@ -24,7 +24,7 @@ import static org.hamcrest.Matchers.equalTo;
 import static org.hamcrest.Matchers.greaterThan;
 import static org.hamcrest.Matchers.not;
 import static org.hamcrest.Matchers.notNullValue;
-import static org.mockito.Mockito.anyObject;
+import static org.mockito.Mockito.any;
 import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
@@ -225,7 +225,7 @@ public class CookieValidationTest {
 
         v1.checkCookies(dirs); // stamp original cookies
         verify(dataIntegCheck, times(0)).runPreBootCheck("INVALID_COOKIE");
-        verify(regManager, times(1)).writeCookie(anyObject(), anyObject());
+        verify(regManager, times(1)).writeCookie(any(), any());
 
         // add a directory to trigger data integrity check
         dirs.add(initializedDir());
@@ -236,7 +236,7 @@ public class CookieValidationTest {
             // expected
         }
         verify(dataIntegCheck, times(1)).runPreBootCheck("INVALID_COOKIE");
-        verify(regManager, times(1)).writeCookie(anyObject(), anyObject());
+        verify(regManager, times(1)).writeCookie(any(), any());
 
         // running the check again should run data integrity again, as stamping didn't happen
         try {
@@ -246,7 +246,7 @@ public class CookieValidationTest {
             // expected
         }
         verify(dataIntegCheck, times(2)).runPreBootCheck("INVALID_COOKIE");
-        verify(regManager, times(1)).writeCookie(anyObject(), anyObject());
+        verify(regManager, times(1)).writeCookie(any(), any());
     }
 
     @Test
@@ -289,7 +289,7 @@ public class CookieValidationTest {
         v1.checkCookies(dirs); // stamp original cookies
 
         verify(dataIntegCheck, times(0)).runPreBootCheck("INVALID_COOKIE");
-        verify(regManager, times(1)).writeCookie(anyObject(), anyObject());
+        verify(regManager, times(1)).writeCookie(any(), any());
 
         Cookie current = Cookie.readFromDirectory(dirs.get(0));
         Cookie mismatch = Cookie.newBuilder(current).setBookieId("mismatch:3181").build();
@@ -298,7 +298,7 @@ public class CookieValidationTest {
 
         v1.checkCookies(dirs);
         verify(dataIntegCheck, times(1)).runPreBootCheck("INVALID_COOKIE");
-        verify(regManager, times(2)).writeCookie(anyObject(), anyObject());
+        verify(regManager, times(2)).writeCookie(any(), any());
 
         Cookie afterCheck = Cookie.readFromDirectory(dirs.get(0));
         assertThat(afterCheck, equalTo(current));
@@ -318,7 +318,7 @@ public class CookieValidationTest {
         v1.checkCookies(dirs); // stamp original cookies
 
         verify(dataIntegCheck, times(0)).runPreBootCheck("INVALID_COOKIE");
-        verify(regManager, times(1)).writeCookie(anyObject(), anyObject());
+        verify(regManager, times(1)).writeCookie(any(), any());
 
         File cookieFile = new File(dirs.get(0), BookKeeperConstants.VERSION_FILENAME);
         try (FileOutputStream out = new FileOutputStream(cookieFile)) {
diff --git a/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/datainteg/DataIntegrityCheckTest.java b/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/datainteg/DataIntegrityCheckTest.java
index d5e240d..0834c30 100644
--- a/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/datainteg/DataIntegrityCheckTest.java
+++ b/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/datainteg/DataIntegrityCheckTest.java
@@ -26,9 +26,9 @@ import static org.hamcrest.Matchers.instanceOf;
 import static org.hamcrest.Matchers.is;
 import static org.hamcrest.Matchers.isIn;
 import static org.hamcrest.Matchers.not;
+import static org.mockito.Mockito.any;
 import static org.mockito.Mockito.anyInt;
 import static org.mockito.Mockito.anyLong;
-import static org.mockito.Mockito.anyObject;
 import static org.mockito.Mockito.eq;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.spy;
@@ -812,12 +812,12 @@ public class DataIntegrityCheckTest {
 
         for (long e = 0; e <= metadata1.getLastEntryId(); e++) {
             if (e % 2 == 0) {
-                verify(bookieClient, times(0)).readEntry(anyObject(), eq(id1), eq(e),
-                                                         anyObject(), anyObject(), anyInt());
+                verify(bookieClient, times(0)).readEntry(any(), eq(id1), eq(e),
+                                                         any(), any(), anyInt());
             }
             if (e % 2 == 1) {
-                verify(bookieClient, times(1)).readEntry(anyObject(), eq(id1), eq(e),
-                                                         anyObject(), anyObject(), anyInt());
+                verify(bookieClient, times(1)).readEntry(any(), eq(id1), eq(e),
+                                                         any(), any(), anyInt());
             }
 
             assertThat(storage.entryExists(id1, e), equalTo(true));
diff --git a/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/datainteg/EntryCopierTest.java b/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/datainteg/EntryCopierTest.java
index f4b851d..8ea6269 100644
--- a/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/datainteg/EntryCopierTest.java
+++ b/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/datainteg/EntryCopierTest.java
@@ -23,9 +23,9 @@ import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.contains;
 import static org.hamcrest.Matchers.equalTo;
 import static org.hamcrest.Matchers.instanceOf;
+import static org.mockito.Mockito.any;
 import static org.mockito.Mockito.anyInt;
 import static org.mockito.Mockito.anyLong;
-import static org.mockito.Mockito.anyObject;
 import static org.mockito.Mockito.eq;
 import static org.mockito.Mockito.inOrder;
 import static org.mockito.Mockito.spy;
@@ -136,17 +136,17 @@ public class EntryCopierTest {
         CompletableFuture.allOf(f1, f2, f3, f4).get();
 
         verify(bookieClient, times(1)).readEntry(eq(bookie2), eq(ledgerId), eq(0L),
-                                                 anyObject(), anyObject(), anyInt(), anyObject());
+                                                 any(), any(), anyInt(), any());
         verify(bookieClient, times(1)).readEntry(eq(bookie2), eq(ledgerId), eq(2L),
-                                                 anyObject(), anyObject(), anyInt(), anyObject());
+                                                 any(), any(), anyInt(), any());
         verify(bookieClient, times(1)).readEntry(eq(bookie2), eq(ledgerId), eq(4L),
-                                                 anyObject(), anyObject(), anyInt(), anyObject());
+                                                 any(), any(), anyInt(), any());
         verify(bookieClient, times(1)).readEntry(eq(bookie2), eq(ledgerId), eq(10L),
-                                                 anyObject(), anyObject(), anyInt(), anyObject());
+                                                 any(), any(), anyInt(), any());
         verify(bookieClient, times(4)).readEntry(eq(bookie2), eq(ledgerId), anyLong(),
-                                                 anyObject(), anyObject(), anyInt(), anyObject());
+                                                 any(), any(), anyInt(), any());
 
-        verify(storage, times(4)).addEntry(anyObject());
+        verify(storage, times(4)).addEntry(any());
         assertThat(storage.entryExists(ledgerId, 0), equalTo(true));
         assertThat(storage.entryExists(ledgerId, 2), equalTo(true));
         assertThat(storage.entryExists(ledgerId, 4), equalTo(true));
@@ -229,7 +229,7 @@ public class EntryCopierTest {
         }
 
         // other entries should still have been added
-        verify(storage, times(3)).addEntry(anyObject());
+        verify(storage, times(3)).addEntry(any());
         assertThat(storage.entryExists(ledgerId, 0), equalTo(true));
         assertThat(storage.entryExists(ledgerId, 4), equalTo(true));
         assertThat(storage.entryExists(ledgerId, 10), equalTo(true));
@@ -272,7 +272,7 @@ public class EntryCopierTest {
         }
 
         // Nothing should have been added
-        verify(storage, times(0)).addEntry(anyObject());
+        verify(storage, times(0)).addEntry(any());
     }
 
     @Test
@@ -319,7 +319,7 @@ public class EntryCopierTest {
         }
 
         // other entries should still have been added
-        verify(storage, times(4)).addEntry(anyObject());
+        verify(storage, times(4)).addEntry(any());
         assertThat(storage.entryExists(ledgerId, 0), equalTo(false));
         assertThat(storage.entryExists(ledgerId, 2), equalTo(true));
         assertThat(storage.entryExists(ledgerId, 4), equalTo(true));
@@ -366,7 +366,7 @@ public class EntryCopierTest {
         }
 
         // other entries should still have been added
-        verify(storage, times(4)).addEntry(anyObject());
+        verify(storage, times(4)).addEntry(any());
         assertThat(storage.entryExists(ledgerId, 0), equalTo(false));
         assertThat(storage.entryExists(ledgerId, 2), equalTo(false));
         assertThat(storage.entryExists(ledgerId, 4), equalTo(false));
@@ -397,10 +397,10 @@ public class EntryCopierTest {
         EntryCopierImpl.BatchImpl batch = (EntryCopierImpl.BatchImpl) copier.newBatch(ledgerId, metadata);
         for (int i = 0; i <= 10; i++) {
             batch.fetchEntry(i).get();
-            verify(bookieClient, times(i + 1)).readEntry(anyObject(), anyLong(), anyLong(),
-                                                       anyObject(), anyObject(), anyInt());
+            verify(bookieClient, times(i + 1)).readEntry(any(), anyLong(), anyLong(),
+                                                       any(), any(), anyInt());
             verify(bookieClient, times(i + 1)).readEntry(eq(bookie3), anyLong(), anyLong(),
-                                                       anyObject(), anyObject(), anyInt());
+                                                       any(), any(), anyInt());
         }
     }
 
@@ -440,20 +440,20 @@ public class EntryCopierTest {
         batch.fetchEntry(0).get();
 
         // will read twice, fail at bookie3, succeed at bookie1
-        verify(bookieClient, times(2)).readEntry(anyObject(), anyLong(), anyLong(),
-                                                 anyObject(), anyObject(), anyInt());
+        verify(bookieClient, times(2)).readEntry(any(), anyLong(), anyLong(),
+                                                 any(), any(), anyInt());
         verify(bookieClient, times(1)).readEntry(eq(bookie3), anyLong(), anyLong(),
-                                                 anyObject(), anyObject(), anyInt());
+                                                 any(), any(), anyInt());
         verify(bookieClient, times(1)).readEntry(eq(bookie1), anyLong(), anyLong(),
-                                                 anyObject(), anyObject(), anyInt());
+                                                 any(), any(), anyInt());
         errorProcessedPromise.get(10, TimeUnit.SECONDS);
         batch.fetchEntry(1).get();
 
         // subsequent read should go straight for bookie1
-        verify(bookieClient, times(3)).readEntry(anyObject(), anyLong(), anyLong(),
-                                                       anyObject(), anyObject(), anyInt());
+        verify(bookieClient, times(3)).readEntry(any(), anyLong(), anyLong(),
+                                                       any(), any(), anyInt());
         verify(bookieClient, times(2)).readEntry(eq(bookie1), anyLong(), anyLong(),
-                                                   anyObject(), anyObject(), anyInt());
+                                                   any(), any(), anyInt());
     }
 
     @Test
@@ -497,9 +497,9 @@ public class EntryCopierTest {
 
         InOrder inOrder = inOrder(bookieClient);
         inOrder.verify(bookieClient, times(1)).readEntry(eq(bookie3), anyLong(), anyLong(),
-                                                         anyObject(), anyObject(), anyInt());
+                                                         any(), any(), anyInt());
         inOrder.verify(bookieClient, times(1)).readEntry(eq(bookie1), anyLong(), anyLong(),
-                                                         anyObject(), anyObject(), anyInt());
+                                                         any(), any(), anyInt());
     }
 
     @Test
@@ -537,9 +537,9 @@ public class EntryCopierTest {
             };
         batch.fetchEntry(0).get();
         verify(bookieClient, times(1)).readEntry(eq(bookie3), anyLong(), anyLong(),
-                                                 anyObject(), anyObject(), anyInt());
+                                                 any(), any(), anyInt());
         verify(bookieClient, times(1)).readEntry(eq(bookie1), anyLong(), anyLong(),
-                                                 anyObject(), anyObject(), anyInt());
+                                                 any(), any(), anyInt());
         errorProcessedPromise.get(10, TimeUnit.SECONDS);
 
         // bookie3 should be fine to use again, but we shouldn't use it until if come out
@@ -550,9 +550,9 @@ public class EntryCopierTest {
         EntryCopierImpl.BatchImpl batch2 = copier.new BatchImpl(bookie2, ledgerId, metadata, sinBin);
         batch2.fetchEntry(0).get();
         verify(bookieClient, times(1)).readEntry(eq(bookie3), anyLong(), anyLong(),
-                                                 anyObject(), anyObject(), anyInt());
+                                                 any(), any(), anyInt());
         verify(bookieClient, times(2)).readEntry(eq(bookie1), anyLong(), anyLong(),
-                                                 anyObject(), anyObject(), anyInt());
+                                                 any(), any(), anyInt());
         // advance time
         ticker.advance(70, TimeUnit.SECONDS);
 
@@ -560,9 +560,9 @@ public class EntryCopierTest {
         EntryCopierImpl.BatchImpl batch3 = copier.new BatchImpl(bookie2, ledgerId, metadata, sinBin);
         batch3.fetchEntry(0).get();
         verify(bookieClient, times(2)).readEntry(eq(bookie3), anyLong(), anyLong(),
-                                                 anyObject(), anyObject(), anyInt());
+                                                 any(), any(), anyInt());
         verify(bookieClient, times(2)).readEntry(eq(bookie1), anyLong(), anyLong(),
-                                                 anyObject(), anyObject(), anyInt());
+                                                 any(), any(), anyInt());
     }
 
     @Test
@@ -595,8 +595,8 @@ public class EntryCopierTest {
         } catch (ExecutionException ee) {
             assertThat(ee.getCause(), instanceOf(BKException.BKReadException.class));
         }
-        verify(bookieClient, times(0)).readEntry(anyObject(), anyLong(), anyLong(),
-                                                 anyObject(), anyObject(), anyInt());
+        verify(bookieClient, times(0)).readEntry(any(), anyLong(), anyLong(),
+                                                 any(), any(), anyInt());
     }
 
     @Test