Fix resource leaks in test cases
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / test / java / org / opendaylight / controller / md / sal / binding / impl / test / BindingDOMDataBrokerAdapterTest.java
index e2fceba..f8a95b7 100644 (file)
@@ -57,23 +57,26 @@ public class BindingDOMDataBrokerAdapterTest {
 
         BindingToNormalizedNodeCodec codec = new BindingToNormalizedNodeCodec(classLoadingStrategy, codecRegistry);
 
-        BindingDOMDataBrokerAdapter bindingDOMDataBrokerAdapter = new BindingDOMDataBrokerAdapter(dataBroker, codec);
-        Mockito.when(codecRegistry.toYangInstanceIdentifier(TOP_PATH)).thenReturn(yangInstanceIdentifier);
-
-        ArgumentCaptor<ClusteredDOMDataChangeListener> clusteredDOMListener = ArgumentCaptor.
-            forClass(ClusteredDOMDataChangeListener.class);
-        ArgumentCaptor<LogicalDatastoreType> logicalDatastoreType = ArgumentCaptor.forClass(LogicalDatastoreType.class);
-        ArgumentCaptor<AsyncDataBroker.DataChangeScope> dataChangeScope = ArgumentCaptor.
-            forClass(AsyncDataBroker.DataChangeScope.class);
-        ArgumentCaptor<YangInstanceIdentifier> yangInstanceIdentifier = ArgumentCaptor.
-            forClass(YangInstanceIdentifier.class);
-
-        TestListener listener = new TestListener();
-
-        bindingDOMDataBrokerAdapter.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, TOP_PATH, listener,
-            AsyncDataBroker.DataChangeScope.BASE);
-        Mockito.verify(dataBroker).registerDataChangeListener(logicalDatastoreType.capture(), yangInstanceIdentifier.capture(),
-            clusteredDOMListener.capture(), dataChangeScope.capture());
+        try (BindingDOMDataBrokerAdapter bindingDOMDataBrokerAdapter = new BindingDOMDataBrokerAdapter(dataBroker,
+                codec)) {
+            Mockito.when(codecRegistry.toYangInstanceIdentifier(TOP_PATH)).thenReturn(yangInstanceIdentifier);
+
+            ArgumentCaptor<ClusteredDOMDataChangeListener> clusteredDOMListener = ArgumentCaptor
+                    .forClass(ClusteredDOMDataChangeListener.class);
+            ArgumentCaptor<LogicalDatastoreType> logicalDatastoreType = ArgumentCaptor
+                    .forClass(LogicalDatastoreType.class);
+            ArgumentCaptor<AsyncDataBroker.DataChangeScope> dataChangeScope = ArgumentCaptor
+                    .forClass(AsyncDataBroker.DataChangeScope.class);
+            ArgumentCaptor<YangInstanceIdentifier> yangInstanceIdentifier = ArgumentCaptor
+                    .forClass(YangInstanceIdentifier.class);
+
+            TestListener listener = new TestListener();
+
+            bindingDOMDataBrokerAdapter.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, TOP_PATH,
+                    listener, AsyncDataBroker.DataChangeScope.BASE);
+            Mockito.verify(dataBroker).registerDataChangeListener(logicalDatastoreType.capture(),
+                    yangInstanceIdentifier.capture(), clusteredDOMListener.capture(), dataChangeScope.capture());
+        }
 
     }
 

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.