You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by jv...@apache.org on 2004/05/24 19:27:38 UTC

cvs commit: maven-components/maven-plugin/src/main/java/org/apache/maven/plugin PluginTestCase.java

jvanzyl     2004/05/24 10:27:38

  Modified:    maven-plugin/src/main/java/org/apache/maven/plugin
                        PluginTestCase.java
  Log:
  o use the strategy used in plexus to instantiate an instance of the class being tested by using the test class name. the user can override the setupPlugin() method if they want to do something differently or instantiate an instance of the class to be tested manually.
  
  Revision  Changes    Path
  1.2       +21 -3     maven-components/maven-plugin/src/main/java/org/apache/maven/plugin/PluginTestCase.java
  
  Index: PluginTestCase.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-plugin/src/main/java/org/apache/maven/plugin/PluginTestCase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PluginTestCase.java	21 May 2004 23:49:43 -0000	1.1
  +++ PluginTestCase.java	24 May 2004 17:27:38 -0000	1.2
  @@ -38,8 +38,26 @@
       //
       // ----------------------------------------------------------------------
   
  -    protected abstract void setupPlugin()
  -        throws Exception;
  +    protected void setupPlugin()
  +        throws Exception
  +    {
  +        String mojoClassName = getClass().getName();
  +
  +        mojoClassName = mojoClassName.substring( 0, mojoClassName.length() - 4 );
  +
  +        try
  +        {
  +            Class mojoClass = Thread.currentThread().getContextClassLoader().loadClass( mojoClassName );
  +
  +            plugin = (Plugin) mojoClass.newInstance();
  +        }
  +        catch ( Exception e )
  +        {
  +            throw new Exception(
  +                "Cannot find " + mojoClassName + "! Make sure your test case is named in the form ${mojoClassName}Test " +
  +                "or override the setupPlugin() method to instantiate the mojo yourself." );
  +        }
  +    }
   
       protected abstract Map getTestParameters()
           throws Exception;
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org