1 package com.simpligility.maven.plugins.android.config;
2
3 import static org.easymock.EasyMock.createNiceMock;
4 import static org.easymock.EasyMock.expect;
5 import static org.easymock.EasyMock.replay;
6 import static org.junit.Assert.assertArrayEquals;
7 import static org.junit.Assert.assertEquals;
8 import static org.junit.Assert.assertTrue;
9
10 import org.apache.maven.execution.MavenSession;
11 import org.apache.maven.plugin.MojoExecution;
12 import org.apache.maven.plugin.descriptor.MojoDescriptor;
13 import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
14 import org.apache.maven.project.MavenProject;
15 import org.junit.Before;
16 import org.junit.Test;
17
18 import com.simpligility.maven.plugins.android.config.ConfigHandler;
19
20 public class ConfigHandlerTest {
21
22 private DummyMojo mojo = new DummyMojo();
23
24 private MavenSession session;
25 private MojoExecution execution;
26
27 @Before
28 public void setUp()
29 {
30 session = createNiceMock( MavenSession.class );
31
32 final MavenProject project = new MavenProjectStub();
33 MojoDescriptor mojoDesc = new MojoDescriptor();
34
35 this.execution = new MojoExecution( mojoDesc );
36
37 expect( session.getExecutionProperties() ).andReturn( project.getProperties() );
38 expect( session.getCurrentProject() ).andReturn( project );
39 replay( session );
40 }
41
42 @Test
43 public void testParseConfigurationDefault() throws Exception {
44 ConfigHandler configHandler = new ConfigHandler( mojo, this.session, this.execution );
45 configHandler.parseConfiguration();
46 assertTrue(mojo.getParsedBooleanValue());
47 }
48
49 @Test
50 public void testParseConfigurationFromConfigPojo() throws Exception {
51 mojo.setConfigPojo(new DummyConfigPojo("from config pojo", null));
52 ConfigHandler configHandler = new ConfigHandler( mojo, this.session, this.execution );
53 configHandler.parseConfiguration();
54 assertEquals("from config pojo",mojo.getParsedStringValue());
55 }
56
57 @Test
58 public void testParseConfigurationFromMaven() throws Exception {
59 mojo.setConfigPojoStringValue("maven value");
60 ConfigHandler configHandler = new ConfigHandler( mojo, this.session, this.execution );
61 configHandler.parseConfiguration();
62 assertEquals("maven value",mojo.getParsedStringValue());
63 }
64
65 @Test
66 public void testParseConfigurationDefaultMethodValue() throws Exception {
67 ConfigHandler configHandler = new ConfigHandler( mojo, this.session, this.execution );
68 configHandler.parseConfiguration();
69 assertArrayEquals(new String[] {"a","b"},mojo.getParsedMethodValue());
70 }
71 }