MD-SAL API integration
[ovsdb.git] / southbound / southbound-impl / src / test / java / org / opendaylight / ovsdb / southbound / ovsdb / transact / ProtocolRemovedCommandTest.java
index b650fdc14b39d5b6cf1fada1bb30de8a4bed7b4b..17cfdfc47bc5d5ccf5aafbee0fa1ef0748ad54b9 100644 (file)
@@ -1,30 +1,27 @@
 /*
- * Copyright (c) 2015 Inocybe Technologies. and others.  All rights reserved.
+ * Copyright © 2015, 2017 Inocybe Technologies. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.ovsdb.southbound.ovsdb.transact;
 
-import static org.mockito.Matchers.any;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-import com.google.common.base.Optional;
 import java.lang.reflect.Field;
 import java.util.HashSet;
 import java.util.Map;
+import java.util.Optional;
 import java.util.Set;
 import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.Mockito;
-import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
 import org.opendaylight.ovsdb.lib.notation.Column;
 import org.opendaylight.ovsdb.lib.notation.Mutator;
 import org.opendaylight.ovsdb.lib.operations.Mutate;
@@ -32,10 +29,9 @@ import org.opendaylight.ovsdb.lib.operations.Operation;
 import org.opendaylight.ovsdb.lib.operations.Operations;
 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
 import org.opendaylight.ovsdb.lib.schema.ColumnSchema;
-import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
 import org.opendaylight.ovsdb.lib.schema.GenericTableSchema;
-import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
 import org.opendaylight.ovsdb.schema.openvswitch.Bridge;
+import org.opendaylight.ovsdb.southbound.InstanceIdentifierCodec;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeProtocolBase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeProtocolOpenflow10;
@@ -48,10 +44,10 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
 import org.powermock.modules.junit4.PowerMockRunner;
 
 @RunWith(PowerMockRunner.class)
-@PrepareForTest({InstanceIdentifier.class, TransactUtils.class, TyperUtils.class })
+@PrepareForTest({InstanceIdentifier.class, TransactUtils.class })
 public class ProtocolRemovedCommandTest {
 
-    private Set<InstanceIdentifier<ProtocolEntry>> removed = new HashSet<>();
+    private final Set<InstanceIdentifier<ProtocolEntry>> removed = new HashSet<>();
     @Mock private Map<InstanceIdentifier<OvsdbBridgeAugmentation>, OvsdbBridgeAugmentation> updatedBridges;
 
     @SuppressWarnings("unchecked")
@@ -61,12 +57,8 @@ public class ProtocolRemovedCommandTest {
         PowerMockito.suppress(MemberMatcher.methodsDeclaredIn(InstanceIdentifier.class));
 
         ProtocolEntry protocol = mock(ProtocolEntry.class);
-        when(protocol.getProtocol()).thenAnswer(new Answer<Class<? extends OvsdbBridgeProtocolBase>>() {
-            public Class<? extends OvsdbBridgeProtocolBase> answer(
-                    InvocationOnMock invocation) throws Exception {
-                return OvsdbBridgeProtocolOpenflow10.class;
-            }
-        });
+        when(protocol.getProtocol()).thenAnswer(
+                (Answer<Class<? extends OvsdbBridgeProtocolBase>>) invocation -> OvsdbBridgeProtocolOpenflow10.class);
 
         BridgeOperationalState bridgeOpState = mock(BridgeOperationalState.class);
         when(bridgeOpState.getProtocolEntry(any(InstanceIdentifier.class))).thenReturn(Optional.of(protocol));
@@ -86,18 +78,18 @@ public class ProtocolRemovedCommandTest {
         Bridge bridge = mock(Bridge.class);
         when(bridge.getProtocolsColumn()).thenReturn(column);
         when(column.getSchema()).thenReturn(mock(ColumnSchema.class));
-        when(column.getData()).thenReturn(new HashSet<String>());
+        when(column.getData()).thenReturn(new HashSet<>());
         when(mutate.addMutation(any(ColumnSchema.class), any(Mutator.class), any(Set.class))).thenReturn(mutate);
 
-        PowerMockito.mockStatic(TyperUtils.class);
-        when(TyperUtils.getTypedRowWrapper(any(DatabaseSchema.class), any(Class.class))).thenReturn(bridge);
-
         TransactionBuilder transaction = mock(TransactionBuilder.class);
-        protocolRemovedCommand.execute(transaction, bridgeOpState, mock(AsyncDataChangeEvent.class));
+        when(transaction.getTypedRowWrapper(any(Class.class))).thenReturn(bridge);
+
+        protocolRemovedCommand.execute(transaction, bridgeOpState, mock(DataChangeEvent.class),
+                mock(InstanceIdentifierCodec.class));
         Mockito.verify(transaction).add(any(Operation.class));
     }
 
-    private Object setField(String fieldName) throws Exception {
+    private Object setField(final String fieldName) throws Exception {
         Field field = Operations.class.getDeclaredField(fieldName);
         field.setAccessible(true);
         field.set(field.get(Operations.class), mock(Operations.class));