Rework PruningDataTreeModificationTest 37/87037/2
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 19 Jan 2020 10:20:08 +0000 (11:20 +0100)
committerRobert Varga <nite@hq.sk>
Sun, 19 Jan 2020 14:35:02 +0000 (14:35 +0000)
Eliminate the use of a dedicated constructor, ensure invariants
are shared across tests.

JIRA: CONTROLLER-1923
Change-Id: Ieaec8bafcb7c2f6bf4fe22815b1b14f84d396ef9
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/PruningDataTreeModification.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/PruningDataTreeModificationTest.java

index 3c326dc2df9d8ae702caee2650191f2af53c5f4f..f69a22e5b6e96fdb2c5f1a7d474280353b99a022 100644 (file)
@@ -47,11 +47,6 @@ public class PruningDataTreeModification extends ForwardingObject implements Dat
         this.pruner = requireNonNull(pruner);
     }
 
-    public PruningDataTreeModification(final DataTreeModification delegate, final DataTree dataTree,
-            final SchemaContext schemaContext) {
-        this(delegate, dataTree, ReusableNormalizedNodePruner.forSchemaContext(schemaContext));
-    }
-
     public PruningDataTreeModification(final DataTreeModification delegate, final DataTree dataTree,
             final DataSchemaContextTree dataSchemaContext) {
         this(delegate, dataTree, ReusableNormalizedNodePruner.forDataSchemaContext(dataSchemaContext));
index 73db5465b54f090745f43b1c0680c266918862ab..50179c706b1ffda9587990c95b5f5b8650e2a431 100644 (file)
@@ -5,7 +5,6 @@
  * 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.controller.cluster.datastore.utils;
 
 import static org.junit.Assert.assertEquals;
@@ -27,10 +26,12 @@ import com.google.common.reflect.Reflection;
 import java.lang.reflect.InvocationTargetException;
 import java.util.Optional;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnitRunner;
 import org.opendaylight.controller.cluster.datastore.Shard;
 import org.opendaylight.controller.cluster.datastore.ShardDataTree;
 import org.opendaylight.controller.md.cluster.datastore.model.CarsModel;
@@ -54,15 +55,17 @@ import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory;
 import org.opendaylight.yangtools.yang.data.impl.schema.tree.SchemaValidationFailedException;
+import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
+@RunWith(MockitoJUnitRunner.class)
 public class PruningDataTreeModificationTest {
-    static final SchemaContext SCHEMA_CONTEXT = SchemaContextHelper.select(SchemaContextHelper.CARS_YANG,
-            SchemaContextHelper.ODL_DATASTORE_TEST_YANG);
-
     static final QName INVALID_TEST_QNAME = QName.create(TestModel.TEST_QNAME, "invalid");
     static final YangInstanceIdentifier INVALID_TEST_PATH = YangInstanceIdentifier.of(INVALID_TEST_QNAME);
 
+    private static SchemaContext SCHEMA_CONTEXT;
+    private static DataSchemaContextTree CONTEXT_TREE;
+
     @Mock
     private DataTreeModification mockModification;
 
@@ -71,11 +74,16 @@ public class PruningDataTreeModificationTest {
     private DataTreeModification proxyModification;
     private PruningDataTreeModification pruningDataTreeModification;
 
+    @BeforeClass
+    public static void beforeClass() {
+        SCHEMA_CONTEXT = SchemaContextHelper.select(SchemaContextHelper.CARS_YANG,
+            SchemaContextHelper.ODL_DATASTORE_TEST_YANG);
+        CONTEXT_TREE = DataSchemaContextTree.from(SCHEMA_CONTEXT);
+    }
+
     @Before
     @SuppressWarnings("checkstyle:avoidHidingCauseException")
     public void setUp() {
-        MockitoAnnotations.initMocks(this);
-
         dataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_CONFIGURATION,
             SCHEMA_CONTEXT);
 
@@ -89,7 +97,7 @@ public class PruningDataTreeModificationTest {
             }
         });
 
-        pruningDataTreeModification = new PruningDataTreeModification(proxyModification, dataTree, SCHEMA_CONTEXT);
+        pruningDataTreeModification = new PruningDataTreeModification(proxyModification, dataTree, CONTEXT_TREE);
     }
 
     @Test