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/19 05:27:13 UTC

svn commit: r395118 - in /maven/plugins/trunk/maven-checkstyle-plugin: ./ src/main/java/org/apache/maven/plugin/checkstyle/ src/test/ src/test/java/ src/test/java/org/ src/test/java/org/apache/ src/test/java/org/apache/maven/ src/test/java/org/apache/m...

Author: epunzalan
Date: Tue Apr 18 20:27:09 2006
New Revision: 395118

URL: http://svn.apache.org/viewcvs?rev=395118&view=rev
Log:
PR: MCHECKSTYLE-39

Added plugin unit tests

Added:
    maven/plugins/trunk/maven-checkstyle-plugin/src/test/
    maven/plugins/trunk/maven-checkstyle-plugin/src/test/java/
    maven/plugins/trunk/maven-checkstyle-plugin/src/test/java/org/
    maven/plugins/trunk/maven-checkstyle-plugin/src/test/java/org/apache/
    maven/plugins/trunk/maven-checkstyle-plugin/src/test/java/org/apache/maven/
    maven/plugins/trunk/maven-checkstyle-plugin/src/test/java/org/apache/maven/plugin/
    maven/plugins/trunk/maven-checkstyle-plugin/src/test/java/org/apache/maven/plugin/checkstyle/
    maven/plugins/trunk/maven-checkstyle-plugin/src/test/java/org/apache/maven/plugin/checkstyle/CheckstyleReportListenerTest.java
    maven/plugins/trunk/maven-checkstyle-plugin/src/test/java/org/apache/maven/plugin/checkstyle/CheckstyleResultsTest.java
    maven/plugins/trunk/maven-checkstyle-plugin/src/test/java/org/apache/maven/plugin/checkstyle/LocatorTest.java
    maven/plugins/trunk/maven-checkstyle-plugin/src/test/java/org/apache/maven/plugin/checkstyle/ReportResourceTest.java
Modified:
    maven/plugins/trunk/maven-checkstyle-plugin/pom.xml
    maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/Locator.java
    maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/ReportResource.java

Modified: maven/plugins/trunk/maven-checkstyle-plugin/pom.xml
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-checkstyle-plugin/pom.xml?rev=395118&r1=395117&r2=395118&view=diff
==============================================================================
--- maven/plugins/trunk/maven-checkstyle-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-checkstyle-plugin/pom.xml Tue Apr 18 20:27:09 2006
@@ -53,7 +53,7 @@
     <dependency>
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-utils</artifactId>
-      <version>1.0.4</version>
+      <version>1.1</version>
     </dependency>
     <dependency>
       <groupId>checkstyle</groupId>

Modified: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/Locator.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/Locator.java?rev=395118&r1=395117&r2=395118&view=diff
==============================================================================
--- maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/Locator.java (original)
+++ maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/Locator.java Tue Apr 18 20:27:09 2006
@@ -41,7 +41,7 @@
     /**
      * Create a Locator object.
      *
-     * @param logger       the logger object to log with.
+     * @param log       the logger object to log with.
      * @param resolveToDir the directory to resolve resources into.
      */
     public Locator( Log log, File resolveToDir )

Modified: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/ReportResource.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/ReportResource.java?rev=395118&r1=395117&r2=395118&view=diff
==============================================================================
--- maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/ReportResource.java (original)
+++ maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/ReportResource.java Tue Apr 18 20:27:09 2006
@@ -1,7 +1,7 @@
 package org.apache.maven.plugin.checkstyle;
 
 /*
- * Copyright 2004-2005 The Apache Software Foundation.
+ * Copyright 2004-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.
@@ -16,8 +16,6 @@
  * limitations under the License.
  */
 
-import org.apache.maven.plugin.logging.Log;
-import org.apache.maven.plugin.logging.SystemStreamLog;
 import org.codehaus.plexus.util.FileUtils;
 
 import java.io.File;
