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
25
26
27
28 public class CpdViolationCheckMojoTest
29 extends AbstractPmdReportTestCase
30 {
31
32 public void testDefaultConfiguration()
33 throws Exception
34 {
35 generateReport( "cpd", "default-configuration/cpd-default-configuration-plugin-config.xml" );
36
37
38 CapturingPrintStream.init( true );
39
40 try
41 {
42 File testPom =
43 new File( getBasedir(),
44 "src/test/resources/unit/default-configuration/pmd-check-default-configuration-plugin-config.xml" );
45 final CpdViolationCheckMojo cpdViolationMojo = (CpdViolationCheckMojo) lookupMojo( "cpd-check", testPom );
46 cpdViolationMojo.execute();
47
48 fail( "MojoFailureException should be thrown." );
49 }
50 catch ( final Exception e )
51 {
52
53 String output = CapturingPrintStream.getOutput();
54 assertTrue ( output.contains( "PMD version: " + AbstractPmdReport.getPmdVersion() ) );
55
56 assertTrue( e.getMessage().startsWith( "You have 1 CPD duplication." ) );
57 }
58 }
59
60 public void testNotFailOnViolation()
61 throws Exception
62 {
63
64 generateReport( "cpd", "default-configuration/cpd-default-configuration-plugin-config.xml" );
65
66 File testPom =
67 new File( getBasedir(),
68 "src/test/resources/unit/default-configuration/cpd-check-notfailonviolation-plugin-config.xml" );
69 final CpdViolationCheckMojo cpdViolationMojo = (CpdViolationCheckMojo) lookupMojo( "cpd-check", testPom );
70 cpdViolationMojo.execute();
71
72 assertTrue( true );
73 }
74
75 public void testException()
76 throws Exception
77 {
78 try
79 {
80 final File testPom =
81 new File( getBasedir(),
82 "src/test/resources/unit/custom-configuration/pmd-check-exception-test-plugin-config.xml" );
83 final CpdViolationCheckMojo mojo = (CpdViolationCheckMojo) lookupMojo( "cpd-check", testPom );
84 mojo.execute();
85
86 fail( "MojoFailureException should be thrown." );
87 }
88 catch ( final Exception e )
89 {
90 assertTrue( true );
91 }
92 }
93
94 public void testExclusionsConfiguration()
95 throws Exception
96 {
97 generateReport( "cpd", "default-configuration/cpd-default-configuration-plugin-config.xml" );
98
99 File testPom =
100 new File( getBasedir(),
101 "src/test/resources/unit/default-configuration/cpd-check-cpd-exclusions-configuration-plugin-config.xml" );
102 final CpdViolationCheckMojo cpdViolationMojo = (CpdViolationCheckMojo) lookupMojo( "cpd-check", testPom );
103
104
105 cpdViolationMojo.execute();
106 }
107 }