From ec7287b86e81d5dac288e9eaa777b17d4a6cb728 Mon Sep 17 00:00:00 2001 From: Jakub Toth Date: Mon, 15 Feb 2016 08:49:17 +0100 Subject: [PATCH] Bug 3899: Milestone: Increase test coverage for Yangtools YangToSourcesMojoTest Change-Id: I3e22b99eec2e8ec974241ea9bcc0a800045529a2 Signed-off-by: Jakub Toth --- .../plugin/YangToSourcesMojoTest.java | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 yang/yang-maven-plugin/src/test/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesMojoTest.java diff --git a/yang/yang-maven-plugin/src/test/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesMojoTest.java b/yang/yang-maven-plugin/src/test/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesMojoTest.java new file mode 100644 index 0000000000..9e31f25a29 --- /dev/null +++ b/yang/yang-maven-plugin/src/test/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesMojoTest.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.yangtools.yang2sources.plugin; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import org.apache.maven.model.Build; +import org.apache.maven.model.Plugin; +import org.apache.maven.project.MavenProject; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.runners.MockitoJUnitRunner; +import org.opendaylight.yangtools.yang2sources.plugin.ConfigArg.CodeGeneratorArg; +import org.opendaylight.yangtools.yang2sources.plugin.GenerateSourcesTest.GeneratorMock; +import org.opendaylight.yangtools.yang2sources.plugin.YangToSourcesProcessor.YangProvider; + +@RunWith(MockitoJUnitRunner.class) +public class YangToSourcesMojoTest { + + private YangToSourcesMojo mojo; + + @Mock + private MavenProject project; + + @Mock + private Plugin plugin; + + private YangToSourcesProcessor proc; + + @Test + public void yangToSourceMojoTest() throws Exception{ + Mockito.when(this.project.getPlugin(YangToSourcesMojo.PLUGIN_NAME)).thenReturn(this.plugin); + + this.mojo = new YangToSourcesMojo(); + this.mojo.setProject(this.project); + this.mojo.execute(); + Assert.assertNotNull(this.mojo); + + final YangToSourcesProcessor processor = Mockito.mock(YangToSourcesProcessor.class); + this.mojo = new YangToSourcesMojo(processor); + this.mojo.setProject(this.project); + this.mojo.execute(); + Mockito.verify(processor).execute(); + } + + @Test + public void test() throws Exception { + prepareProcessor(); + Assert.assertNotNull(this.proc); + this.mojo = new YangToSourcesMojo(this.proc); + this.mojo.setProject(this.project); + this.mojo.execute(); + Assert.assertNotNull(this.mojo); + } + + private void prepareProcessor() { + final File file = new File(getClass().getResource("/yang").getFile()); + final File excludedYang = new File(getClass().getResource("/yang/excluded-file.yang").getFile()); + final String path = file.getPath(); + final File[] yangFilesRootDir = { excludedYang }; + final List codeGenerators = new ArrayList<>(); + final CodeGeneratorArg codeGeneratorArg = new CodeGeneratorArg(GeneratorMock.class.getName(), path); + codeGenerators.add(codeGeneratorArg); + final MavenProject mvnProject = Mockito.mock(MavenProject.class); + final Build build = new Build(); + Mockito.when(mvnProject.getBuild()).thenReturn(build); + final boolean dependencies = true; + this.proc = new YangToSourcesProcessor(file, yangFilesRootDir, codeGenerators, + mvnProject, dependencies, new YangProvider()); + } +} -- 2.36.6