Do not use ListenerRegistration in mdsal-binding-api 54/109254/3
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 9 Dec 2023 12:24:47 +0000 (13:24 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sat, 9 Dec 2023 15:57:34 +0000 (16:57 +0100)
We have a few direct uses of ListenerRegistration. Convert them to use a
plain Registration instead.

JIRA: MDSAL-843
Change-Id: I1946d4ad17854894617931aa4979c74098d61e6c
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
12 files changed:
binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/DataTreeChangeService.java
binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/MountPointService.java
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/BindingDOMDataBrokerAdapter.java
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/BindingDOMDataTreeChangeServiceAdapter.java
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/BindingDOMMountPointListenerAdapter.java
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/BindingDOMMountPointServiceAdapter.java
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/BindingDataTreeChangeListenerRegistration.java [deleted file]
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/osgi/OSGiDataBroker.java
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/osgi/OSGiMountPointService.java
binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/BindingDOMMountPointListenerAdapterTest.java
binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/Bug4513Test.java
binding/mdsal-binding-spi/src/main/java/org/opendaylight/mdsal/binding/spi/ForwardingDataBroker.java

index 7803e8787677b6929357d36cb2b7ce3366badea0..cbc1c245e9f3e9fbc474ac2a8593fa3ac4e324c9 100644 (file)
@@ -8,55 +8,45 @@
 package org.opendaylight.mdsal.binding.api;
 
 import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
 /**
  * A {@link BindingService} which allows users to register for changes to a subtree.
  */
 public interface DataTreeChangeService extends BindingService {
     /**
-     * Registers a {@link DataTreeChangeListener} to receive
-     * notifications when data changes under a given path in the conceptual data
-     * tree.
+     * Registers a {@link DataTreeChangeListener} to receive notifications when data changes under a given path in the
+     * conceptual data tree.
      *
      * <p>
-     * You are able to register for notifications  for any node or subtree
-     * which can be represented using {@link DataTreeIdentifier}.
+     * You are able to register for notifications  for any node or subtree which can be represented using
+     * {@link DataTreeIdentifier}.
      *
      * <p>
-     * You are able to register for data change notifications for a subtree or leaf
-     * even if it does not exist. You will receive notification once that node is
-     * created.
+     * You are able to register for data change notifications for a subtree or leaf even if it does not exist. You will
+     * receive notification once that node is created.
      *
      * <p>
-     * If there is any pre-existing data in the data tree for the path for which you are
-     * registering, you will receive an initial data change event, which will
-     * contain all pre-existing data, marked as created.
+     * If there is any pre-existing data in the data tree for the path for which you are registering, you will receive
+     * an initial data change event, which will contain all pre-existing data, marked as created.
      *
      * <p>
-     * This method returns a {@link ListenerRegistration} object. To
-     * "unregister" your listener for changes call the {@link ListenerRegistration#close()}
-     * method on the returned object.
+     * This method returns a {@link Registration} object. To "unregister" your listener for changes call the
+     * {@link Registration#close()} method on the returned object.
      *
      * <p>
      * You MUST explicitly unregister your listener when you no longer want to receive
      * notifications. This is especially true in OSGi environments, where failure to
      * do so during bundle shutdown can lead to stale listeners being still registered.
      *
-     * @param treeId
-     *            Data tree identifier of the subtree which should be watched for
-     *            changes.
-     * @param listener
-     *            Listener instance which is being registered
-     * @return Listener registration object, which may be used to unregister
-     *         your listener using {@link ListenerRegistration#close()} to stop
-     *         delivery of change events.
+     * @param treeId Data tree identifier of the subtree which should be watched for changes
+     * @param listener Listener instance which is being registered
+     * @return a Registration object, which may be used to unregister your listener using {@link Registration#close()}
+     *         to stop delivery of change events.
      */
-    <T extends DataObject, L extends DataTreeChangeListener<T>> @NonNull ListenerRegistration<L>
-            registerDataTreeChangeListener(@NonNull DataTreeIdentifier<T> treeId, @NonNull L listener);
+    <T extends DataObject> @NonNull Registration registerDataTreeChangeListener(@NonNull DataTreeIdentifier<T> treeId,
+        @NonNull DataTreeChangeListener<T> listener);
 
     /**
      * Registers a {@link DataTreeChangeListener} to receive
@@ -128,7 +118,7 @@ public interface DataTreeChangeService extends BindingService {
 
     private static <T extends DataObject> @NonNull DataTreeIdentifier<T> checkNotWildcard(
             final DataTreeIdentifier<T> treeId) {
-        final @NonNull InstanceIdentifier<T> instanceIdentifier = treeId.getRootIdentifier();
+        final var instanceIdentifier = treeId.getRootIdentifier();
         if (instanceIdentifier.isWildcarded()) {
             throw new IllegalArgumentException("Cannot register listener for wildcard " + instanceIdentifier);
         }
index e5752124f95a66509412b2c58c3444f25aaebb35..09e9999c8fbd9291ce4fa8e00084b25be1960d56 100644 (file)
@@ -7,21 +7,21 @@
  */
 package org.opendaylight.mdsal.binding.api;
 
-import java.util.EventListener;
 import java.util.Optional;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
 public interface MountPointService extends BindingService {
 
     Optional<MountPoint> getMountPoint(InstanceIdentifier<?> mountPoint);
 
-    <T extends MountPointListener> ListenerRegistration<T> registerListener(InstanceIdentifier<?> path, T listener);
+    @NonNull Registration registerListener(InstanceIdentifier<?> path, MountPointListener listener);
 
-    interface MountPointListener extends EventListener {
+    interface MountPointListener {
 
-        void onMountPointCreated(InstanceIdentifier<?> path);
+        void onMountPointCreated(@NonNull InstanceIdentifier<?> path);
 
-        void onMountPointRemoved(InstanceIdentifier<?> path);
+        void onMountPointRemoved(@NonNull InstanceIdentifier<?> path);
     }
 }
index 0a9cc5ea81e015080a6a6951eee701ada11fed70..edcd2491e9c37ae5db0e55c1b6935d1a1bcce081 100644 (file)
@@ -25,7 +25,7 @@ import org.opendaylight.mdsal.binding.dom.adapter.BindingDOMAdapterBuilder.Facto
 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService;
 import org.opendaylight.mdsal.dom.api.DOMService;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 
 /**
@@ -75,6 +75,15 @@ public class BindingDOMDataBrokerAdapter extends AbstractBindingAdapter<@NonNull
             listener);
     }
 
+    @Override
+    public <T extends DataObject> Registration registerDataTreeChangeListener(final DataTreeIdentifier<T> treeId,
+            final DataTreeChangeListener<T> listener) {
+        if (treeChangeService == null) {
+            throw new UnsupportedOperationException("Underlying data broker does not expose DOMDataTreeChangeService.");
+        }
+        return treeChangeService.registerDataTreeChangeListener(treeId, listener);
+    }
+
     private static class Builder extends BindingDOMAdapterBuilder<DataBroker> {
         Builder(final AdapterContext adapterContext) {
             super(adapterContext);
@@ -91,13 +100,4 @@ public class BindingDOMDataBrokerAdapter extends AbstractBindingAdapter<@NonNull
         }
     }
 
-    @Override
-    public <T extends DataObject, L extends DataTreeChangeListener<T>>
-            ListenerRegistration<L> registerDataTreeChangeListener(final DataTreeIdentifier<T> treeId,
-                final L listener) {
-        if (treeChangeService == null) {
-            throw new UnsupportedOperationException("Underlying data broker does not expose DOMDataTreeChangeService.");
-        }
-        return treeChangeService.registerDataTreeChangeListener(treeId, listener);
-    }
 }
index fb2c78148d4d136823355ab9fbec6bd949a27642..42d5fd59b29a4983c35c1f374936b04519f22034 100644 (file)
@@ -16,7 +16,6 @@ import org.opendaylight.mdsal.binding.api.DataTreeChangeService;
 import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.binding.Augmentation;
 import org.opendaylight.yangtools.yang.binding.DataObject;
@@ -36,8 +35,8 @@ final class BindingDOMDataTreeChangeServiceAdapter extends AbstractBindingAdapte
     }
 
     @Override
-    public <T extends DataObject, L extends DataTreeChangeListener<T>> ListenerRegistration<L>
-            registerDataTreeChangeListener(final DataTreeIdentifier<T> treeId, final L listener) {
+    public <T extends DataObject> Registration registerDataTreeChangeListener(final DataTreeIdentifier<T> treeId,
+            final DataTreeChangeListener<T> listener) {
         final var domIdentifier = toDomTreeIdentifier(treeId);
         final var storeType = treeId.getDatastoreType();
         final var target = treeId.getRootIdentifier().getTargetType();
@@ -48,8 +47,7 @@ final class BindingDOMDataTreeChangeServiceAdapter extends AbstractBindingAdapte
                 (ClusteredDataTreeChangeListener<T>) listener, storeType, augment)
                 : new BindingDOMDataTreeChangeListenerAdapter<>(adapterContext(), listener, storeType, augment);
 
-        final var domReg = getDelegate().registerDataTreeChangeListener(domIdentifier, domListener);
-        return new BindingDataTreeChangeListenerRegistration<>(listener, domReg);
+        return getDelegate().registerDataTreeChangeListener(domIdentifier, domListener);
     }
 
     @Override
index 86085fcba75e54e3accd89bc9f8875218bf30a9b..0744517727f948539c79c7e09bc76294441cc7a7 100644 (file)
@@ -9,11 +9,11 @@ package org.opendaylight.mdsal.binding.dom.adapter;
 
 import static java.util.Objects.requireNonNull;
 
+import com.google.common.annotations.VisibleForTesting;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.binding.api.MountPointService.MountPointListener;
 import org.opendaylight.mdsal.dom.api.DOMMountPointListener;
 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
@@ -22,26 +22,21 @@ import org.opendaylight.yangtools.yang.data.impl.codec.DeserializationException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-final class BindingDOMMountPointListenerAdapter<T extends MountPointListener> implements
-            ListenerRegistration<T>, DOMMountPointListener {
+final class BindingDOMMountPointListenerAdapter implements Registration, DOMMountPointListener {
     private static final Logger LOG = LoggerFactory.getLogger(BindingDOMMountPointListenerAdapter.class);
 
-    private final @NonNull T listener;
+    @VisibleForTesting
+    final @NonNull MountPointListener listener;
     private final AdapterContext adapterContext;
     private final Registration registration;
 
-    BindingDOMMountPointListenerAdapter(final T listener, final AdapterContext adapterContext,
+    BindingDOMMountPointListenerAdapter(final MountPointListener listener, final AdapterContext adapterContext,
             final DOMMountPointService mountService) {
         this.listener = requireNonNull(listener);
         this.adapterContext = requireNonNull(adapterContext);
         registration = mountService.registerProvisionListener(this);
     }
 
-    @Override
-    public T getInstance() {
-        return listener;
-    }
-
     @Override
     public void close() {
         registration.close();
@@ -78,6 +73,4 @@ final class BindingDOMMountPointListenerAdapter<T extends MountPointListener> im
         }
         return binding;
     }
-
-
 }
\ No newline at end of file
index 75742fb76612ddc33c100e12514796339766025a..d924aacdb51eec94fc40a8f5300223852c2af074 100644 (file)
@@ -12,9 +12,8 @@ import org.opendaylight.mdsal.binding.api.MountPoint;
 import org.opendaylight.mdsal.binding.api.MountPointService;
 import org.opendaylight.mdsal.dom.api.DOMMountPoint;
 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 
 public class BindingDOMMountPointServiceAdapter
         extends AbstractBindingLoadingAdapter<DOMMountPointService, DOMMountPoint, BindingMountPointAdapter>
@@ -26,15 +25,13 @@ public class BindingDOMMountPointServiceAdapter
 
     @Override
     public Optional<MountPoint> getMountPoint(final InstanceIdentifier<?> mountPoint) {
-        YangInstanceIdentifier domPath = currentSerializer().toCachedYangInstanceIdentifier(mountPoint);
-        Optional<DOMMountPoint> domMount = getDelegate().getMountPoint(domPath);
-        return domMount.map(this::getAdapter);
+        final var domPath = currentSerializer().toCachedYangInstanceIdentifier(mountPoint);
+        return getDelegate().getMountPoint(domPath).map(this::getAdapter);
     }
 
     @Override
-    public <T extends MountPointListener> ListenerRegistration<T> registerListener(final InstanceIdentifier<?> path,
-            final T listener) {
-        return new BindingDOMMountPointListenerAdapter<>(listener, adapterContext(), getDelegate());
+    public Registration registerListener(final InstanceIdentifier<?> path, final MountPointListener listener) {
+        return new BindingDOMMountPointListenerAdapter(listener, adapterContext(), getDelegate());
     }
 
     @Override
diff --git a/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/BindingDataTreeChangeListenerRegistration.java b/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/BindingDataTreeChangeListenerRegistration.java
deleted file mode 100644 (file)
index 9da8dcf..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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.mdsal.binding.dom.adapter;
-
-import static java.util.Objects.requireNonNull;
-
-import org.opendaylight.mdsal.binding.api.DataTreeChangeListener;
-import org.opendaylight.yangtools.concepts.AbstractListenerRegistration;
-import org.opendaylight.yangtools.concepts.Registration;
-
-class BindingDataTreeChangeListenerRegistration<L extends DataTreeChangeListener<?>>
-        extends AbstractListenerRegistration<L> {
-    private final Registration domReg;
-
-    BindingDataTreeChangeListenerRegistration(final L listener, final Registration domReg) {
-        super(listener);
-        this.domReg = requireNonNull(domReg);
-    }
-
-    @Override
-    protected void removeRegistration() {
-        domReg.close();
-    }
-}
index b16ca11c49219a61da9b15391aaf462e6b4033a3..d018d7c4054087bebca70eb98641de557b0941ff 100644 (file)
@@ -18,7 +18,7 @@ import org.opendaylight.mdsal.binding.api.ReadWriteTransaction;
 import org.opendaylight.mdsal.binding.api.TransactionChain;
 import org.opendaylight.mdsal.binding.api.TransactionChainListener;
 import org.opendaylight.mdsal.binding.api.WriteTransaction;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.osgi.service.component.annotations.Activate;
 import org.osgi.service.component.annotations.Component;
@@ -50,9 +50,8 @@ public final class OSGiDataBroker extends AbstractAdaptedService<DataBroker> imp
     }
 
     @Override
-    public <T extends DataObject, L extends DataTreeChangeListener<T>>
-            ListenerRegistration<L> registerDataTreeChangeListener(final DataTreeIdentifier<T> treeId,
-                    final L listener) {
+    public <T extends DataObject> Registration registerDataTreeChangeListener(final DataTreeIdentifier<T> treeId,
+            final DataTreeChangeListener<T> listener) {
         return delegate().registerDataTreeChangeListener(treeId, listener);
     }
 
index 38e85986763e385c372e82699c5887b5ae090211..14c11f44248b46a26193c49a25724c454a7412d5 100644 (file)
@@ -12,7 +12,7 @@ import java.util.Map;
 import java.util.Optional;
 import org.opendaylight.mdsal.binding.api.MountPoint;
 import org.opendaylight.mdsal.binding.api.MountPointService;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.osgi.service.component.annotations.Activate;
 import org.osgi.service.component.annotations.Component;
@@ -35,8 +35,7 @@ public final class OSGiMountPointService extends AbstractAdaptedService<MountPoi
     }
 
     @Override
-    public <T extends MountPointService.MountPointListener> ListenerRegistration<T> registerListener(
-            final InstanceIdentifier<?> path, final T listener) {
+    public Registration registerListener(final InstanceIdentifier<?> path, final MountPointListener listener) {
         return delegate().registerListener(path, listener);
     }
 
index 71c9d06acffa99124e317967b7d5ef7ed72aa2fd..70fb1385315e7206579df758b63940cc4b1b74d8 100644 (file)
@@ -7,7 +7,7 @@
  */
 package org.opendaylight.mdsal.binding.dom.adapter;
 
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.reset;
@@ -22,15 +22,13 @@ import org.mockito.Mock;
 import org.mockito.junit.MockitoJUnitRunner;
 import org.opendaylight.mdsal.binding.api.MountPointService.MountPointListener;
 import org.opendaylight.mdsal.binding.dom.adapter.test.util.BindingBrokerTestFactory;
-import org.opendaylight.mdsal.binding.dom.adapter.test.util.BindingTestContext;
 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 
 @RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class BindingDOMMountPointListenerAdapterTest {
-
-    private BindingDOMMountPointListenerAdapter<?> bindingDOMMountPointListenerAdapter;
+    private BindingDOMMountPointListenerAdapter adapter;
     private AdapterContext codec;
 
     @Mock private MountPointListener listener;
@@ -39,34 +37,33 @@ public class BindingDOMMountPointListenerAdapterTest {
 
     @Before
     public void setUp() throws Exception {
-        final BindingBrokerTestFactory testFactory = new BindingBrokerTestFactory();
+        final var testFactory = new BindingBrokerTestFactory();
         testFactory.setExecutor(MoreExecutors.newDirectExecutorService());
-        final BindingTestContext testContext = testFactory.getTestContext();
+        final var testContext = testFactory.getTestContext();
         testContext.start();
         codec = testContext.getCodec();
         doReturn(listenerRegistration).when(mountPointService).registerProvisionListener(any());
-        bindingDOMMountPointListenerAdapter =
-                new BindingDOMMountPointListenerAdapter<>(listener, codec, mountPointService);
+        adapter = new BindingDOMMountPointListenerAdapter(listener, codec, mountPointService);
     }
 
     @Test
     public void basicTest() throws Exception {
-        assertEquals(listener, bindingDOMMountPointListenerAdapter.getInstance());
-        bindingDOMMountPointListenerAdapter.close();
+        assertSame(listener, adapter.listener);
+        adapter.close();
         verify(listenerRegistration).close();
     }
 
     @Test
     public void onMountPointCreatedWithExceptionTest() throws Exception {
         reset(listener);
-        bindingDOMMountPointListenerAdapter.onMountPointCreated(YangInstanceIdentifier.of());
+        adapter.onMountPointCreated(YangInstanceIdentifier.of());
         verifyNoInteractions(listener);
     }
 
     @Test
     public void onMountPointRemovedWithExceptionTest() throws Exception {
         reset(listener);
-        bindingDOMMountPointListenerAdapter.onMountPointRemoved(YangInstanceIdentifier.of());
+        adapter.onMountPointRemoved(YangInstanceIdentifier.of());
         verifyNoInteractions(listener);
     }
 }
\ No newline at end of file
index 4b15ab1d4872b575e04607fcdb7fe4bdbf302145..78ffc5f88d5da1b5390e3b7243d779ffebe8689f 100644 (file)
@@ -7,62 +7,63 @@
  */
 package org.opendaylight.mdsal.binding.dom.adapter;
 
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.mock;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.mockito.Mockito.timeout;
 import static org.mockito.Mockito.verify;
 
 import java.util.Collection;
-import java.util.Map;
 import org.junit.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.ArgumentCaptor;
-import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.mockito.Captor;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
 import org.opendaylight.mdsal.binding.api.DataTreeChangeListener;
 import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
 import org.opendaylight.mdsal.binding.api.DataTreeModification;
-import org.opendaylight.mdsal.binding.api.WriteTransaction;
 import org.opendaylight.mdsal.binding.dom.adapter.test.AbstractDataBrokerTest;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.listener.rev150825.ListenerTest;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.listener.rev150825.ListenerTestBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.listener.rev150825.listener.test.ListItem;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.listener.rev150825.listener.test.ListItemBuilder;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.util.BindingMap;
 import org.opendaylight.yangtools.yang.common.Uint32;
 
 /**
  * Regression test suite for https://bugs.opendaylight.org/show_bug.cgi?id=4513 - Change event is empty when
  * Homogeneous composite key is used homogeneous composite key is used.
  */
-public class Bug4513Test extends AbstractDataBrokerTest {
-    @SuppressWarnings({ "rawtypes", "unchecked" })
+@ExtendWith(MockitoExtension.class)
+class Bug4513Test extends AbstractDataBrokerTest {
+    @Mock
+    private DataTreeChangeListener<ListItem> listener;
+    @Captor
+    private ArgumentCaptor<Collection<DataTreeModification<ListItem>>> captor;
+
     @Test
-    public void testDataTreeChangeListener() {
-        DataBroker dataBroker = getDataBroker();
+    void testDataTreeChangeListener() {
+        final var dataBroker = getDataBroker();
 
-        DataTreeChangeListener<ListItem> listener = mock(DataTreeChangeListener.class);
-        InstanceIdentifier<ListItem> wildCard = InstanceIdentifier.builder(ListenerTest.class)
-                .child(ListItem.class).build();
-        ListenerRegistration<DataTreeChangeListener<ListItem>> reg = dataBroker.registerDataTreeChangeListener(
+        final var wildCard = InstanceIdentifier.builder(ListenerTest.class).child(ListItem.class).build();
+        final var reg = dataBroker.registerDataTreeChangeListener(
                 DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL, wildCard), listener);
 
-        final ListItem item = writeListItem();
-
-        ArgumentCaptor<Collection> captor = ArgumentCaptor.forClass(Collection.class);
+        final var item = writeListItem();
 
         verify(listener, timeout(100)).onDataTreeChanged(captor.capture());
 
-        Collection<DataTreeModification<ListItem>> mods = captor.getValue();
-        assertEquals("ListItem", item, mods.iterator().next().getRootNode().getDataAfter());
+        final var mods = captor.getValue();
+        assertEquals(1, mods.size());
+        assertEquals(item, mods.iterator().next().getRootNode().getDataAfter());
     }
 
     private ListItem writeListItem() {
-        WriteTransaction writeTransaction = getDataBroker().newWriteOnlyTransaction();
-        final ListItem item = new ListItemBuilder().setSip("name").setOp(Uint32.valueOf(43)).build();
-        ListenerTestBuilder builder = new ListenerTestBuilder().setListItem(Map.of(item.key(), item));
-        writeTransaction.put(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.builder(
-                ListenerTest.class).build(), builder.build());
+        final var writeTransaction = getDataBroker().newWriteOnlyTransaction();
+        final var item = new ListItemBuilder().setSip("name").setOp(Uint32.valueOf(43)).build();
+        writeTransaction.put(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(ListenerTest.class),
+            new ListenerTestBuilder().setListItem(BindingMap.of(item)).build());
         assertCommit(writeTransaction.commit());
         return item;
     }
index 480e9366113f961f8e1909a5a85eae00cd84838f..7ddd2664512ea15ac2a67b2eebb0b1125cefc5c6 100644 (file)
@@ -17,7 +17,7 @@ import org.opendaylight.mdsal.binding.api.ReadWriteTransaction;
 import org.opendaylight.mdsal.binding.api.TransactionChain;
 import org.opendaylight.mdsal.binding.api.TransactionChainListener;
 import org.opendaylight.mdsal.binding.api.WriteTransaction;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 
 /**
@@ -43,8 +43,8 @@ public abstract class ForwardingDataBroker extends ForwardingObject implements D
     }
 
     @Override
-    public <T extends DataObject, L extends DataTreeChangeListener<T>> ListenerRegistration<L>
-            registerDataTreeChangeListener(final DataTreeIdentifier<T> treeId, final L listener) {
+    public <T extends DataObject> Registration registerDataTreeChangeListener(final DataTreeIdentifier<T> treeId,
+            final DataTreeChangeListener<T> listener) {
         return delegate().registerDataTreeChangeListener(treeId, listener);
     }