Convert to using requireNonNull()
[netconf.git] / restconf / restconf-nb-rfc8040 / src / test / java / org / opendaylight / restconf / nb / rfc8040 / streams / listeners / NotificationListenerTest.java
index 62434c8a16037d9d334c411f94e21a3dcbfb0c16..851dae944913938cc1668645d6fb8e364db8ae06 100644 (file)
@@ -7,24 +7,21 @@
  */
 package org.opendaylight.restconf.nb.rfc8040.streams.listeners;
 
+import static java.util.Objects.requireNonNull;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-import com.google.common.base.Preconditions;
 import com.google.common.collect.Lists;
 import java.net.URI;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
 import java.util.Optional;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.MockitoAnnotations;
-import org.opendaylight.controller.md.sal.dom.api.DOMNotification;
+import org.opendaylight.mdsal.dom.api.DOMNotification;
 import org.opendaylight.restconf.nb.rfc8040.TestUtils;
 import org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.NotificationOutputTypeGrouping.NotificationOutputType;
 import org.opendaylight.yangtools.util.SingletonSet;
@@ -174,9 +171,8 @@ public class NotificationListenerTest {
 
     private static MapEntryNode mockMapEntry(final QName entryQName, final LeafNode<String> leaf) {
         final MapEntryNode entry = mock(MapEntryNode.class);
-        final Map<QName, Object> keyValues = new HashMap<>();
-        keyValues.put(leaf.getNodeType(), "value");
-        final NodeIdentifierWithPredicates nodeId = new NodeIdentifierWithPredicates(leaf.getNodeType(), keyValues);
+        final NodeIdentifierWithPredicates nodeId = NodeIdentifierWithPredicates.of(leaf.getNodeType(),
+            leaf.getNodeType(), "value");
         when(entry.getIdentifier()).thenReturn(nodeId);
         when(entry.getChild(any())).thenReturn(Optional.of(leaf));
 
@@ -215,16 +211,9 @@ public class NotificationListenerTest {
         return child;
     }
 
-    private String prepareJson(final DOMNotification notificationData, final SchemaPath schemaPathNotifi)
-            throws Exception {
-        final List<SchemaPath> paths = new ArrayList<>();
-        paths.add(schemaPathNotifi);
-        final List<NotificationListenerAdapter> listNotifi =
-                Notificator.createNotificationListener(paths, "stream-name", NotificationOutputType.JSON.toString());
-        final NotificationListenerAdapter notifi = listNotifi.get(0);
-        notifi.setNotification(notificationData);
-        notifi.setSchemaContext(this.schmeaCtx);
-        final String result = notifi.prepareJson();
-        return Preconditions.checkNotNull(result);
+    private String prepareJson(final DOMNotification notificationData, final SchemaPath schemaPathNotifi) {
+        final NotificationListenerAdapter notifiAdapter = ListenersBroker.getInstance().registerNotificationListener(
+                schemaPathNotifi, "stream-name", NotificationOutputType.JSON);
+        return requireNonNull(notifiAdapter.prepareJson(schmeaCtx, notificationData));
     }
 }