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 @Override
36 protected void setUp()
37 throws Exception
38 {
39 super.setUp();
40 }
41
42 public void testDefaultConfiguration()
43 throws Exception
44 {
45 try
46 {
47 final File testPom = new File( getBasedir(),
48 "src/test/resources/unit/default-configuration/pmd-check-default-configuration-plugin-config.xml" );
49 final CpdViolationCheckMojo mojo = (CpdViolationCheckMojo) lookupMojo( "cpd-check", testPom );
50 mojo.execute();
51
52 fail( "MojoFailureException should be thrown." );
53 }
54 catch ( final Exception e )
55 {
56 assertTrue( true );
57 }
58 }
59
60 public void testNotFailOnViolation()
61 throws Exception
62 {
63
64 File testPom = new File( getBasedir(),
65 "src/test/resources/unit/default-configuration/cpd-default-configuration-plugin-config.xml" );
66 final CpdReport mojo = (CpdReport) lookupMojo( "cpd", testPom );
67 mojo.execute();
68
69 testPom = new File( getBasedir(),
70 "src/test/resources/unit/default-configuration/pmd-check-notfailonviolation-plugin-config.xml" );
71 final CpdViolationCheckMojo cpdViolationMojo = (CpdViolationCheckMojo) lookupMojo( "cpd-check", testPom );
72 cpdViolationMojo.execute();
73
74 assertTrue( true );
75 }
76
77 public void testException()
78 throws Exception
79 {
80 try
81 {
82 final File testPom = new File( getBasedir(),
83 "src/test/resources/unit/custom-configuration/pmd-check-exception-test-plugin-config.xml" );
84 final CpdViolationCheckMojo mojo = (CpdViolationCheckMojo) lookupMojo( "cpd-check", testPom );
85 mojo.execute();
86
87 fail( "MojoFailureException should be thrown." );
88 }
89 catch ( final Exception e )
90 {
91 assertTrue( true );
92 }
93 }
94
95 public void testExclusionsConfiguration()
96 throws Exception
97 {
98 File testPom = new File( getBasedir(),
99 "src/test/resources/unit/default-configuration/cpd-default-configuration-plugin-config.xml" );
100 final CpdReport mojo = (CpdReport) lookupMojo( "cpd", testPom );
101 mojo.execute();
102
103 testPom = new File( getBasedir(),
104 "src/test/resources/unit/default-configuration/pmd-check-cpd-exclusions-configuration-plugin-config.xml" );
105 final CpdViolationCheckMojo cpdViolationMojo = (CpdViolationCheckMojo) lookupMojo( "cpd-check", testPom );
106 cpdViolationMojo.execute();
107
108 assertTrue( true );
109 }
110 }