Migrate netconf-server/spi tests to JUnit5
[netconf.git] / protocol / netconf-server / src / test / java / org / opendaylight / netconf / server / spi / SubtreeFilterNotificationTest.java
index 560cd8e67725d4823c516469d71c14226e9a0447..b2d833eab9f58fe1b804cbef832487e0db5a4f43 100644 (file)
@@ -7,43 +7,25 @@
  */
 package org.opendaylight.netconf.server.spi;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
 
-import java.util.Collection;
-import java.util.List;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
+import java.util.stream.Stream;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
 import org.opendaylight.netconf.api.xml.XmlElement;
 import org.opendaylight.netconf.api.xml.XmlUtil;
 import org.w3c.dom.Document;
 import org.xmlunit.builder.DiffBuilder;
 
-@RunWith(value = Parameterized.class)
-public class SubtreeFilterNotificationTest {
-    private final int directoryIndex;
+class SubtreeFilterNotificationTest {
 
-    @Parameters
-    public static Collection<Object[]> data() {
-        return List.of(
-            new Object[] { 0 },
-            new Object[] { 1 },
-            new Object[] { 2 },
-            new Object[] { 3 },
-            new Object[] { 4 });
-    }
-
-    public SubtreeFilterNotificationTest(final int directoryIndex) {
-        this.directoryIndex = directoryIndex;
-    }
-
-    @Test
-    public void testFilterNotification() throws Exception {
-        final var filter = XmlElement.fromDomDocument(getDocument("filter.xml"));
-        final var preFilter = getDocument("pre-filter.xml");
-        final var expectedPostFilter = getDocument("post-filter.xml");
+    @MethodSource
+    @ParameterizedTest
+    void testFilterNotification(final int directoryIndex) throws Exception {
+        final var filter = XmlElement.fromDomDocument(getDocument(directoryIndex, "filter.xml"));
+        final var preFilter = getDocument(directoryIndex, "pre-filter.xml");
+        final var expectedPostFilter = getDocument(directoryIndex, "post-filter.xml");
         final var postFilterOpt = SubtreeFilter.applySubtreeNotificationFilter(filter, preFilter);
         if (postFilterOpt.isPresent()) {
             final var diff = DiffBuilder.compare(postFilterOpt.orElseThrow())
@@ -51,13 +33,17 @@ public class SubtreeFilterNotificationTest {
                 .ignoreWhitespace()
                 .checkForIdentical()
                 .build();
-            assertFalse(diff.toString(), diff.hasDifferences());
+            assertFalse(diff.hasDifferences(), diff.toString());
         } else {
             assertEquals("empty", XmlElement.fromDomDocument(expectedPostFilter).getName());
         }
     }
 
-    private Document getDocument(final String fileName) throws Exception {
+    private static Stream<Integer> testFilterNotification() {
+        return Stream.of(0, 1, 2, 3, 4);
+    }
+
+    private Document getDocument(final int directoryIndex, final String fileName) throws Exception {
         return XmlUtil.readXmlToDocument(SubtreeFilterNotificationTest.class.getResourceAsStream(
                 "/subtree/notification/" + directoryIndex + "/" + fileName));
     }