PageRenderTime 7ms CodeModel.GetById 1ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/maven-amps-dispatcher-plugin/src/test/java/com/atlassian/maven/plugins/ampsdispatcher/TestAbstractAmpsDispatcherMojo.java

https://bitbucket.org/mmeinhold/amps
Java | 79 lines | 67 code | 12 blank | 0 comment | 0 complexity | afadf61c3113098be4b6a27862c696d6 MD5 | raw file
 1package com.atlassian.maven.plugins.ampsdispatcher;
 2
 3import junit.framework.TestCase;
 4import org.apache.maven.execution.MavenSession;
 5import org.apache.maven.model.Build;
 6import org.apache.maven.model.Plugin;
 7import org.apache.maven.plugin.PluginManager;
 8import org.apache.maven.project.MavenProject;
 9import static org.mockito.Mockito.mock;
10import static org.mockito.Mockito.when;
11
12import java.util.ArrayList;
13import java.util.Arrays;
14import java.util.List;
15
16public class TestAbstractAmpsDispatcherMojo extends TestCase
17{
18
19    MavenProject project;
20    MavenSession session;
21    PluginManager pluginManager;
22    AbstractAmpsDispatcherMojo mojo;
23
24    @Override
25    protected void setUp() throws Exception
26    {
27        super.setUp();
28        project = new MavenProject();
29        session = mock(MavenSession.class);
30        pluginManager = mock(PluginManager.class);
31        mojo = new AbstractAmpsDispatcherMojo(){};
32        mojo.pluginManager = pluginManager;
33        mojo.project = project;
34        mojo.session = session;
35    }
36
37    public void testDetectAmpsProduct()
38    {
39        assertPlugin(true, "maven-refapp-plugin");
40        assertPlugin(true, "maven-confluence-plugin");
41        assertPlugin(true, "maven-jira-plugin");
42        assertPlugin(true, "maven-stash-plugin");
43        assertPlugin(true, "maven-confluence-plugin");
44        assertPlugin(true, "maven-bamboo-plugin");
45        assertPlugin(true, "maven-crowd-plugin");
46        assertPlugin(true, "maven-fecru-plugin");
47        assertPlugin(false, "maven-refappsd-plugin");
48        assertPlugin(false, "mas");
49    }
50
51    public void testDetermineGoal()
52    {
53        when(session.getGoals()).thenReturn(Arrays.asList("foo"));
54        assertEquals("foo", mojo.determineGoal());
55
56        when(session.getGoals()).thenReturn(Arrays.asList("foo:bar"));
57        assertEquals("bar", mojo.determineGoal());
58
59        when(session.getGoals()).thenReturn(Arrays.asList("foo:bar:baz"));
60        assertEquals("baz", mojo.determineGoal());
61
62        when(session.getGoals()).thenReturn(Arrays.asList("foo", "bar"));
63        assertEquals("foo", mojo.determineGoal());
64    }
65
66    private void assertPlugin(boolean expected, String artifactId)
67    {
68        List<Plugin> buildPlugins = new ArrayList<Plugin>();
69        Plugin plugin = new Plugin();
70        plugin.setGroupId("com.atlassian.maven.plugins");
71        plugin.setArtifactId(artifactId);
72        buildPlugins.add(plugin);
73        Build build = new Build();
74        build.setPlugins(buildPlugins);
75        project.setBuild(build);
76        assertEquals(expected, artifactId.equals(mojo.detectAmpsProduct()));
77    }
78
79}