*/
package org.opendaylight.yangtools.yang2sources.plugin;
-import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Collections2;
import com.google.common.collect.ImmutableList;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
private boolean inspectDependencies;
@Component
- @VisibleForTesting
- BuildContext buildContext;
-
- private YangToSourcesProcessor yangToSourcesProcessor;
+ private BuildContext buildContext;
@Component
private RepositorySystem repoSystem;
}
- @VisibleForTesting
- YangToSourcesMojo(final YangToSourcesProcessor processor) {
- yangToSourcesProcessor = processor;
- }
-
- public void setProject(final MavenProject project) {
- this.project = project;
- }
-
@Override
@SuppressFBWarnings(value = "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", justification = "yangFilesRootDir")
public void execute() throws MojoExecutionException, MojoFailureException {
}
Util.checkClasspath(project, repoSystem, localRepository, remoteRepos);
- if (yangToSourcesProcessor == null) {
- // defaults to ${basedir}/src/main/yang
- File yangFilesRootFile = processYangFilesRootDir(yangFilesRootDir, project.getBasedir());
- Collection<File> excludedFiles = processExcludeFiles(excludeFiles, yangFilesRootFile);
+ // defaults to ${basedir}/src/main/yang
+ File yangFilesRootFile = processYangFilesRootDir(yangFilesRootDir, project.getBasedir());
+ Collection<File> excludedFiles = processExcludeFiles(excludeFiles, yangFilesRootFile);
- yangToSourcesProcessor = new YangToSourcesProcessor(buildContext, yangFilesRootFile,
- excludedFiles, arrayToList(fileGenerators), project, inspectDependencies);
- }
- yangToSourcesProcessor.execute();
+ new YangToSourcesProcessor(buildContext, yangFilesRootFile, excludedFiles, arrayToList(fileGenerators), project,
+ inspectDependencies).execute();
}
private static <T> List<T> arrayToList(final T[] array) {
import org.apache.maven.model.Build;
import org.apache.maven.model.Plugin;
import org.apache.maven.project.MavenProject;
+import org.junit.Before;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockedStatic;
@Mock
private Plugin plugin;
- final YangToSourcesMojo setupMojo(final YangToSourcesProcessor processor) {
+ @Before
+ public void before() {
doReturn("target/").when(build).getDirectory();
-// doReturn(new File("")).when(project).getBasedir();
doReturn(build).when(project).getBuild();
- doReturn(List.of()).when(plugin).getDependencies();
- doReturn(plugin).when(project).getPlugin(YangToSourcesMojo.PLUGIN_NAME);
-
try {
lenient().when(yangProvider.addYangsToMetaInf(any(MavenProject.class), anyCollection()))
.thenReturn(List.of());
} catch (IOException e) {
throw new AssertionError(e);
}
-
- final YangToSourcesMojo mojo = new YangToSourcesMojo(processor);
- mojo.setProject(project);
- return mojo;
}
@SuppressWarnings({ "rawtypes", "checkstyle:illegalCatch" })
- final void assertMojoExecution(final YangToSourcesProcessor processor, final Prepare prepare, final Verify verify) {
+ static final void assertMojoExecution(final YangToSourcesProcessor processor, final Prepare prepare,
+ final Verify verify) {
try (MockedStatic<ServiceLoader> staticLoader = mockStatic(ServiceLoader.class)) {
final FileGenerator generator = mock(FileGenerator.class);
doCallRealMethod().when(generator).importResolutionMode();
doReturn(Iterators.singletonIterator(factory)).when(loader).iterator();
staticLoader.when(() -> ServiceLoader.load(FileGeneratorFactory.class)).thenReturn(loader);
- final YangToSourcesMojo mojo = setupMojo(processor);
try {
prepare.prepare(generator);
- mojo.execute();
+ processor.execute();
verify.verify(generator);
} catch (Exception e) {
throw new AssertionError(e);
+++ /dev/null
-/*
- * 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 static org.junit.Assert.assertNotNull;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.verify;
-
-import org.apache.maven.model.Plugin;
-import org.apache.maven.project.MavenProject;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.sonatype.plexus.build.incremental.DefaultBuildContext;
-
-@RunWith(MockitoJUnitRunner.class)
-public class YangToSourcesMojoTest {
- @Mock
- private MavenProject project;
- @Mock
- private Plugin plugin;
-
- @Test
- public void yangToSourceMojoTest() throws Exception {
- doReturn(plugin).when(project).getPlugin(YangToSourcesMojo.PLUGIN_NAME);
-
- YangToSourcesMojo mojo = new YangToSourcesMojo();
- mojo.setProject(project);
- mojo.buildContext = new DefaultBuildContext();
- mojo.execute();
- assertNotNull(mojo);
-
- final YangToSourcesProcessor processor = Mockito.mock(YangToSourcesProcessor.class);
- mojo = new YangToSourcesMojo(processor);
- mojo.setProject(project);
- mojo.execute();
- verify(processor).execute();
- }
-}