2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang2sources.plugin;
10 import static org.junit.Assert.assertEquals;
11 import static org.mockito.ArgumentMatchers.any;
12 import static org.mockito.Mockito.doAnswer;
14 import com.google.common.collect.ImmutableTable;
16 import java.util.List;
18 import org.junit.Test;
19 import org.junit.runner.RunWith;
20 import org.mockito.junit.MockitoJUnitRunner;
21 import org.opendaylight.yangtools.yang.model.api.Module;
23 @RunWith(MockitoJUnitRunner.StrictStubs.class)
24 public class YangToSourcesProcessorTest extends AbstractCodeGeneratorTest {
25 private final File file = new File(getClass().getResource("/yang").getFile());
28 public void basicTest() {
29 assertMojoExecution(new YangToSourcesProcessor(file, List.of(),
30 List.of(new FileGeneratorArg("mockGenerator")), project, true,
31 YangProvider.getInstance()), mock -> {
32 doAnswer(invocation -> {
33 final Set<Module> localModules = invocation.getArgument(1);
34 assertEquals(2, localModules.size());
35 return ImmutableTable.of();
36 }).when(mock).generateFiles(any(), any(), any());
41 public void excludeFilesTest() throws Exception {
42 final File excludedYang = new File(getClass().getResource("/yang/excluded-file.yang").getFile());
44 assertMojoExecution(new YangToSourcesProcessor(file, List.of(excludedYang),
45 List.of(new FileGeneratorArg("mockGenerator")), project, true,
46 YangProvider.getInstance()), mock -> {
47 doAnswer(invocation -> {
48 final Set<Module> localModules = invocation.getArgument(1);
49 assertEquals(1, localModules.size());
50 assertEquals("mock", localModules.iterator().next().getName());
51 return ImmutableTable.of();
52 }).when(mock).generateFiles(any(), any(), any());