Author: tchemit Date: 2009-09-06 15:31:48 +0200 (Sun, 06 Sep 2009) New Revision: 567 Modified: trunk/changelog.txt trunk/src/test/java/org/nuiton/license/plugin/LicensePluginTest.java trunk/src/test/java/org/nuiton/util/BasePluginTestCase.java Log: [FEATURE #45] utiliser des generics dans le framework de test de mojos Modified: trunk/changelog.txt =================================================================== --- trunk/changelog.txt 2009-08-29 21:37:23 UTC (rev 566) +++ trunk/changelog.txt 2009-09-06 13:31:48 UTC (rev 567) @@ -1,10 +1,16 @@ +maven-helper-plugin (1.0.3) stable; urgency=high + + * [FEATURE #45] utiliser des generics dans le framework de test de mojos + + -- chemit -- + maven-helper-plugin (1.0.2) stable; urgency=high - * [FIX] #36 protect emails + * [FIX #36] protect emails * [FEATURE] use maven.file.license * [FEATURE] improve code + add some usefull methods for plugin * [FEATURE] add some documentation on site + use apt format (no deps to jrst) - * [FEATURE] #26 add a check-project-files goal to detect existence of the changelog.txt file for root module of project. + * [FEATURE #26] add a check-project-files goal to detect existence of the changelog.txt file for root module of project. -- chemit -- Sat, 29 Aug 2009 19:45:05 +0200 Modified: trunk/src/test/java/org/nuiton/license/plugin/LicensePluginTest.java =================================================================== --- trunk/src/test/java/org/nuiton/license/plugin/LicensePluginTest.java 2009-08-29 21:37:23 UTC (rev 566) +++ trunk/src/test/java/org/nuiton/license/plugin/LicensePluginTest.java 2009-09-06 13:31:48 UTC (rev 567) @@ -34,7 +34,7 @@ import org.nuiton.util.BasePluginTestCase; /** @author chemit */ -public class LicensePluginTest extends BasePluginTestCase { +public class LicensePluginTest extends BasePluginTestCase<LicensePlugin> { @BeforeClass public static void initClass() throws Exception { @@ -51,14 +51,13 @@ @Override public void setUp() throws Exception { super.setUp(); - LicensePlugin plugin = (LicensePlugin) mojo; - plugin.setOutputDirectory(new File(getBaseDir(), plugin.getOutputDirectory().toString())); - if (!plugin.getOutputDirectory().exists()) { - if (!plugin.getOutputDirectory().mkdirs()) { - throw new IOException("could not create directory : " + plugin.getOutputDirectory()); + mojo.setOutputDirectory(new File(getBaseDir(), mojo.getOutputDirectory().toString())); + if (!mojo.getOutputDirectory().exists()) { + if (!mojo.getOutputDirectory().mkdirs()) { + throw new IOException("could not create directory : " + mojo.getOutputDirectory()); } } - plugin.setLicenseFile(new File(pomFile.getParentFile(), plugin.getLicenseFile().toString())); + mojo.setLicenseFile(new File(pomFile.getParentFile(), mojo.getLicenseFile().toString())); } @Test @@ -66,24 +65,22 @@ public void testOne() throws MojoExecutionException, MojoFailureException { assertNotNull(mojo); - LicensePlugin p = (LicensePlugin) mojo; + long t0 = mojo.getLicenseFile().lastModified(); - long t0 = p.getLicenseFile().lastModified(); - // always assume pom is older than any file // since we can not ensure order of copy test resources - p.getProject().getFile().setLastModified(0); + mojo.getProject().getFile().setLastModified(0); - p.execute(); + mojo.execute(); - long t1 = p.getLicenseFile().lastModified(); + long t1 = mojo.getLicenseFile().lastModified(); assertEquals(t0, t1); - p.setForce(true); + mojo.setForce(true); - p.execute(); - t1 = p.getLicenseFile().lastModified(); + mojo.execute(); + t1 = mojo.getLicenseFile().lastModified(); assertTrue(t1 > t0); } Modified: trunk/src/test/java/org/nuiton/util/BasePluginTestCase.java =================================================================== --- trunk/src/test/java/org/nuiton/util/BasePluginTestCase.java 2009-08-29 21:37:23 UTC (rev 566) +++ trunk/src/test/java/org/nuiton/util/BasePluginTestCase.java 2009-09-06 13:31:48 UTC (rev 567) @@ -34,8 +34,10 @@ import org.codehaus.plexus.PlexusTestCase; import org.nuiton.AbstractPlugin; -/** @author chemit */ -public abstract class BasePluginTestCase { +/** + * @param <P> le mojo a test + * @author chemit */ +public abstract class BasePluginTestCase<P extends AbstractPlugin> { protected static File basedir; protected static File testDir; @@ -43,7 +45,7 @@ protected static MyAbstractMojoTestCase delegate; protected String goalName; protected File pomFile; - protected AbstractPlugin mojo; + protected P mojo; protected static File getBaseDir() { if (basedir == null) { @@ -58,7 +60,7 @@ return testDir; } - protected static void initConfigs(Class<? extends BasePluginTestCase> klass, String... testNames) throws Exception { + protected static <P extends AbstractPlugin> void initConfigs(Class<? extends BasePluginTestCase<P>> klass, String... testNames) throws Exception { List<PluginConfig> configs = new ArrayList<PluginConfig>(); String rep = klass.getName(); rep = rep.replaceAll("\\.", File.separator); @@ -94,7 +96,7 @@ protected void initPomFile(PluginConfig pluginConfig) throws Exception { this.goalName = pluginConfig.goalName(); this.pomFile = new File(getTestDir(), pluginConfig.pomName()); - this.mojo = (AbstractPlugin) delegate.lookupMojo(goalName, pomFile); + this.mojo = (P) delegate.lookupMojo(goalName, pomFile); MavenProject project = mojo.getProject(); if (project == null) {