Clean up NetconfDeviceSimulator.addModuleCapability()
[netconf.git] / netconf / tools / netconf-testtool / src / main / java / org / opendaylight / netconf / test / tool / NetconfDeviceSimulator.java
index 8407b94064082f1a14aec37d3ff05b424fa8a7dc..c60f5116c841728285ca344f1fdd23da492aee38 100644 (file)
@@ -343,18 +343,19 @@ public class NetconfDeviceSimulator implements Closeable {
 
     private static void addModuleCapability(final SharedSchemaRepository consumer, final Set<Capability> capabilities,
                                             final ModuleLike module) {
-        final SourceIdentifier moduleSourceIdentifier = new SourceIdentifier(module.getName(),
+        final var sourceId = new SourceIdentifier(module.getName(),
             module.getRevision().map(Revision::toString).orElse(null));
-        try {
 
-            final String moduleContent = consumer.getSchemaSource(moduleSourceIdentifier, YangTextSchemaSource.class)
-                .get().asCharSource(StandardCharsets.UTF_8).read();
-            capabilities.add(new YangModuleCapability(module, moduleContent));
-            //IOException would be thrown in creating SchemaContext already
-        } catch (final ExecutionException | InterruptedException | IOException e) {
+        final String moduleContent;
+        try {
+            moduleContent = consumer.getSchemaSource(sourceId, YangTextSchemaSource.class).get()
+                .asCharSource(StandardCharsets.UTF_8).read();
+        } catch (ExecutionException | InterruptedException | IOException e) {
             throw new IllegalStateException(
-                "Cannot retrieve schema source for module " + moduleSourceIdentifier + " from schema repository", e);
+                "Cannot retrieve schema source for module " + sourceId + " from schema repository", e);
         }
+
+        capabilities.add(new YangModuleCapability(module, moduleContent));
     }
 
     private static void registerSource(final SharedSchemaRepository consumer, final String resource,