Adjust to yangtools-2.0.0/odlparent-3.0.0 changes
[netconf.git] / restconf / sal-rest-docgen / src / test / java / org / opendaylight / controller / sal / rest / doc / impl / DocGenTestHelper.java
index a8196dac47d562035afaa33cfa15d626e9e8c122..1c48480a830070f0aac00c49fc30dfb4db1053f0 100644 (file)
@@ -19,18 +19,15 @@ import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Date;
 import java.util.List;
+import java.util.Optional;
 import java.util.Set;
 import javax.ws.rs.core.UriBuilder;
 import javax.ws.rs.core.UriInfo;
 import org.mockito.ArgumentCaptor;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
 import org.opendaylight.controller.sal.core.api.model.SchemaService;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 
 public class DocGenTestHelper {
@@ -39,8 +36,7 @@ public class DocGenTestHelper {
     private ObjectMapper mapper;
     private SchemaContext schemaContext;
 
-    public Set<Module> loadModules(final String resourceDirectory)
-            throws URISyntaxException, FileNotFoundException, ReactorException {
+    public Set<Module> loadModules(final String resourceDirectory) throws URISyntaxException, FileNotFoundException {
 
         final URI resourceDirUri = getClass().getResource(resourceDirectory).toURI();
         final File testDir = new File(resourceDirUri);
@@ -53,7 +49,7 @@ public class DocGenTestHelper {
             files.add(new File(testDir, fileName));
         }
 
-        this.schemaContext = YangParserTestUtils.parseYangSources(files);
+        this.schemaContext = YangParserTestUtils.parseYangFiles(files);
         return this.schemaContext.getModules();
     }
 
@@ -90,36 +86,30 @@ public class DocGenTestHelper {
         when(mockContext.getModules()).thenReturn(this.modules);
 
         final ArgumentCaptor<String> moduleCapture = ArgumentCaptor.forClass(String.class);
-        final ArgumentCaptor<Date> dateCapture = ArgumentCaptor.forClass(Date.class);
+        final ArgumentCaptor<Optional> dateCapture = ArgumentCaptor.forClass(Optional.class);
         final ArgumentCaptor<URI> namespaceCapture = ArgumentCaptor.forClass(URI.class);
-        when(mockContext.findModuleByName(moduleCapture.capture(), dateCapture.capture())).then(
-                new Answer<Module>() {
-                    @Override
-                    public Module answer(final InvocationOnMock invocation) throws Throwable {
-                        final String module = moduleCapture.getValue();
-                        final Date date = dateCapture.getValue();
-                        for (final Module m : Collections.unmodifiableSet(DocGenTestHelper.this.modules)) {
-                            if (m.getName().equals(module) && m.getRevision().equals(date)) {
-                                return m;
-                            }
-                        }
-                        return null;
+        when(mockContext.findModule(moduleCapture.capture(), dateCapture.capture())).then(
+            invocation -> {
+                final String module = moduleCapture.getValue();
+                final Optional<?> date = dateCapture.getValue();
+                for (final Module m : Collections.unmodifiableSet(DocGenTestHelper.this.modules)) {
+                    if (m.getName().equals(module) && m.getRevision().equals(date)) {
+                        return Optional.of(m);
                     }
-                });
-        when(mockContext.findModuleByNamespaceAndRevision(namespaceCapture.capture(), dateCapture.capture())).then(
-                new Answer<Module>() {
-                    @Override
-                    public Module answer(final InvocationOnMock invocation) throws Throwable {
-                        final URI namespace = namespaceCapture.getValue();
-                        final Date date = dateCapture.getValue();
-                        for (final Module m : Collections.unmodifiableSet(DocGenTestHelper.this.modules)) {
-                            if (m.getNamespace().equals(namespace) && m.getRevision().equals(date)) {
-                                return m;
-                            }
-                        }
-                        return null;
+                }
+                return Optional.empty();
+            });
+        when(mockContext.findModule(namespaceCapture.capture(), dateCapture.capture())).then(
+            invocation -> {
+                final URI namespace = namespaceCapture.getValue();
+                final Optional<?> date = dateCapture.getValue();
+                for (final Module m : Collections.unmodifiableSet(DocGenTestHelper.this.modules)) {
+                    if (m.getNamespace().equals(namespace) && m.getRevision().equals(date)) {
+                        return Optional.of(m);
                     }
-                });
+                }
+                return Optional.empty();
+            });
         return mockContext;
     }
 
@@ -130,12 +120,7 @@ public class DocGenTestHelper {
 
         final ArgumentCaptor<String> subStringCapture = ArgumentCaptor.forClass(String.class);
         when(mockBuilder.path(subStringCapture.capture())).thenReturn(mockBuilder);
-        when(mockBuilder.build()).then(new Answer<URI>() {
-            @Override
-            public URI answer(final InvocationOnMock invocation) throws Throwable {
-                return URI.create(uri + "/" + subStringCapture.getValue());
-            }
-        });
+        when(mockBuilder.build()).then(invocation -> URI.create(uri + "/" + subStringCapture.getValue()));
 
         final UriInfo info = mock(UriInfo.class);