Improve {Bug394,TwoRevisions}Test
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / TestUtils.java
index fd55a88966bd7b6eecc5c14fdee44ad15f617550..65378f78da4d14735c8e56ccd2ac6b7b7d752ba5 100644 (file)
@@ -48,9 +48,14 @@ public final class TestUtils {
         // Hidden on purpose
     }
 
-    public static @NonNull List<StatementStreamSource> loadSources(final String yangFilesDirectoryPath)
+    public static @NonNull List<StatementStreamSource> loadSources(final String resourceDirectory)
             throws Exception {
-        final var files = new File(TestUtils.class.getResource(yangFilesDirectoryPath).toURI())
+        return loadSources(TestUtils.class, resourceDirectory);
+    }
+
+    public static @NonNull List<StatementStreamSource> loadSources(final Class<?> cls, final String resourceDirectory)
+            throws Exception {
+        final var files = new File(cls.getResource(resourceDirectory).toURI())
             .listFiles(StmtTestUtils.YANG_FILE_FILTER);
         final var sources = new ArrayList<StatementStreamSource>(files.length);
         for (var file : files) {
@@ -59,6 +64,15 @@ public final class TestUtils {
         return sources;
     }
 
+    public static EffectiveModelContext loadModules(final String resourceDirectory) throws Exception {
+        return loadModules(TestUtils.class, resourceDirectory);
+    }
+
+    public static EffectiveModelContext loadModules(final Class<?> cls, final String resourceDirectory)
+            throws Exception {
+        return loadModules(cls.getResource(resourceDirectory).toURI());
+    }
+
     public static EffectiveModelContext loadModules(final URI resourceDirectory)
             throws ReactorException, IOException, YangSyntaxErrorException {
         final BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild();
@@ -149,16 +163,6 @@ public final class TestUtils {
         }
     }
 
-    public static List<Module> findModules(final Collection<? extends Module> modules, final String moduleName) {
-        List<Module> result = new ArrayList<>();
-        for (Module module : modules) {
-            if (module.getName().equals(moduleName)) {
-                result.add(module);
-            }
-        }
-        return result;
-    }
-
     public static EffectiveModelContext parseYangSources(final StatementStreamSource... sources)
             throws ReactorException {
         return RFC7950Reactors.defaultReactor().newBuild().addSources(sources).buildEffective();
@@ -181,16 +185,6 @@ public final class TestUtils {
         return parseYangSources(files.toArray(new File[files.size()]));
     }
 
-    public static EffectiveModelContext parseYangSources(final String yangSourcesDirectoryPath)
-            throws ReactorException, URISyntaxException, IOException, YangSyntaxErrorException {
-
-        URL resourceDir = StmtTestUtils.class.getResource(yangSourcesDirectoryPath);
-        File testSourcesDir = new File(resourceDir.toURI());
-
-        return parseYangSources(testSourcesDir.listFiles(
-            (dir, name) -> name.endsWith(YangConstants.RFC6020_YANG_FILE_EXTENSION)));
-    }
-
     public static EffectiveModelContext parseYangSource(final String yangSourceFilePath)
             throws ReactorException, URISyntaxException, IOException, YangSyntaxErrorException {