@@ -31,8 +29,6 @@
  */
 public class ReportResource
 {
-    private Log log;
-
     private String resourcePathBase;
 
     private File outputDirectory;
@@ -48,20 +44,6 @@
     {
         URL url = Thread.currentThread().getContextClassLoader().getResource( resourcePathBase + "/" + resourceName );
         FileUtils.copyURLToFile( url, new File( outputDirectory, resourceName ) );
-    }
-
-    public Log getLog()
-    {
-        if ( this.log == null )
-        {
-            this.log = new SystemStreamLog();
-        }
-        return log;
-    }
-
-    public void setLog( Log log )
-    {
-        this.log = log;
     }
 
     public File getOutputDirectory()

Added: maven/plugins/trunk/maven-checkstyle-plugin/src/test/java/org/apache/maven/plugin/checkstyle/CheckstyleReportListenerTest.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-checkstyle-plugin/src/test/java/org/apache/maven/plugin/checkstyle/CheckstyleReportListenerTest.java?rev=395118&view=auto
==============================================================================
--- maven/plugins/trunk/maven-checkstyle-plugin/src/test/java/org/apache/maven/plugin/checkstyle/CheckstyleReportListenerTest.java (added)
+++ maven/plugins/trunk/maven-checkstyle-plugin/src/test/java/org/apache/maven/plugin/checkstyle/CheckstyleReportListenerTest.java Tue Apr 18 20:27:09 2006
@@ -0,0 +1,185 @@
+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 com.puppycrawl.tools.checkstyle.api.AuditEvent;
+import com.puppycrawl.tools.checkstyle.api.LocalizedMessage;
+import com.puppycrawl.tools.checkstyle.api.SeverityLevel;
+import junit.framework.TestCase;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * @author Edwin Punzalan
+ */
+public class CheckstyleReportListenerTest
+    extends TestCase
+{
+    private Map listenerMap;
+
+    protected void setUp()
+        throws Exception
+    {
+        listenerMap = new HashMap();
+
+        CheckstyleReportListener listener = new CheckstyleReportListener( new File( "/source/path" ) );
+        listener.setSeverityLevelFilter( SeverityLevel.INFO );
+        listenerMap.put( listener.getSeverityLevelFilter(), listener );
+
+        listener = new CheckstyleReportListener( new File( "/source/path" ) );
+        listener.setSeverityLevelFilter( SeverityLevel.WARNING );
+        listenerMap.put( listener.getSeverityLevelFilter(), listener );
+
+        listener = new CheckstyleReportListener( new File( "/source/path" ) );
+        listener.setSeverityLevelFilter( SeverityLevel.ERROR );
+        listenerMap.put( listener.getSeverityLevelFilter(), listener );
+
+        listener = new CheckstyleReportListener( new File( "/source/path" ) );
+        listener.setSeverityLevelFilter( SeverityLevel.IGNORE );
+        listenerMap.put( listener.getSeverityLevelFilter(), listener );
+    }
+
+    public void testListeners()
+    {
+        fireAuditStarted( null );
+
+        AuditEvent event = new AuditEvent( this, "/source/path/file1", null );
+        fireFileStarted( event );
+        LocalizedMessage message = new LocalizedMessage( 0, 0, "", "", null, SeverityLevel.INFO, getClass() );
+        fireAddError( new AuditEvent( this, "/source/path/file1", message ) );
+        fireFileFinished( event );
+
+        event = new AuditEvent( this, "/source/path/file2", null );
+        fireFileStarted( event );
+        message = new LocalizedMessage( 0, 0, "", "", null, SeverityLevel.WARNING, getClass() );
+        fireAddError( new AuditEvent( this, "/source/path/file2", message ) );
+        fireAddError( new AuditEvent( this, "/source/path/file2", message ) );
+        fireFileFinished( event );
+
+        event = new AuditEvent( this, "/source/path/file3", null );
+        fireFileStarted( event );
+        message = new LocalizedMessage( 0, 0, "", "", null, SeverityLevel.ERROR, getClass() );
+        fireAddError( new AuditEvent( this, "/source/path/file3", message ) );
+        fireAddError( new AuditEvent( this, "/source/path/file3", message ) );
+        fireAddError( new AuditEvent( this, "/source/path/file3", message ) );
+        fireFileFinished( event );
+
+        event = new AuditEvent( this, "/source/path/file4", null );
+        fireFileStarted( event );
+        message = new LocalizedMessage( 0, 0, "", "", null, SeverityLevel.IGNORE, getClass() );
+        fireAddError( new AuditEvent( this, "/source/path/file4", message ) );
+        fireAddError( new AuditEvent( this, "/source/path/file4", message ) );
+        fireAddError( new AuditEvent( this, "/source/path/file4", message ) );
+        fireAddError( new AuditEvent( this, "/source/path/file4", message ) );
+        fireFileFinished( event );
+
+        fireAuditFinished( null );
+
+        CheckstyleReportListener listener = (CheckstyleReportListener) listenerMap.get( SeverityLevel.INFO );
+        CheckstyleResults results = listener.getResults();
+        assertEquals( "Test total files", 4, results.getFiles().size() );
+        assertEquals( "Test file count", 4, results.getFileCount() );
+        assertEquals( "test file violations", 1, results.getFileViolations( "file1" ).size() );
+        assertEquals( "test file severities", 1, results.getSeverityCount( "file1", SeverityLevel.INFO ) );
+        assertEquals( "test file severities", 0, results.getSeverityCount( "file1", SeverityLevel.WARNING ) );
+        assertEquals( "test file severities", 0, results.getSeverityCount( "file1", SeverityLevel.ERROR ) );
+        assertEquals( "test file severities", 0, results.getSeverityCount( "file1", SeverityLevel.IGNORE ) );
+
+        listener = (CheckstyleReportListener) listenerMap.get( SeverityLevel.WARNING );
+        results = listener.getResults();
+        assertEquals( "Test total files", 4, results.getFiles().size() );
+        assertEquals( "Test file count", 4, results.getFileCount() );
+        assertEquals( "test file violations", 2, results.getFileViolations( "file2" ).size() );
+        assertEquals( "test file severities", 0, results.getSeverityCount( "file2", SeverityLevel.INFO ) );
+        assertEquals( "test file severities", 2, results.getSeverityCount( "file2", SeverityLevel.WARNING ) );
+        assertEquals( "test file severities", 0, results.getSeverityCount( "file2", SeverityLevel.ERROR ) );
+        assertEquals( "test file severities", 0, results.getSeverityCount( "file2", SeverityLevel.IGNORE ) );
+
+        listener = (CheckstyleReportListener) listenerMap.get( SeverityLevel.ERROR );
+        results = listener.getResults();
+        assertEquals( "Test total files", 4, results.getFiles().size() );
+        assertEquals( "Test file count", 4, results.getFileCount() );
+        assertEquals( "test file violations", 3, results.getFileViolations( "file3" ).size() );
+        assertEquals( "test file severities", 0, results.getSeverityCount( "file3", SeverityLevel.INFO ) );
+        assertEquals( "test file severities", 0, results.getSeverityCount( "file3", SeverityLevel.WARNING ) );
+        assertEquals( "test file severities", 3, results.getSeverityCount( "file3", SeverityLevel.ERROR ) );
+        assertEquals( "test file severities", 0, results.getSeverityCount( "file3", SeverityLevel.IGNORE ) );
+
+        listener = (CheckstyleReportListener) listenerMap.get( SeverityLevel.IGNORE );
+        results = listener.getResults();
+        assertEquals( "Test total files", 4, results.getFiles().size() );
+        assertEquals( "Test file count", 4, results.getFileCount() );
+        assertEquals( "test file violations", 0, results.getFileViolations( "file4" ).size() );
+        assertEquals( "test file severities", 0, results.getSeverityCount( "file4", SeverityLevel.INFO ) );
+        assertEquals( "test file severities", 0, results.getSeverityCount( "file4", SeverityLevel.WARNING ) );
+        assertEquals( "test file severities", 0, results.getSeverityCount( "file4", SeverityLevel.ERROR ) );
+        assertEquals( "test file severities", 0, results.getSeverityCount( "file4", SeverityLevel.IGNORE ) );
+    }
+
+    private void fireAuditStarted( AuditEvent event )
+    {
+        for ( Iterator listeners = listenerMap.values().iterator(); listeners.hasNext(); )
+        {
+            CheckstyleReportListener listener = (CheckstyleReportListener) listeners.next();
+
+            listener.auditStarted( event );
+        }
+    }
+
+    private void fireAuditFinished( AuditEvent event )
+    {
+        for ( Iterator listeners = listenerMap.values().iterator(); listeners.hasNext(); )
+        {
+            CheckstyleReportListener listener = (CheckstyleReportListener) listeners.next();
+
+            listener.auditFinished( event );
+        }
+    }
+
+    private void fireFileStarted( AuditEvent event )
+    {
+        for ( Iterator listeners = listenerMap.values().iterator(); listeners.hasNext(); )
+        {
+            CheckstyleReportListener listener = (CheckstyleReportListener) listeners.next();
+
+            listener.fileStarted( event );
+        }
+    }
+
+    private void fireFileFinished( AuditEvent event )
+    {
+        for ( Iterator listeners = listenerMap.values().iterator(); listeners.hasNext(); )
+        {
+            CheckstyleReportListener listener = (CheckstyleReportListener) listeners.next();
+
+            listener.fileFinished( event );
+        }
+    }
+
+    private void fireAddError( AuditEvent event )
+    {
+        for ( Iterator listeners = listenerMap.values().iterator(); listeners.hasNext(); )
+        {
+            CheckstyleReportListener listener = (CheckstyleReportListener) listeners.next();
+
+            listener.addError( event );
+        }
+    }
+}

Added: maven/plugins/trunk/maven-checkstyle-plugin/src/test/java/org/apache/maven/plugin/checkstyle/CheckstyleResultsTest.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-checkstyle-plugin/src/test/java/org/apache/maven/plugin/checkstyle/CheckstyleResultsTest.java?rev=395118&view=auto
==============================================================================
--- maven/plugins/trunk/maven-checkstyle-plugin/src/test/java/org/apache/maven/plugin/checkstyle/CheckstyleResultsTest.java (added)
+++ maven/plugins/trunk/maven-checkstyle-plugin/src/test/java/org/apache/maven/plugin/checkstyle/CheckstyleResultsTest.java Tue Apr 18 20:27:09 2006
@@ -0,0 +1,132 @@
+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 junit.framework.TestCase;
+import com.puppycrawl.tools.checkstyle.api.SeverityLevel;
+import com.puppycrawl.tools.checkstyle.api.AuditEvent;
+import com.puppycrawl.tools.checkstyle.api.LocalizedMessage;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @author Edwin Punzalan
+ */
+public class CheckstyleResultsTest
+    extends TestCase
+{
+    private CheckstyleResults results;
+
+    protected void setUp()
+        throws Exception
+    {
+        results = new CheckstyleResults();
+    }
+
+    public void testEmptyResults()
+    {
+        assertEquals( "test total files", 0, results.getFiles().size() );
+
+        assertEquals( "test file count", 0, results.getFileCount() );
+
+        assertEquals( "test zero file violations", 0, results.getFileViolations( "filename" ).size() );
+
+        assertEquals( "test INFO severity count", 0, results.getSeverityCount( SeverityLevel.INFO ) );
+
+        assertEquals( "test WARNING severity count", 0, results.getSeverityCount( SeverityLevel.WARNING ) );
+
+        assertEquals( "test ERROR severity count", 0, results.getSeverityCount( SeverityLevel.ERROR ) );
+
+        assertEquals( "test IGNORE severity count", 0, results.getSeverityCount( SeverityLevel.IGNORE ) );
+    }
+
+    public void testResults()
+    {
+        Map files = new HashMap();
+
+        LocalizedMessage message = new LocalizedMessage( 0, 0, "", "", null, SeverityLevel.INFO, getClass() );
+        AuditEvent event = new AuditEvent( this, "file1", message );
+        files.put( "file1", Collections.singletonList( event ) );
+
+        message = new LocalizedMessage( 0, 0, "", "", null, SeverityLevel.WARNING, getClass() );
+        List events = new ArrayList();
+        events.add( new AuditEvent( this, "file2", message ) );
+        events.add( new AuditEvent( this, "file2", message ) );
+        files.put( "file2", events );
+
+        message = new LocalizedMessage( 0, 0, "", "", null, SeverityLevel.ERROR, getClass() );
+        events = new ArrayList();
+        events.add( new AuditEvent( this, "file3", message ) );
+        events.add( new AuditEvent( this, "file3", message ) );
+        events.add( new AuditEvent( this, "file3", message ) );
+        files.put( "file3", events );
+
+        message = new LocalizedMessage( 0, 0, "", "", null, SeverityLevel.IGNORE, getClass() );
+        events = new ArrayList();
+        events.add( new AuditEvent( this, "file4", message ) );
+        events.add( new AuditEvent( this, "file4", message ) );
+        events.add( new AuditEvent( this, "file4", message ) );
+        events.add( new AuditEvent( this, "file4", message ) );
+        files.put( "file4", events );
+
+        results.setFiles( files );
+
+        assertEquals( "test total files", 4, results.getFiles().size() );
+        assertEquals( "test file count", 4, results.getFileCount() );
+
+        assertEquals( "test file severities", 0, results.getSeverityCount( "file0", SeverityLevel.INFO ) );
+        assertEquals( "test file severities", 0, results.getSeverityCount( "file0", SeverityLevel.WARNING ) );
+        assertEquals( "test file severities", 0, results.getSeverityCount( "file0", SeverityLevel.ERROR ) );
+        assertEquals( "test file severities", 0, results.getSeverityCount( "file0", SeverityLevel.IGNORE ) );
+
+        assertEquals( "test file violations", 1, results.getFileViolations( "file1" ).size() );
+        assertEquals( "test file severities", 1, results.getSeverityCount( "file1", SeverityLevel.INFO ) );
+        assertEquals( "test file severities", 0, results.getSeverityCount( "file1", SeverityLevel.WARNING ) );
+        assertEquals( "test file severities", 0, results.getSeverityCount( "file1", SeverityLevel.ERROR ) );
+        assertEquals( "test file severities", 0, results.getSeverityCount( "file1", SeverityLevel.IGNORE ) );
+
+        assertEquals( "test file violations", 2, results.getFileViolations( "file2" ).size() );
+        assertEquals( "test file severities", 0, results.getSeverityCount( "file2", SeverityLevel.INFO ) );
+        assertEquals( "test file severities", 2, results.getSeverityCount( "file2", SeverityLevel.WARNING ) );
+        assertEquals( "test file severities", 0, results.getSeverityCount( "file2", SeverityLevel.ERROR ) );
+        assertEquals( "test file severities", 0, results.getSeverityCount( "file2", SeverityLevel.IGNORE ) );
+
+        assertEquals( "test file violations", 3, results.getFileViolations( "file3" ).size() );
+        assertEquals( "test file severities", 0, results.getSeverityCount( "file3", SeverityLevel.INFO ) );
+        assertEquals( "test file severities", 0, results.getSeverityCount( "file3", SeverityLevel.WARNING ) );
+        assertEquals( "test file severities", 3, results.getSeverityCount( "file3", SeverityLevel.ERROR ) );
+        assertEquals( "test file severities", 0, results.getSeverityCount( "file3", SeverityLevel.IGNORE ) );
+
+        assertEquals( "test file violations", 4, results.getFileViolations( "file4" ).size() );
+        assertEquals( "test file severities", 0, results.getSeverityCount( "file4", SeverityLevel.INFO ) );
+        assertEquals( "test file severities", 0, results.getSeverityCount( "file4", SeverityLevel.WARNING ) );
+        assertEquals( "test file severities", 0, results.getSeverityCount( "file4", SeverityLevel.ERROR ) );
+        assertEquals( "test file severities", 4, results.getSeverityCount( "file4", SeverityLevel.IGNORE ) );
+
+        assertEquals( "test INFO severity count", 1, results.getSeverityCount( SeverityLevel.INFO ) );
+        assertEquals( "test WARNING severity count", 2, results.getSeverityCount( SeverityLevel.WARNING ) );
+        assertEquals( "test ERROR severity count", 3, results.getSeverityCount( SeverityLevel.ERROR ) );
+        assertEquals( "test IGNORE severity count", 4, results.getSeverityCount( SeverityLevel.IGNORE ) );
+
+        results.setFileViolations( "file", Collections.EMPTY_LIST );
+        assertEquals( "test file violations", 0, results.getFileViolations( "file" ).size() );
+    }
+}

Added: maven/plugins/trunk/maven-checkstyle-plugin/src/test/java/org/apache/maven/plugin/checkstyle/LocatorTest.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-checkstyle-plugin/src/test/java/org/apache/maven/plugin/checkstyle/LocatorTest.java?rev=395118&view=auto
==============================================================================
--- maven/plugins/trunk/maven-checkstyle-plugin/src/test/java/org/apache/maven/plugin/checkstyle/LocatorTest.java (added)
+++ maven/plugins/trunk/maven-checkstyle-plugin/src/test/java/org/apache/maven/plugin/checkstyle/LocatorTest.java Tue Apr 18 20:27:09 2006
@@ -0,0 +1,93 @@
+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 junit.framework.TestCase;
+import org.codehaus.plexus.PlexusTestCase;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * @author Edwin Punzalan
+ */
+public class LocatorTest
+    extends TestCase
+{
+    Locator locator;
+
+    File testDir = new File( PlexusTestCase.getBasedir(), "target/unit-test/Locator" );
+
+    protected void setUp()
+        throws Exception
+    {
+        locator = new Locator( null, testDir );
+    }
+
+    public void testEmptyLocation()
+        throws Exception
+    {
+        assertNull( "Test null location", locator.resolveLocation( null, "" ) );
+        assertNull( "Test empty location", locator.resolveLocation( "", "" ) );
+    }
+
+    public void testURLs()
+        throws Exception
+    {
+        String basedir = PlexusTestCase.getBasedir();
+        File resolvedFile = locator.resolveLocation( "file:///" + basedir + "/target/classes/config/maven_checks.xml",
+                                                     "maven_checks.xml" );
+
+        assertNotNull( "Test resolved file", resolvedFile );
+        assertTrue( "Test resolved file exists", resolvedFile.exists() );
+    }
+
+    public void testLocalFile()
+        throws Exception
+    {
+        String basedir = PlexusTestCase.getBasedir();
+
+        File resolvedFile = locator.resolveLocation( basedir + "/target/classes/config/avalon_checks.xml",
+                                                     "avalon_checks.xml" );
+
+        assertNotNull( "Test resolved file", resolvedFile );
+        assertTrue( "Test resolved file exists", resolvedFile.exists() );
+    }
+
+    public void testResource()
+        throws Exception
+    {
+        File resolvedFile = locator.resolveLocation( "META-INF/plexus/components.xml", "components.xml" );
+
+        assertNotNull( "Test resolved file", resolvedFile );
+        assertTrue( "Test resolved file exists", resolvedFile.exists() );
+    }
+
+    public void testException()
+    {
+        try
+        {
+            locator.resolveLocation( "edwin/punzalan", "exception" );
+
+            fail( "Expected IOException not thrown" );
+        }
+        catch ( IOException e )
+        {
+            //expected
+        }
+    }
+}

Added: maven/plugins/trunk/maven-checkstyle-plugin/src/test/java/org/apache/maven/plugin/checkstyle/ReportResourceTest.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-checkstyle-plugin/src/test/java/org/apache/maven/plugin/checkstyle/ReportResourceTest.java?rev=395118&view=auto
==============================================================================
--- maven/plugins/trunk/maven-checkstyle-plugin/src/test/java/org/apache/maven/plugin/checkstyle/ReportResourceTest.java (added)
+++ maven/plugins/trunk/maven-checkstyle-plugin/src/test/java/org/apache/maven/plugin/checkstyle/ReportResourceTest.java Tue Apr 18 20:27:09 2006
@@ -0,0 +1,58 @@
+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 junit.framework.TestCase;
+import org.codehaus.plexus.PlexusTestCase;
+
+import java.io.File;
+
+/**
+ * @author Edwin Punzalan
+ */
+public class ReportResourceTest
+    extends TestCase
+{
+    private File outputDir = new File( PlexusTestCase.getBasedir(), "target/unit-test/ReportResource" );
+
+    public void testConstructor()
+    {
+        ReportResource reportResource = new ReportResource( "reportbase", outputDir );
+        assertEquals( "Test resourcePathBase", "reportbase", reportResource.getResourcePathBase() );
+        assertEquals( "Test outputDirectory", outputDir, reportResource.getOutputDirectory() );
+    }
+
+    public void testSetters()
+    {
+        ReportResource reportResource = new ReportResource( null, null );
+        reportResource.setResourcePathBase( "reportbase" );
+        reportResource.setOutputDirectory( outputDir );
+
+        assertEquals( "Test resourcePathBase", "reportbase", reportResource.getResourcePathBase() );
+        assertEquals( "Test outputDirectory", outputDir, reportResource.getOutputDirectory() );
+    }
+
+    public void testCopy()
+        throws Exception
+    {
+        ReportResource reportResource = new ReportResource( "META-INF/plexus", outputDir );
+        reportResource.copy( "components.xml" );
+
+        File copiedFile = new File( outputDir, "components.xml" );
+        assertTrue( "Test copied file exists", copiedFile.exists() );
+    }
+}