Improve AbstractQueryParams XML parsing
[netconf.git] / restconf / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / restconf / impl / test / ExpressionParserTest.java
index ab14b638080160d0546f4785dc1d1cb0ba458526..2551e3ee3316db03e8bf15da7f58de139997d180 100644 (file)
@@ -10,7 +10,7 @@ package org.opendaylight.controller.sal.restconf.impl.test;
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileReader;
-import java.lang.reflect.Field;
+import java.io.IOException;
 import java.lang.reflect.Method;
 import java.util.Collection;
 import org.junit.Assert;
@@ -134,6 +134,8 @@ public class ExpressionParserTest {
         Mockito.when(path.getLastPathArgument()).thenReturn(pathValue);
         final ListenerAdapter listener = Notificator.createListener(path, "streamName", NotificationOutputType.JSON);
         listener.setQueryParams(null, null, filter);
+
+        // FIXME: do not use reflection here
         final Class<?> superclass = listener.getClass().getSuperclass().getSuperclass();
         Method m = null;
         for (final Method method : superclass.getDeclaredMethods()) {
@@ -145,15 +147,11 @@ public class ExpressionParserTest {
             throw new Exception("Methode parseFilterParam doesn't exist in " + superclass.getName());
         }
         m.setAccessible(true);
-        final Field xmlField = superclass.getDeclaredField("xml");
-        xmlField.setAccessible(true);
-        xmlField.set(listener, readFile(xml));
-        return (boolean) m.invoke(listener, null);
+        return (boolean) m.invoke(listener, readFile(xml));
     }
 
-    private String readFile(final File xml) throws Exception {
-        final BufferedReader br = new BufferedReader(new FileReader(xml));
-        try {
+    private static String readFile(final File xml) throws IOException {
+        try (final BufferedReader br = new BufferedReader(new FileReader(xml))) {
             final StringBuilder sb = new StringBuilder();
             String line = br.readLine();
 
@@ -163,8 +161,6 @@ public class ExpressionParserTest {
                 line = br.readLine();
             }
             return sb.toString();
-        } finally {
-            br.close();
         }
     }