View Javadoc

1   package org.apache.maven.plugins.help;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.plugin.descriptor.MojoDescriptor;
23  import org.apache.maven.plugin.descriptor.Parameter;
24  
25  import junit.framework.Assert;
26  import junit.framework.TestCase;
27  import junitx.util.PrivateAccessor;
28  
29  /**
30   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
31   * @version $Id: DescribeMojoTest.java 1441715 2013-02-02 08:16:52Z hboutemy $
32   */
33  public class DescribeMojoTest
34      extends TestCase
35  {
36      /**
37       * Test method for {@link org.apache.maven.plugins.help.DescribeMojo#toLines(java.lang.String, int, int, int)}.
38       *
39       * @throws Exception if any
40       */
41      public void testGetExpressionsRoot()
42          throws Exception
43      {
44          try
45          {
46              PrivateAccessor.invoke( DescribeMojo.class, "toLines", new Class[] { String.class, Integer.TYPE,
47                  Integer.TYPE, Integer.TYPE }, new Object[] { "", new Integer( 2 ), new Integer( 2 ),
48                  new Integer( 80 ) } );
49              assertTrue( true );
50          }
51          catch ( Throwable e )
52          {
53              Assert.fail( "The API changes" );
54          }
55      }
56      
57      public void testValidExpression()
58          throws Exception
59      {
60          StringBuilder sb = new StringBuilder();
61          MojoDescriptor md = new MojoDescriptor();
62          Parameter parameter = new Parameter();
63          parameter.setName( "name" );
64          parameter.setExpression( "${valid.expression}" );
65          md.addParameter( parameter );
66          
67          try
68          {
69              PrivateAccessor.invoke( new DescribeMojo(), "describeMojoParameters", new Class[] { MojoDescriptor.class,
70                  StringBuilder.class }, new Object[] { md, sb } );
71              
72              assertEquals( "  Available parameters:\n" +
73              		      "\n" +
74              		      "    name\n" +
75              		      "      User property: valid.expression\n" +
76              		      "      (no description available)\n", sb.toString() );
77          }
78          catch ( Throwable e )
79          {
80              fail( e.getMessage() );
81          }
82      }
83      
84      public void testInvalidExpression()
85          throws Exception
86      {
87          StringBuilder sb = new StringBuilder();
88          MojoDescriptor md = new MojoDescriptor();
89          Parameter parameter = new Parameter();
90          parameter.setName( "name" );
91          parameter.setExpression( "${project.build.directory}/generated-sources/foobar" ); //this is a defaultValue
92          md.addParameter( parameter );
93          
94          try
95          {
96              PrivateAccessor.invoke( new DescribeMojo(), "describeMojoParameters", new Class[] { MojoDescriptor.class,
97                  StringBuilder.class }, new Object[] { md, sb } );
98              
99              assertEquals( "  Available parameters:\n" +
100                           "\n" +
101                           "    name\n" +
102                           "      Expression: ${project.build.directory}/generated-sources/foobar\n" +
103                           "      (no description available)\n", sb.toString() );
104         }
105         catch ( Throwable e )
106         {
107             fail( e.getMessage() );
108         }
109         
110     }
111 
112 }