Fix resource leaks in test cases
[controller.git] / opendaylight / config / config-persister-file-xml-adapter / src / test / java / org / opendaylight / controller / config / persist / storage / file / xml / FileStorageAdapterTest.java
index de5f41f..dc1fc78 100644 (file)
@@ -259,33 +259,36 @@ public class FileStorageAdapterTest {
         if (!file.exists()) {
             return;
         }
         if (!file.exists()) {
             return;
         }
-        XmlFileStorageAdapter storage = new XmlFileStorageAdapter();
-        storage.setFileStorage(file);
+        try (XmlFileStorageAdapter storage = new XmlFileStorageAdapter()) {
+            storage.setFileStorage(file);
 
 
-        List<ConfigSnapshotHolder> elementOptional = storage.loadLastConfigs();
-        assertThat(elementOptional.size(), is(0));
+            List<ConfigSnapshotHolder> elementOptional = storage.loadLastConfigs();
+            assertThat(elementOptional.size(), is(0));
+        }
     }
 
     @Test(expected = NullPointerException.class)
     public void testNoProperties() throws Exception {
     }
 
     @Test(expected = NullPointerException.class)
     public void testNoProperties() throws Exception {
-        XmlFileStorageAdapter storage = new XmlFileStorageAdapter();
-        storage.loadLastConfigs();
+        try (XmlFileStorageAdapter storage = new XmlFileStorageAdapter()) {
+            storage.loadLastConfigs();
+        }
     }
 
     @Test(expected = NullPointerException.class)
     public void testNoProperties2() throws Exception {
     }
 
     @Test(expected = NullPointerException.class)
     public void testNoProperties2() throws Exception {
-        XmlFileStorageAdapter storage = new XmlFileStorageAdapter();
-        storage.persistConfig(new ConfigSnapshotHolder() {
-            @Override
-            public String getConfigSnapshot() {
-                return mock(String.class);
-            }
-
-            @Override
-            public SortedSet<String> getCapabilities() {
-                return new TreeSet<>();
-            }
-        } );
+        try (XmlFileStorageAdapter storage = new XmlFileStorageAdapter()) {
+            storage.persistConfig(new ConfigSnapshotHolder() {
+                @Override
+                public String getConfigSnapshot() {
+                    return mock(String.class);
+                }
+
+                @Override
+                public SortedSet<String> getCapabilities() {
+                    return new TreeSet<>();
+                }
+            });
+        }
     }
 
     static String createConfig() {
     }
 
     static String createConfig() {