View Javadoc

1   package org.apache.maven.plugin.pmd;
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.testing.AbstractMojoTestCase;
23  
24  import java.io.File;
25  
26  
27  /**
28   * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
29   * @version $Id$
30   */
31  public class CpdViolationCheckMojoTest
32      extends AbstractMojoTestCase
33  {
34      /** {@inheritDoc} */
35      protected void setUp()
36          throws Exception
37      {
38          super.setUp();
39      }
40  
41      public void testDefaultConfiguration()
42          throws Exception
43      {
44          try
45          {
46              File testPom = new File( getBasedir(),
47                                       "src/test/resources/unit/default-configuration/pmd-check-default-configuration-plugin-config.xml" );
48              CpdViolationCheckMojo mojo = (CpdViolationCheckMojo) lookupMojo( "cpd-check", testPom );
49              mojo.execute();
50  
51              fail( "MojoFailureException should be thrown." );
52          }
53          catch ( Exception e )
54          {
55              assertTrue( true );
56          }
57      }
58  
59      public void testNotFailOnViolation()
60          throws Exception
61      {
62  
63          File testPom = new File( getBasedir(),
64                                   "src/test/resources/unit/default-configuration/cpd-default-configuration-plugin-config.xml" );
65          CpdReport mojo = (CpdReport) lookupMojo( "cpd", testPom );
66          mojo.execute();
67  
68          testPom = new File( getBasedir(),
69                              "src/test/resources/unit/default-configuration/pmd-check-notfailonviolation-plugin-config.xml" );
70          CpdViolationCheckMojo cpdViolationMojo = (CpdViolationCheckMojo) lookupMojo( "cpd-check", testPom );
71          cpdViolationMojo.execute();
72  
73          assertTrue( true );
74      }
75  
76      public void testException()
77          throws Exception
78      {
79          try
80          {
81              File testPom = new File( getBasedir(),
82                                       "src/test/resources/unit/custom-configuration/pmd-check-exception-test-plugin-config.xml" );
83              CpdViolationCheckMojo mojo = (CpdViolationCheckMojo) lookupMojo( "cpd-check", testPom );
84              mojo.execute();
85  
86              fail( "MojoFailureException should be thrown." );
87          }
88          catch ( Exception e )
89          {
90              assertTrue( true );
91          }
92      }
93  }