import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.ArgumentMatchers;
import org.mockito.InOrder;
-import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.invocation.InvocationOnMock;
import org.mockito.runners.MockitoJUnitRunner;
-import org.mockito.stubbing.Answer;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.openflowplugin.applications.frsync.SyncReactor;
import org.opendaylight.openflowplugin.applications.frsync.util.SyncupEntry;
public void setUp() {
final ExecutorService executorService = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder()
.setDaemon(false)
- .setNameFormat("frsync-test%d")
- .setUncaughtExceptionHandler((thread, e) -> LOG.error("Uncaught exception {}", thread, e))
+ .setNameFormat("frsync-test-%d")
+ .setUncaughtExceptionHandler((thread, ex) -> LOG.error("Uncaught exception {}", thread, ex))
.build());
syncThreadPool = MoreExecutors.listeningDecorator(executorService);
reactor = new SyncReactorFutureZipDecorator(delegate, syncThreadPool);
final SyncupEntry zipped = new SyncupEntry(dataAfter2, configDS, dataBefore, configDS);
final List<ListenableFuture<Boolean>> allResults = new ArrayList<>();
- Mockito.when(delegate.syncup(Matchers.<InstanceIdentifier<FlowCapableNode>>any(), Mockito.eq(first)))
- .thenAnswer(new Answer<ListenableFuture<Boolean>>() {
- @Override
- public ListenableFuture<Boolean> answer(final InvocationOnMock invocationOnMock) throws Throwable {
- LOG.info("unlocking next configs");
- latchForNext.countDown();
- latchForFirst.await();
- LOG.info("unlocking first delegate");
- return Futures.immediateFuture(Boolean.TRUE);
- }
+ Mockito.when(delegate.syncup(ArgumentMatchers.<InstanceIdentifier<FlowCapableNode>>any(), Mockito.eq(first)))
+ .thenAnswer(invocationOnMock -> {
+ LOG.info("unlocking next configs");
+ latchForNext.countDown();
+ latchForFirst.await();
+ LOG.info("unlocking first delegate");
+ return Futures.immediateFuture(Boolean.TRUE);
});
allResults.add(reactor.syncup(fcNodePath, first));
final SyncupEntry first = new SyncupEntry(dataBefore, configDS, null, configDS);
final SyncupEntry second = new SyncupEntry(dataAfter, configDS, dataBefore, configDS);
- Mockito.when(delegate.syncup(Matchers.<InstanceIdentifier<FlowCapableNode>>any(), Mockito.eq(first)))
- .thenAnswer(new Answer<ListenableFuture<Boolean>>() {
- @Override
- public ListenableFuture<Boolean> answer(final InvocationOnMock invocationOnMock) throws Throwable {
- LOG.info("unlocking next config");
- latchForNext.countDown();
- return Futures.immediateFuture(Boolean.TRUE);
- }
- });
+ Mockito.when(delegate.syncup(ArgumentMatchers.<InstanceIdentifier<FlowCapableNode>>any(), Mockito.eq(first)))
+ .thenAnswer(invocationOnMock -> {
+ LOG.info("unlocking next config");
+ latchForNext.countDown();
+ return Futures.immediateFuture(Boolean.TRUE);
+ });
reactor.syncup(fcNodePath, first);
latchForNext.await();
final SyncupEntry first = new SyncupEntry(configAfter, configDS, configBefore, configDS);
final SyncupEntry second = new SyncupEntry(configActual, configDS, freshOperational, operationalDS);
- Mockito.when(delegate.syncup(Matchers.<InstanceIdentifier<FlowCapableNode>>any(), Mockito.eq(first)))
- .thenAnswer(new Answer<ListenableFuture<Boolean>>() {
- @Override
- public ListenableFuture<Boolean> answer(final InvocationOnMock invocationOnMock) throws Throwable {
- LOG.info("unlocking for fresh operational");
- latchForNext.countDown();
- latchForFirst.await();
- LOG.info("unlocking first delegate");
- return Futures.immediateFuture(Boolean.TRUE);
- }
- });
+ Mockito.when(delegate.syncup(ArgumentMatchers.<InstanceIdentifier<FlowCapableNode>>any(), Mockito.eq(first)))
+ .thenAnswer(invocationOnMock -> {
+ LOG.info("unlocking for fresh operational");
+ latchForNext.countDown();
+ latchForFirst.await();
+ LOG.info("unlocking first delegate");
+ return Futures.immediateFuture(Boolean.TRUE);
+ });
reactor.syncup(fcNodePath, first);
latchForNext.await();
Mockito.verify(delegate, Mockito.times(1)).syncup(fcNodePath, second);
}
- private void mockSyncupWithEntry(final SyncupEntry entry) throws InterruptedException {
- Mockito.when(delegate.syncup(Matchers.<InstanceIdentifier<FlowCapableNode>>any(), Mockito.eq(entry)))
+ private void mockSyncupWithEntry(final SyncupEntry entry) {
+ Mockito.when(delegate.syncup(ArgumentMatchers.any(), Mockito.eq(entry)))
.thenReturn(Futures.immediateFuture(Boolean.TRUE));
}
public void tearDown() {
syncThreadPool.shutdownNow();
}
-}
\ No newline at end of file
+}