Skip to content

Commit

Permalink
[Test] Migrate deprecated Matchers to ArgumentMatchers (apache#5423)
Browse files Browse the repository at this point in the history
* Migrate deprecated Matchers to ArgumentMatchers

* Add ServerCnxTest

* add PulsarKafkaProducerTest
  • Loading branch information
liketic authored and merlimat committed Oct 31, 2019
1 parent f01ff8a commit 3d5bc0a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ public void testConnectCommandWithAuthenticationPositive() throws Exception {
doReturn(authenticationService).when(brokerService).getAuthenticationService();
doReturn(authenticationProvider).when(authenticationService).getAuthenticationProvider(Mockito.anyString());
doReturn(authenticationState).when(authenticationProvider)
.newAuthState(Mockito.anyObject(), Mockito.anyObject(), Mockito.anyObject());
.newAuthState(Mockito.any(), Mockito.any(), Mockito.any());
doReturn(authData).when(authenticationState)
.authenticate(authData);
doReturn(true).when(authenticationState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
package org.apache.pulsar.broker.transaction.buffer;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.matches;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.matches;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -247,7 +246,7 @@ public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
return null;
}
}).when(mlFactoryMock)
.asyncOpen(matches(".*success.*"), any(ManagedLedgerConfig.class), any(OpenLedgerCallback.class), anyObject());
.asyncOpen(matches(".*success.*"), any(ManagedLedgerConfig.class), any(OpenLedgerCallback.class), any());

// call openLedgerFailed on ML factory asyncOpen
doAnswer(new Answer<Object>() {
Expand All @@ -258,7 +257,7 @@ public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
return null;
}
}).when(mlFactoryMock)
.asyncOpen(matches(".*fail.*"), any(ManagedLedgerConfig.class), any(OpenLedgerCallback.class), anyObject());
.asyncOpen(matches(".*fail.*"), any(ManagedLedgerConfig.class), any(OpenLedgerCallback.class), any());

// call addComplete on ledger asyncAddEntry
doAnswer(new Answer<Object>() {
Expand All @@ -268,7 +267,7 @@ public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
.addComplete(new PositionImpl(1, 1), invocationOnMock.getArguments()[2]);
return null;
}
}).when(ledgerMock).asyncAddEntry(any(ByteBuf.class), any(AddEntryCallback.class), anyObject());
}).when(ledgerMock).asyncAddEntry(any(ByteBuf.class), any(AddEntryCallback.class), any());

// call openCursorComplete on cursor asyncOpen
doAnswer(new Answer<Object>() {
Expand All @@ -278,7 +277,7 @@ public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
return null;
}
}).when(ledgerMock)
.asyncOpenCursor(matches(".*success.*"), any(InitialPosition.class), any(OpenCursorCallback.class), anyObject());
.asyncOpenCursor(matches(".*success.*"), any(InitialPosition.class), any(OpenCursorCallback.class), any());

doAnswer(new Answer<Object>() {
@Override
Expand All @@ -287,7 +286,7 @@ public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
return null;
}
}).when(ledgerMock).asyncOpenCursor(matches(".*success.*"), any(InitialPosition.class), any(Map.class),
any(OpenCursorCallback.class), anyObject());
any(OpenCursorCallback.class), any());

// call deleteLedgerComplete on ledger asyncDelete
doAnswer(new Answer<Object>() {
Expand All @@ -296,21 +295,21 @@ public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
((DeleteLedgerCallback) invocationOnMock.getArguments()[0]).deleteLedgerComplete(null);
return null;
}
}).when(ledgerMock).asyncDelete(any(DeleteLedgerCallback.class), anyObject());
}).when(ledgerMock).asyncDelete(any(DeleteLedgerCallback.class), any());

doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
((DeleteCursorCallback) invocationOnMock.getArguments()[1]).deleteCursorComplete(null);
return null;
}
}).when(ledgerMock).asyncDeleteCursor(matches(".*success.*"), any(DeleteCursorCallback.class), anyObject());
}).when(ledgerMock).asyncDeleteCursor(matches(".*success.*"), any(DeleteCursorCallback.class), any());

