1
2 package com.simpligility.maven.plugins.android.standalonemojos;
3
4 import org.junit.After;
5 import org.junit.Assert;
6 import org.junit.Before;
7 import org.junit.FixMethodOrder;
8 import org.junit.Ignore;
9 import org.junit.Test;
10 import org.junit.runner.RunWith;
11 import org.junit.runners.MethodSorters;
12 import org.junit.runners.Parameterized;
13 import org.junit.runners.Parameterized.Parameters;
14
15 import com.simpligility.maven.plugins.android.AbstractAndroidMojoTestCase;
16 import com.simpligility.maven.plugins.android.config.ConfigHandler;
17 import com.simpligility.maven.plugins.android.configuration.MetaInf;
18 import com.simpligility.maven.plugins.android.standalonemojos.UnpackMojo;
19
20 import java.util.ArrayList;
21 import java.util.List;
22
23
24
25
26 @Ignore("This test has to be migrated to be an IntegrationTest using AbstractAndroidMojoIntegrationTest")
27 @RunWith( Parameterized.class )
28 @FixMethodOrder( MethodSorters.NAME_ASCENDING )
29 public class UnpackMojoTest
30 extends AbstractAndroidMojoTestCase<UnpackMojo>
31 {
32
33 @Parameters
34 static public List<Object[]> suite()
35 {
36 final List<Object[]> suite = new ArrayList<Object[]>();
37
38 suite.add( new Object[] { "unpack-config-project1", null } );
39 suite.add( new Object[] { "unpack-config-project2", new MetaInf().include( "persistence.xml" ) } );
40 suite.add( new Object[] { "unpack-config-project3", new MetaInf().include( "services/**", "persistence.xml" ) } );
41 suite.add( new Object[] { "unpack-config-project4", new MetaInf() } );
42
43 return suite;
44 }
45
46 private final String projectName;
47
48 private final MetaInf expected;
49
50 public UnpackMojoTest( String projectName, MetaInf expected )
51 {
52 this.projectName = projectName;
53 this.expected = expected;
54 }
55
56 @Override
57 public String getPluginGoalName()
58 {
59 return "unpack";
60 }
61
62 @Override
63 @Before
64 public void setUp()
65 throws Exception
66 {
67 super.setUp();
68 }
69
70 @Override
71 @After
72 public void tearDown()
73 throws Exception
74 {
75 super.tearDown();
76 }
77
78 @Test
79 public void testConfigHelper()
80 throws Exception
81 {
82 final UnpackMojo mojo = createMojo( this.projectName );
83 final ConfigHandler cfh = new ConfigHandler( mojo, this.session, this.execution );
84
85 cfh.parseConfiguration();
86
87 MetaInf result = getFieldValue( mojo, "unpackMetaInf" );
88
89 Assert.assertEquals( this.expected, result );
90
91 Assert.assertEquals( result == null, getFieldValue( mojo, "unpack" ) == null );
92 }
93
94 protected <T> T getFieldValue( Object object, String fieldName )
95 throws IllegalAccessException
96 {
97 return (T) super.getVariableValueFromObject( object, fieldName );
98 }
99
100 }