From: Jozef Bacigal Date: Fri, 8 Sep 2017 07:23:23 +0000 (+0200) Subject: Fix codestyle X-Git-Tag: release/oxygen~96^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=cd2ee9a2cc640746835fe585cf1a45b1d33b423f;p=openflowplugin.git Fix codestyle - Anonymous type replaced by lambda See also:Bug-8607 Change-Id: I7134315329b860d698927c6eb2c7f94a9476afde Signed-off-by: Jozef Bacigal --- diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/ItemLifeCycleRegistryImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/ItemLifeCycleRegistryImpl.java index c2cfda5b69..c1ca0e92bb 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/ItemLifeCycleRegistryImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/ItemLifeCycleRegistryImpl.java @@ -31,12 +31,7 @@ public class ItemLifeCycleRegistryImpl implements ItemLifeCycleRegistry { public Registration registerLifeCycleSource(final ItemLifeCycleSource lifeCycleSource) { registry.add(lifeCycleSource); - return new Registration() { - @Override - public void close() throws Exception { - registry.remove(lifeCycleSource); - } - }; + return () -> registry.remove(lifeCycleSource); } @Override diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/deserialization/ActionDeserializerInjector.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/deserialization/ActionDeserializerInjector.java index 69156c7170..f749210d1f 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/deserialization/ActionDeserializerInjector.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/deserialization/ActionDeserializerInjector.java @@ -73,15 +73,12 @@ class ActionDeserializerInjector { * @param version Openflow version * @return injector */ - @VisibleForTesting - static Function>> createInjector( + private static Function>> createInjector( final DeserializerExtensionProvider provider, final short version) { - return code -> deserializer -> { - provider.registerDeserializer( - new MessageCodeExperimenterKey(version, code, Action.class, null), - deserializer); - }; + return code -> deserializer -> provider.registerDeserializer( + new MessageCodeExperimenterKey(version, code, Action.class, null), + deserializer); } } diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/deserialization/InstructionDeserializerInjector.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/deserialization/InstructionDeserializerInjector.java index 27eb207c23..ac3f1e8acf 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/deserialization/InstructionDeserializerInjector.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/deserialization/InstructionDeserializerInjector.java @@ -63,16 +63,17 @@ class InstructionDeserializerInjector { * @param version Openflow version * @return injector */ - @VisibleForTesting - static Function>>> createInjector( + private static Function>>> createInjector( final DeserializerExtensionProvider provider, final short version) { - return code -> actionPath -> deserializer -> { - provider.registerDeserializer((Objects.nonNull(actionPath) - ? new MessageCodeActionExperimenterKey(version, code, Instruction.class, actionPath, null) - : new MessageCodeExperimenterKey(version, code, Instruction.class, null)), - deserializer); - }; + return code -> actionPath -> deserializer -> provider.registerDeserializer((Objects.nonNull(actionPath) + ? new MessageCodeActionExperimenterKey(version, + code, + Instruction.class, + actionPath, + null) + : new MessageCodeExperimenterKey(version, code, Instruction.class, null)), + deserializer); } } diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/deserialization/MultipartDeserializerInjector.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/deserialization/MultipartDeserializerInjector.java index a2b47a9aa8..6fb61b5a85 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/deserialization/MultipartDeserializerInjector.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/deserialization/MultipartDeserializerInjector.java @@ -78,15 +78,12 @@ class MultipartDeserializerInjector { * @param version Openflow version * @return injector */ - @VisibleForTesting - static Function>> createInjector( + private static Function>> createInjector( final DeserializerExtensionProvider provider, final short version) { - return code -> deserializer -> { - provider.registerDeserializer( - new MessageCodeKey(version, code, MultipartReplyBody.class), - deserializer); - }; + return code -> deserializer -> provider.registerDeserializer( + new MessageCodeKey(version, code, MultipartReplyBody.class), + deserializer); } } diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalGroupsBatchServiceImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalGroupsBatchServiceImpl.java index e84f69c755..d8057a3882 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalGroupsBatchServiceImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalGroupsBatchServiceImpl.java @@ -17,6 +17,7 @@ import com.google.common.util.concurrent.ListenableFuture; import java.util.ArrayList; import java.util.List; import java.util.concurrent.Future; +import java.util.stream.Collectors; import javax.annotation.Nullable; import org.opendaylight.openflowplugin.impl.util.BarrierUtil; import org.opendaylight.openflowplugin.impl.util.GroupUtil; @@ -38,6 +39,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupRef; import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.AddGroupsBatchInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.AddGroupsBatchOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.BatchGroupInputUpdateGrouping; import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.RemoveGroupsBatchInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.RemoveGroupsBatchOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.SalGroupsBatchService; @@ -86,14 +88,9 @@ public class SalGroupsBatchServiceImpl implements SalGroupsBatchService { resultsLot.add(JdkFutureAdapters.listenInPoolThread(salGroupService.updateGroup(updateGroupInput))); } - final Iterable groups = Iterables.transform(batchUpdateGroups, new Function() { - @Nullable - @Override - public Group apply(@Nullable final BatchUpdateGroups input) { - return input.getUpdatedBatchedGroup(); - } - } - ); + final Iterable groups = batchUpdateGroups.stream() + .map(BatchGroupInputUpdateGrouping::getUpdatedBatchedGroup) + .collect(Collectors.toList()); final ListenableFuture>> commonResult = Futures.transform(Futures.allAsList(resultsLot), GroupUtil.createCumulatingFunction( diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalMetersBatchServiceImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalMetersBatchServiceImpl.java index ea0361423d..981640fb0a 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalMetersBatchServiceImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalMetersBatchServiceImpl.java @@ -17,6 +17,7 @@ import com.google.common.util.concurrent.ListenableFuture; import java.util.ArrayList; import java.util.List; import java.util.concurrent.Future; +import java.util.stream.Collectors; import javax.annotation.Nullable; import org.opendaylight.openflowplugin.impl.util.BarrierUtil; import org.opendaylight.openflowplugin.impl.util.MeterUtil; @@ -40,6 +41,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.Meter import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterRef; import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.AddMetersBatchInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.AddMetersBatchOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.BatchMeterInputUpdateGrouping; import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.RemoveMetersBatchInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.RemoveMetersBatchOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.SalMetersBatchService; @@ -86,14 +88,9 @@ public class SalMetersBatchServiceImpl implements SalMetersBatchService { resultsLot.add(JdkFutureAdapters.listenInPoolThread(salMeterService.updateMeter(updateMeterInput))); } - final Iterable meters = Iterables.transform(batchUpdateMeters, new Function() { - @Nullable - @Override - public Meter apply(@Nullable final BatchUpdateMeters input) { - return input.getUpdatedBatchedMeter(); - } - } - ); + final Iterable meters = batchUpdateMeters.stream() + .map(BatchMeterInputUpdateGrouping::getUpdatedBatchedMeter) + .collect(Collectors.toList()); final ListenableFuture>> commonResult = Futures.transform(Futures.allAsList(resultsLot), MeterUtil.createCumulativeFunction( diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/ofpspecific/EventsTimeCounter.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/ofpspecific/EventsTimeCounter.java index 2e0f9b8669..6b5ea80e99 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/ofpspecific/EventsTimeCounter.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/ofpspecific/EventsTimeCounter.java @@ -37,22 +37,11 @@ public final class EventsTimeCounter { private static EventTimeCounter getOrCreateEventOfType(final String event, final Map deviceEvents) { - EventTimeCounter lookup = deviceEvents.get(event); - if (null == lookup) { - lookup = new EventTimeCounter(); - deviceEvents.put(event, lookup); - } - return lookup; + return deviceEvents.computeIfAbsent(event, k -> new EventTimeCounter()); } private static Map getOrCreateCountersForDevice(final String deviceId) { - Map lookup = DEVICES_EVENTS.get(deviceId); - if (null == lookup) { - lookup = new HashMap<>(); - DEVICES_EVENTS.put(deviceId, lookup); - } - - return lookup; + return DEVICES_EVENTS.computeIfAbsent(deviceId, k -> new HashMap<>()); } public static List provideTimes() { diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/ofpspecific/SessionStatistics.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/ofpspecific/SessionStatistics.java index 0e2aa3a734..b0d8c68c1e 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/ofpspecific/SessionStatistics.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/ofpspecific/SessionStatistics.java @@ -26,21 +26,11 @@ public class SessionStatistics { private static EventCounter getConnectionEvent(final Map sessionsConnectionEvents, final ConnectionStatus connectionStatus) { - EventCounter eventCounter = sessionsConnectionEvents.get(connectionStatus); - if (null == eventCounter) { - eventCounter = new EventCounter(); - sessionsConnectionEvents.put(connectionStatus, eventCounter); - } - return eventCounter; + return sessionsConnectionEvents.computeIfAbsent(connectionStatus, k -> new EventCounter()); } private static Map getConnectionEvents(final String sessionId) { - Map sessionConnectionEvents = SESSION_EVENTS.get(sessionId); - if (null == sessionConnectionEvents) { - sessionConnectionEvents = new HashMap<>(); - SESSION_EVENTS.put(sessionId, sessionConnectionEvents); - } - return sessionConnectionEvents; + return SESSION_EVENTS.computeIfAbsent(sessionId, k -> new HashMap<>()); } diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/util/BarrierUtil.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/util/BarrierUtil.java index 14a7455850..500dd413a2 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/util/BarrierUtil.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/util/BarrierUtil.java @@ -52,14 +52,10 @@ public final class BarrierUtil { // store input result and append barrier final ListenableFuture> barrierResult = Futures.transformAsync(input, - new AsyncFunction, RpcResult>() { - @Override - public ListenableFuture> apply(@Nullable final RpcResult interInput) - throws Exception { - resultPair.setLeft(interInput); - final SendBarrierInput barrierInput = createSendBarrierInput(nodeRef); - return JdkFutureAdapters.listenInPoolThread(transactionService.sendBarrier(barrierInput)); - } + interInput -> { + resultPair.setLeft(interInput); + final SendBarrierInput barrierInput = createSendBarrierInput(nodeRef); + return JdkFutureAdapters.listenInPoolThread(transactionService.sendBarrier(barrierInput)); }); // store barrier result and return initiated pair final ListenableFuture, RpcResult>> compositeResult = Futures.transform( diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/connection/listener/HandshakeListenerImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/connection/listener/HandshakeListenerImplTest.java index d2ad7ff607..9dede809be 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/connection/listener/HandshakeListenerImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/connection/listener/HandshakeListenerImplTest.java @@ -40,8 +40,6 @@ import org.opendaylight.yangtools.yang.common.RpcResultBuilder; @RunWith(MockitoJUnitRunner.class) public class HandshakeListenerImplTest { - private final Short version = OFConstants.OFP_VERSION_1_3; - @Mock private DeviceConnectedHandler deviceConnectedHandler; @Mock @@ -74,7 +72,7 @@ public class HandshakeListenerImplTest { @Test public void testOnHandshakeSuccessfull() throws Exception { - handshakeListener.onHandshakeSuccessful(features, version); + handshakeListener.onHandshakeSuccessful(features, OFConstants.OFP_VERSION_1_3); Mockito.verify(connectionContextSpy).changeStateToWorking(); Mockito.verify(connectionContextSpy).setFeatures(Matchers.any(FeaturesReply.class)); Mockito.verify(connectionContextSpy).setNodeId(nodeIdCaptor.capture()); diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/listener/MultiMsgCollectorImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/listener/MultiMsgCollectorImplTest.java index 3793265459..bbcc77f162 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/listener/MultiMsgCollectorImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/listener/MultiMsgCollectorImplTest.java @@ -145,13 +145,10 @@ public class MultiMsgCollectorImplTest { Mockito.reset(deviceProcessor); - cleanUpCheck = new Runnable() { - @Override - public void run() { - Mockito.verify(deviceProcessor, VerificationModeFactory.noMoreInteractions()) - .processReply(xidCaptor.capture(), mmCaptor.capture()); - Assert.assertEquals(xid, xidCaptor.getValue().getValue()); - } + cleanUpCheck = () -> { + Mockito.verify(deviceProcessor, VerificationModeFactory.noMoreInteractions()) + .processReply(xidCaptor.capture(), mmCaptor.capture()); + Assert.assertEquals(xid, xidCaptor.getValue().getValue()); }; } @@ -174,13 +171,10 @@ public class MultiMsgCollectorImplTest { Mockito.reset(deviceProcessor); - cleanUpCheck = new Runnable() { - @Override - public void run() { - Mockito.verify(deviceProcessor, VerificationModeFactory.noMoreInteractions()) - .processReply(xidCaptor.capture(), mmCaptor.capture()); - Assert.assertEquals(xid, xidCaptor.getValue().getValue()); - } + cleanUpCheck = () -> { + Mockito.verify(deviceProcessor, VerificationModeFactory.noMoreInteractions()) + .processReply(xidCaptor.capture(), mmCaptor.capture()); + Assert.assertEquals(xid, xidCaptor.getValue().getValue()); }; } diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/NextTableMissTablePropertySerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/NextTableMissTablePropertySerializerTest.java index afd5b86bd3..84bcfb5f9d 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/NextTableMissTablePropertySerializerTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/NextTableMissTablePropertySerializerTest.java @@ -29,9 +29,7 @@ public class NextTableMissTablePropertySerializerTest extends AbstractTablePrope .build()) .build(); - assertProperty(property, out -> { - assertEquals(out.readUnsignedByte(), tableId); - }); + assertProperty(property, out -> assertEquals(out.readUnsignedByte(), tableId)); } @Override diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/NextTableTablePropertySerializerTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/NextTableTablePropertySerializerTest.java index 098569c482..c6445794cf 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/NextTableTablePropertySerializerTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/multipart/tablefeatures/NextTableTablePropertySerializerTest.java @@ -29,9 +29,7 @@ public class NextTableTablePropertySerializerTest extends AbstractTablePropertyS .build()) .build(); - assertProperty(property, out -> { - assertEquals(out.readUnsignedByte(), tableId); - }); + assertProperty(property, out -> assertEquals(out.readUnsignedByte(), tableId)); } @Override diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/rpc/RpcContextImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/rpc/RpcContextImplTest.java index 1c591d910f..5bd6e67630 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/rpc/RpcContextImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/rpc/RpcContextImplTest.java @@ -56,7 +56,6 @@ public class RpcContextImplTest { @Mock private BindingAwareBroker.RoutedRpcRegistration routedRpcReg; - private Class serviceClass; @Mock private NotificationPublishService notificationPublishService; @Mock @@ -154,7 +153,7 @@ public class RpcContextImplTest { @Test public void testClose() { - serviceClass = TestRpcService.class; + Class serviceClass = TestRpcService.class; when(routedRpcReg.getServiceType()).thenReturn(serviceClass); rpcContext.registerRpcServiceImplementation(TestRpcService.class, serviceInstance); rpcContext.close(); diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalRoleServiceImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalRoleServiceImplTest.java index 1209558252..91e3eb8063 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalRoleServiceImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalRoleServiceImplTest.java @@ -82,8 +82,6 @@ public class SalRoleServiceImplTest { private NodeId testNodeId = new NodeId(Uri.getDefaultInstance("openflow:1")); - private static short testVersion = 4; - private static long testXid = 100L; private static final String ROLEREQUESTFAILED = org.opendaylight.yang.gen.v1.urn @@ -98,6 +96,7 @@ public class SalRoleServiceImplTest { MockitoAnnotations.initMocks(this); Mockito.when(mockDeviceInfo.getNodeId()).thenReturn(testNodeId); Mockito.when(mockDeviceInfo.getDatapathId()).thenReturn(BigInteger.TEN); + short testVersion = 4; Mockito.when(mockFeaturesOutput.getVersion()).thenReturn(testVersion); Mockito.when(mockDeviceContext.getDeviceState()).thenReturn(mockDeviceState); Mockito.when(mockDeviceContext.getDeviceInfo()).thenReturn(mockDeviceInfo); diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalTableServiceImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalTableServiceImplTest.java index 9563c89cba..50a495dee3 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalTableServiceImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalTableServiceImplTest.java @@ -57,13 +57,10 @@ public class SalTableServiceImplTest extends ServiceMocking { public void setup() { handleResultFuture = SettableFuture.create(); when(mockedRequestContext.getFuture()).thenReturn(handleResultFuture); - Mockito.doAnswer(new Answer() { - @Override - public Void answer(InvocationOnMock invocation) throws Throwable { - final FutureCallback callback = (FutureCallback) invocation.getArguments()[2]; - callback.onSuccess(null); - return null; - } + Mockito.doAnswer((Answer) invocation -> { + final FutureCallback callback = (FutureCallback) invocation.getArguments()[2]; + callback.onSuccess(null); + return null; }) .when(mockedOutboundQueue).commitEntry( Matchers.anyLong(), Matchers.any(), Matchers.>any()); @@ -75,14 +72,11 @@ public class SalTableServiceImplTest extends ServiceMocking { @Test public void testUpdateTableFail1() throws ExecutionException, InterruptedException { - Mockito.doAnswer(new Answer() { - @Override - public Void answer(InvocationOnMock invocation) throws Throwable { - final RpcResult> rpcResult = - RpcResultBuilder.>failed().build(); - handleResultFuture.set(rpcResult); - return null; - } + Mockito.doAnswer((Answer) invocation -> { + final RpcResult> rpcResult = + RpcResultBuilder.>failed().build(); + handleResultFuture.set(rpcResult); + return null; }).when(multiMessageCollector).endCollecting(Matchers.any()); final Future> rpcResultFuture = salTableService.updateTable(prepareUpdateTable()); @@ -92,15 +86,12 @@ public class SalTableServiceImplTest extends ServiceMocking { @Test public void testUpdateTableFail2() throws ExecutionException, InterruptedException { - Mockito.doAnswer(new Answer() { - @Override - public Void answer(InvocationOnMock invocation) throws Throwable { - final RpcResult> rpcResult = - RpcResultBuilder.success(Collections.emptyList()) - .build(); - handleResultFuture.set(rpcResult); - return null; - } + Mockito.doAnswer((Answer) invocation -> { + final RpcResult> rpcResult = + RpcResultBuilder.success(Collections.emptyList()) + .build(); + handleResultFuture.set(rpcResult); + return null; }).when(multiMessageCollector).endCollecting(Matchers.any()); final Future> rpcResultFuture = salTableService.updateTable(prepareUpdateTable()); @@ -110,28 +101,25 @@ public class SalTableServiceImplTest extends ServiceMocking { @Test public void testUpdateTableSuccess() throws ExecutionException, InterruptedException { - Mockito.doAnswer(new Answer() { - @Override - public Void answer(InvocationOnMock invocation) throws Throwable { - TableFeaturesBuilder tableFeaturesBld = new TableFeaturesBuilder() - .setTableId((short) 0) - .setName("Zafod") - .setMaxEntries(42L) - .setTableFeatureProperties(Collections.emptyList()); - MultipartReplyTableFeaturesBuilder mpTableFeaturesBld = new MultipartReplyTableFeaturesBuilder() - .setTableFeatures(Collections.singletonList(tableFeaturesBld.build())); - MultipartReplyTableFeaturesCaseBuilder mpBodyBld = new MultipartReplyTableFeaturesCaseBuilder() - .setMultipartReplyTableFeatures(mpTableFeaturesBld.build()); - MultipartReplyMessageBuilder mpResultBld = new MultipartReplyMessageBuilder() - .setType(MultipartType.OFPMPTABLEFEATURES) - .setMultipartReplyBody(mpBodyBld.build()) - .setXid(21L); - final RpcResult> rpcResult = RpcResultBuilder - .success(Collections.singletonList((MultipartReply) mpResultBld.build())) - .build(); - handleResultFuture.set(rpcResult); - return null; - } + Mockito.doAnswer((Answer) invocation -> { + TableFeaturesBuilder tableFeaturesBld = new TableFeaturesBuilder() + .setTableId((short) 0) + .setName("Zafod") + .setMaxEntries(42L) + .setTableFeatureProperties(Collections.emptyList()); + MultipartReplyTableFeaturesBuilder mpTableFeaturesBld = new MultipartReplyTableFeaturesBuilder() + .setTableFeatures(Collections.singletonList(tableFeaturesBld.build())); + MultipartReplyTableFeaturesCaseBuilder mpBodyBld = new MultipartReplyTableFeaturesCaseBuilder() + .setMultipartReplyTableFeatures(mpTableFeaturesBld.build()); + MultipartReplyMessageBuilder mpResultBld = new MultipartReplyMessageBuilder() + .setType(MultipartType.OFPMPTABLEFEATURES) + .setMultipartReplyBody(mpBodyBld.build()) + .setXid(21L); + final RpcResult> rpcResult = RpcResultBuilder + .success(Collections.singletonList((MultipartReply) mpResultBld.build())) + .build(); + handleResultFuture.set(rpcResult); + return null; }).when(multiMessageCollector).endCollecting(Matchers.any()); final Future> rpcResultFuture = salTableService.updateTable(prepareUpdateTable()); diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/AbstractSingleStatsServiceTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/AbstractSingleStatsServiceTest.java index 0a7e621fbb..aa2a7d17d5 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/AbstractSingleStatsServiceTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/AbstractSingleStatsServiceTest.java @@ -37,13 +37,10 @@ public abstract class AbstractSingleStatsServiceTest extends AbstractStatsServic //NOOP } }; - final Answer closeRequestFutureAnswer = new Answer() { - @Override - public Void answer(InvocationOnMock invocation) throws Throwable { - rqContext.setResult(rpcResult); - rqContext.close(); - return null; - } + final Answer closeRequestFutureAnswer = invocation -> { + rqContext.setResult(rpcResult); + rqContext.close(); + return null; }; Mockito.when(rqContextStack.createRequestContext()).thenReturn(rqContext); diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/AbstractStatsServiceTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/AbstractStatsServiceTest.java index 60feae5fa6..60a64d39f8 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/AbstractStatsServiceTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/AbstractStatsServiceTest.java @@ -70,13 +70,10 @@ public abstract class AbstractStatsServiceTest { public static final NodeId NODE_ID = new NodeId("unit-test-node:123"); - protected final Answer answerVoidToCallback = new Answer() { - @Override - public Void answer(InvocationOnMock invocation) throws Throwable { - final FutureCallback callback = (FutureCallback) (invocation.getArguments()[2]); - callback.onSuccess(null); - return null; - } + protected final Answer answerVoidToCallback = invocation -> { + final FutureCallback callback = (FutureCallback) (invocation.getArguments()[2]); + callback.onSuccess(null); + return null; }; @Before diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightFlowStatisticsServiceImpl1Test.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightFlowStatisticsServiceImpl1Test.java index b03c2a5ebe..39e9cccab8 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightFlowStatisticsServiceImpl1Test.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightFlowStatisticsServiceImpl1Test.java @@ -33,8 +33,6 @@ public class OpendaylightFlowStatisticsServiceImpl1Test extends AbstractStatsSer @Captor private ArgumentCaptor requestInput; - private AbstractRequestContext rqContext; - private OpendaylightFlowStatisticsServiceImpl flowStatisticsService; public void setUp() { @@ -42,7 +40,7 @@ public class OpendaylightFlowStatisticsServiceImpl1Test extends AbstractStatsSer flowStatisticsService = OpendaylightFlowStatisticsServiceImpl.createWithOook(rqContextStack, deviceContext, convertorManager); - rqContext = new AbstractRequestContext(42L) { + AbstractRequestContext rqContext = new AbstractRequestContext(42L) { @Override public void close() { //NOOP diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightFlowStatisticsServiceImpl2Test.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightFlowStatisticsServiceImpl2Test.java index 1ca253f541..50fdfc0989 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightFlowStatisticsServiceImpl2Test.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightFlowStatisticsServiceImpl2Test.java @@ -76,17 +76,14 @@ public class OpendaylightFlowStatisticsServiceImpl2Test extends AbstractStatsSer public void testGetAggregateFlowStatisticsFromFlowTableForGivenMatch() throws Exception { Mockito.doAnswer(answerVoidToCallback).when(outboundQueueProvider) .commitEntry(Matchers.eq(42L), requestInput.capture(), Matchers.any(FutureCallback.class)); - Mockito.doAnswer(new Answer() { - @Override - public Void answer(InvocationOnMock invocation) throws Throwable { - final MultipartReplyMessageBuilder messageBuilder = new MultipartReplyMessageBuilder() - .setVersion(OFConstants.OFP_VERSION_1_3); + Mockito.doAnswer((Answer) invocation -> { + final MultipartReplyMessageBuilder messageBuilder = new MultipartReplyMessageBuilder() + .setVersion(OFConstants.OFP_VERSION_1_3); - rqContextMp.setResult(RpcResultBuilder - .success(Collections.singletonList(messageBuilder.build())) - .build()); - return null; - } + rqContextMp.setResult(RpcResultBuilder + .success(Collections.singletonList(messageBuilder.build())) + .build()); + return null; }).when(multiMsgCollector).endCollecting(Matchers.any(EventIdentifier.class)); Mockito.when(translator.translate( Matchers.any(MultipartReply.class), Matchers.same(deviceInfo), Matchers.isNull()) diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/AbstractCompatibleStatServiceTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/AbstractCompatibleStatServiceTest.java index 80e5bac38d..5055d5a9f7 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/AbstractCompatibleStatServiceTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/AbstractCompatibleStatServiceTest.java @@ -86,13 +86,10 @@ public class AbstractCompatibleStatServiceTest extends AbstractStatsServiceTest //NOOP } }; - final Answer closeRequestFutureAnswer = new Answer() { - @Override - public Void answer(InvocationOnMock invocation) throws Throwable { - rqContext.setResult(rpcResult); - rqContext.close(); - return null; - } + final Answer closeRequestFutureAnswer = invocation -> { + rqContext.setResult(rpcResult); + rqContext.close(); + return null; }; Mockito.when(featuresOutput.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3); diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/translator/FlowRemovedTranslatorTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/translator/FlowRemovedTranslatorTest.java index 9dfa372f90..0d9ac34753 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/translator/FlowRemovedTranslatorTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/translator/FlowRemovedTranslatorTest.java @@ -64,11 +64,9 @@ public class FlowRemovedTranslatorTest { @Mock private FlowWildcardsV10 flowWildcards; - private KeyedInstanceIdentifier nodeId; - @Before public void setUp() throws Exception { - nodeId = InstanceIdentifier.create(Nodes.class) + KeyedInstanceIdentifier nodeId = InstanceIdentifier.create(Nodes.class) .child(Node.class, new NodeKey(new NodeId("dummyNodeId"))); final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager();