1 package org.apache.maven.plugins.pmd;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23
24 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
25
26
27
28
29
30 public class CpdViolationCheckMojoTest
31 extends AbstractMojoTestCase
32 {
33
34 @Override
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 final File testPom =
47 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 =
65 new File( getBasedir(),
66 "src/test/resources/unit/default-configuration/cpd-default-configuration-plugin-config.xml" );
67 final CpdReport mojo = (CpdReport) lookupMojo( "cpd", testPom );
68 mojo.execute();
69
70 testPom =
71 new File( getBasedir(),
72 "src/test/resources/unit/default-configuration/pmd-check-notfailonviolation-plugin-config.xml" );
73 final CpdViolationCheckMojo cpdViolationMojo = (CpdViolationCheckMojo) lookupMojo( "cpd-check", testPom );
74 cpdViolationMojo.execute();
75
76 assertTrue( true );
77 }
78
79 public void testException()
80 throws Exception
81 {
82 try
83 {
84 final File testPom =
85 new File( getBasedir(),
86 "src/test/resources/unit/custom-configuration/pmd-check-exception-test-plugin-config.xml" );
87 final CpdViolationCheckMojo mojo = (CpdViolationCheckMojo) lookupMojo( "cpd-check", testPom );
88 mojo.execute();
89
90 fail( "MojoFailureException should be thrown." );
91 }
92 catch ( final Exception e )
93 {
94 assertTrue( true );
95 }
96 }
97
98 public void testExclusionsConfiguration()
99 throws Exception
100 {
101 File testPom =
102 new File( getBasedir(),
103 "src/test/resources/unit/default-configuration/cpd-default-configuration-plugin-config.xml" );
104 final CpdReport mojo = (CpdReport) lookupMojo( "cpd", testPom );
105 mojo.execute();
106
107 testPom =
108 new File( getBasedir(),
109 "src/test/resources/unit/default-configuration/cpd-check-cpd-exclusions-configuration-plugin-config.xml" );
110 final CpdViolationCheckMojo cpdViolationMojo = (CpdViolationCheckMojo) lookupMojo( "cpd-check", testPom );
111
112
113 cpdViolationMojo.execute();
114 }
115 }