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 {
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);
files.add(new File(testDir, fileName));
}
- this.schemaContext = YangParserTestUtils.parseYangSources(files);
+ this.schemaContext = YangParserTestUtils.parseYangFiles(files);
return this.schemaContext.getModules();
}
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;
}
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);