You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ep...@apache.org on 2006/04/20 10:35:30 UTC
svn commit: r395532 - in
/maven/plugins/trunk/maven-checkstyle-plugin/src/test:
java/org/apache/maven/plugin/checkstyle/CheckstyleViolationCheckMojoTest.java
plugin-configs/check-plugin-config.xml test-sources/checkstyle-result.xml
Author: epunzalan
Date: Thu Apr 20 01:35:28 2006
New Revision: 395532
URL: http://svn.apache.org/viewcvs?rev=395532&view=rev
Log:
PR: MCHECKSTYLE-39
Added test-harness tests for the checkstyle:check mojo
Added:
maven/plugins/trunk/maven-checkstyle-plugin/src/test/java/org/apache/maven/plugin/checkstyle/CheckstyleViolationCheckMojoTest.java
maven/plugins/trunk/maven-checkstyle-plugin/src/test/plugin-configs/check-plugin-config.xml
maven/plugins/trunk/maven-checkstyle-plugin/src/test/test-sources/checkstyle-result.xml
Added: maven/plugins/trunk/maven-checkstyle-plugin/src/test/java/org/apache/maven/plugin/checkstyle/CheckstyleViolationCheckMojoTest.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-checkstyle-plugin/src/test/java/org/apache/maven/plugin/checkstyle/CheckstyleViolationCheckMojoTest.java?rev=395532&view=auto
==============================================================================
--- maven/plugins/trunk/maven-checkstyle-plugin/src/test/java/org/apache/maven/plugin/checkstyle/CheckstyleViolationCheckMojoTest.java (added)
+++ maven/plugins/trunk/maven-checkstyle-plugin/src/test/java/org/apache/maven/plugin/checkstyle/CheckstyleViolationCheckMojoTest.java Thu Apr 20 01:35:28 2006
@@ -0,0 +1,103 @@
+package org.apache.maven.plugin.checkstyle;
+
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.maven.plugin.Mojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.testing.AbstractMojoTestCase;
+
+import java.io.File;
+
+/**
+ * @author Edwin Punzalan
+ */
+public class CheckstyleViolationCheckMojoTest
+ extends AbstractMojoTestCase
+{
+ public void testDefaultConfig()
+ throws Exception
+ {
+ File pluginXmlFile = new File( getBasedir(), "src/test/plugin-configs/check-plugin-config.xml" );
+
+ Mojo mojo = lookupMojo( "check", pluginXmlFile );
+
+ assertNotNull( "Mojo found.", mojo );
+
+ try
+ {
+ mojo.execute();
+
+ fail( "Must throw an exception on violations" );
+ }
+ catch ( MojoFailureException e )
+ {
+ //expected
+ }
+ }
+
+ public void testInvalidFormat()
+ throws Exception
+ {
+ File pluginXmlFile = new File( getBasedir(), "src/test/plugin-configs/check-plugin-config.xml" );
+
+ Mojo mojo = lookupMojo( "check", pluginXmlFile );
+
+ assertNotNull( "Mojo found.", mojo );
+
+ setVariableValueToObject( mojo, "outputFileFormat", "plain" );
+
+ try
+ {
+ mojo.execute();
+
+ fail( "Must throw an exception invalid format: plain" );
+ }
+ catch ( MojoExecutionException e )
+ {
+ //expected
+ }
+ }
+
+ public void testNoOutputFile()
+ throws Exception
+ {
+ File pluginXmlFile = new File( getBasedir(), "src/test/plugin-configs/check-plugin-config.xml" );
+
+ Mojo mojo = lookupMojo( "check", pluginXmlFile );
+
+ assertNotNull( "Mojo found.", mojo );
+
+ setVariableValueToObject( mojo, "outputFile", new File( "target/NoSuchFile.xml" ) );
+
+ mojo.execute();
+ }
+
+ public void testNoFail()
+ throws Exception
+ {
+ File pluginXmlFile = new File( getBasedir(), "src/test/plugin-configs/check-plugin-config.xml" );
+
+ Mojo mojo = lookupMojo( "check", pluginXmlFile );
+
+ assertNotNull( "Mojo found.", mojo );
+
+ setVariableValueToObject( mojo, "failOnViolation", Boolean.FALSE );
+
+ mojo.execute();
+ }
+}
Added: maven/plugins/trunk/maven-checkstyle-plugin/src/test/plugin-configs/check-plugin-config.xml
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-checkstyle-plugin/src/test/plugin-configs/check-plugin-config.xml?rev=395532&view=auto
==============================================================================
--- maven/plugins/trunk/maven-checkstyle-plugin/src/test/plugin-configs/check-plugin-config.xml (added)
+++ maven/plugins/trunk/maven-checkstyle-plugin/src/test/plugin-configs/check-plugin-config.xml Thu Apr 20 01:35:28 2006
@@ -0,0 +1,30 @@
+<!--
+ ~ Copyright 2001-2006 The Apache Software Foundation.
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<project>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <configuration>
+ <outputFile>${basedir}/src/test/test-sources/checkstyle-result.xml</outputFile>
+ <outputFileFormat>xml</outputFileFormat>
+ <failOnViolation>true</failOnViolation>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
Added: maven/plugins/trunk/maven-checkstyle-plugin/src/test/test-sources/checkstyle-result.xml
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-checkstyle-plugin/src/test/test-sources/checkstyle-result.xml?rev=395532&view=auto
==============================================================================
--- maven/plugins/trunk/maven-checkstyle-plugin/src/test/test-sources/checkstyle-result.xml (added)
+++ maven/plugins/trunk/maven-checkstyle-plugin/src/test/test-sources/checkstyle-result.xml Thu Apr 20 01:35:28 2006
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<checkstyle version="4.1">
+<file name="E:\scm\maven-plugins\maven-checkstyle-plugin\src\test\test-sources\package.html">
+<error line="0" severity="error" message="Missing package documentation file." source="com.puppycrawl.tools.checkstyle.checks.javadoc.PackageHtmlCheck"/>
+</file>
+<file name="E:\scm\maven-plugins\maven-checkstyle-plugin\src\test\test-sources\TestJavaObject.java">
+<error line="0" severity="error" message="File does not end with a newline." source="com.puppycrawl.tools.checkstyle.checks.NewlineAtEndOfFileCheck"/>
+</file>
+<file name="E:\scm\maven-plugins\maven-checkstyle-plugin\src\test\test-sources\TestJavaObject.java">
+<error line="1" severity="error" message="Missing a Javadoc comment." source="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTypeCheck"/>
+<error line="2" column="5" severity="error" message="Missing a Javadoc comment." source="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck"/>
+<error line="6" column="5" severity="error" message="Missing a Javadoc comment." source="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck"/>
+</file>
+</checkstyle>