Bug 5947: Increasing code coverage - mdsal-dom-inmemory-datastore
[mdsal.git] / dom / mdsal-dom-inmemory-datastore / src / test / java / org / opendaylight / mdsal / dom / store / inmemory / InMemoryDOMDataStoreFactoryTest.java
index f42cd6515d13fc91eeb0a7edde9548494f6940f2..e2fc19d11ae80ed488e4ee2b925496997f539ab7 100644 (file)
@@ -10,23 +10,41 @@ package org.opendaylight.mdsal.dom.store.inmemory;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
 
 import org.junit.Test;
-import org.mockito.Mockito;
+import org.opendaylight.controller.md.sal.dom.store.impl.TestModel;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
 
 public class InMemoryDOMDataStoreFactoryTest {
 
     @Test
-    public void createTest() throws Exception {
+    public void basicTest() throws Exception {
         final String testStoreName = "TestStore";
-        final DOMSchemaService domSchemaService = Mockito.mock(DOMSchemaService.class);
-        Mockito.doReturn(null).when(domSchemaService).registerSchemaContextListener(any(SchemaContextListener.class));
+        final DOMSchemaService domSchemaService = mock(DOMSchemaService.class);
+        doReturn(null).when(domSchemaService).registerSchemaContextListener(any(SchemaContextListener.class));
 
         final InMemoryDOMDataStore inMemoryDOMDataStore =
                 InMemoryDOMDataStoreFactory.create(testStoreName, domSchemaService);
         assertNotNull(inMemoryDOMDataStore);
         assertEquals(testStoreName, inMemoryDOMDataStore.getIdentifier());
+
+        final DOMDataTreeChangeListener domDataTreeChangeListener = mock(DOMDataTreeChangeListener.class);
+        doReturn("testListener").when(domDataTreeChangeListener).toString();
+        doNothing().when(domDataTreeChangeListener).onDataTreeChanged(any());
+        inMemoryDOMDataStore.onGlobalContextUpdated(TestModel.createTestContext());
+        inMemoryDOMDataStore.registerTreeChangeListener(YangInstanceIdentifier.EMPTY, domDataTreeChangeListener);
+
+        final AutoCloseable autoCloseable = mock(AutoCloseable.class);
+        doNothing().when(autoCloseable).close();
+        inMemoryDOMDataStore.setCloseable(autoCloseable);
+        inMemoryDOMDataStore.close();
+        verify(autoCloseable).close();
     }
 }
\ No newline at end of file