Skip to content
Permalink
Browse files
use mockito.any instead of deprecated mockito.anyObject
### Changes
use mockito.any instead of deprecated mockito.anyObject


Reviewers: Andrey Yegorov <None>, Nicolò Boschi <boschi1997@gmail.com>

This closes #3152 from Shoothzj/use-mockito-any-instead-of-anyObject
  • Loading branch information
Shoothzj committed Mar 30, 2022
1 parent 18e3f85 commit ba2dede103458f6ba64a8fa90e83ac27034cf13c
Showing 3 changed files with 43 additions and 43 deletions.
@@ -24,7 +24,7 @@
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 CompletableFuture<Void> runPreBootCheck(String reason) {

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 CompletableFuture<Void> runPreBootCheck(String reason) {
// 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 CompletableFuture<Void> runPreBootCheck(String reason) {
// 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 void testMismatchLocalCookie() throws Exception {
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 void testMismatchLocalCookie() throws Exception {

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 void testCorruptLocalCookie() throws Exception {
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)) {
@@ -26,9 +26,9 @@
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 void testRecoverSingleLedgerEntriesOnlyEntriesNeededEverySecond() throws

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));
@@ -23,9 +23,9 @@
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 void testCopyFromAvailable() throws Exception {
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 void testCopyOneEntryFails() throws Exception {
}

// 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 void testCopyAllEntriesFail() throws Exception {
}

// Nothing should have been added
verify(storage, times(0)).addEntry(anyObject());
verify(storage, times(0)).addEntry(any());
}

@Test
@@ -319,7 +319,7 @@ public long addEntry(ByteBuf buffer) throws IOException, BookieException {
}

// 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 long addEntry(ByteBuf buffer) throws IOException, BookieException {
}

// 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 void testReadOneEntry() throws Exception {
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 @@ void notifyBookieError(BookieId bookie) {
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 void testReadOneAllReplicasFail() throws Exception {

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 @@ void notifyBookieError(BookieId bookie) {
};
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,19 +550,19 @@ void notifyBookieError(BookieId bookie) {
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);

// sinbinned bookie should be restored, read should come from bookie3 again
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 void testReadEntryOnlyOnSelf() throws Exception {
} 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

0 comments on commit ba2dede

Please sign in to comment.