doAnswer((invokactionOnMock) -> {
((MarkDeleteCallback) invokactionOnMock.getArguments()[2])
.markDeleteComplete(invokactionOnMock.getArguments()[3]);
return null;
}).when(cursorMock).asyncMarkDelete(anyObject(), anyObject(), any(MarkDeleteCallback.class), anyObject());
}).when(cursorMock).asyncMarkDelete(any(), any(), any(MarkDeleteCallback.class), any());

this.buffer = new PersistentTransactionBuffer(successTopicName, factory.open("hello"), brokerService);
}
Expand Down Expand Up @@ -517,7 +516,7 @@ public void testPurgeTxns() throws Exception {
assertEquals(txnId3, meta3.id());
assertEquals(TxnStatus.COMMITTED, meta3.status());

buffer.purgeTxns(Lists.newArrayList(Long.valueOf(22L))).get();
buffer.purgeTxns(Lists.newArrayList(22L)).get();

verifyTxnNotExist(txnId2);

Expand All @@ -531,7 +530,7 @@ public void testPurgeTxns() throws Exception {

// purge a non exist ledger.
try {
buffer.purgeTxns(Lists.newArrayList(Long.valueOf(1L))).get();
buffer.purgeTxns(Lists.newArrayList(1L)).get();
} catch (ExecutionException e) {
assertTrue(e.getCause() instanceof NoTxnsCommittedAtLedgerException);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.anyVararg;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -143,7 +142,7 @@ public void testPulsarKafkaInterceptor() throws PulsarClientException {
doReturn(mockPartitionFuture).when(mockClient).getPartitionsForTopic(anyString());
doReturn(mockProducerBuilder).when(mockProducerBuilder).topic(anyString());
doReturn(mockProducerBuilder).when(mockProducerBuilder).clone();
doReturn(mockProducerBuilder).when(mockProducerBuilder).intercept(anyVararg());
doReturn(mockProducerBuilder).when(mockProducerBuilder).intercept(any());
doReturn(mockProducer).when(mockProducerBuilder).create();
doReturn(mockTypedMessageBuilder).when(mockProducer).newMessage();
doReturn(mockSendAsyncFuture).when(mockTypedMessageBuilder).sendAsync();
Expand All @@ -169,7 +168,7 @@ public void testPulsarKafkaInterceptor() throws PulsarClientException {
pulsarKafkaProducer.send(new ProducerRecord<>("topic", 1,"key", "value"));

// Verify
verify(mockProducerBuilder, times(1)).intercept(anyVararg());
verify(mockProducerBuilder, times(1)).intercept(any());
}

@Test
Expand All @@ -191,7 +190,7 @@ public void testPulsarKafkaSendAvro() throws PulsarClientException {
doReturn(mockPartitionFuture).when(mockClient).getPartitionsForTopic(anyString());
doReturn(mockProducerBuilder).when(mockProducerBuilder).topic(anyString());
doReturn(mockProducerBuilder).when(mockProducerBuilder).clone();
doReturn(mockProducerBuilder).when(mockProducerBuilder).intercept(anyVararg());
doReturn(mockProducerBuilder).when(mockProducerBuilder).intercept(any());
doReturn(mockProducer).when(mockProducerBuilder).create();
doReturn(mockTypedMessageBuilder).when(mockProducer).newMessage();
doReturn(mockSendAsyncFuture).when(mockTypedMessageBuilder).sendAsync();
Expand Down Expand Up @@ -228,7 +227,7 @@ public void testPulsarKafkaSendAvro() throws PulsarClientException {

// Verify
verify(mockTypedMessageBuilder, times(1)).sendAsync();
verify(mockProducerBuilder, times(1)).intercept(anyVararg());
verify(mockProducerBuilder, times(1)).intercept(any());
}

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "Invalid value 2147483648000 for 'connections.max.idle.ms'. Please use a value smaller than 2147483647000 milliseconds.")
Expand Down

0 comments on commit 3d5bc0a

Please sign in to comment.