1 package org.apache.maven.plugin.pmd;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
23
24 import java.io.File;
25
26
27
28
29
30
31 public class CpdViolationCheckMojoTest
32 extends AbstractMojoTestCase
33 {
34
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 }