1   package org.apache.maven.plugin.source;
2   
3   /* ====================================================================
4    *   Copyright 2001-2005 The Apache Software Foundation.
5    *
6    *   Licensed under the Apache License, Version 2.0 (the "License");
7    *   you may not use this file except in compliance with the License.
8    *   You may obtain a copy of the License at
9    *
10   *       http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *   Unless required by applicable law or agreed to in writing, software
13   *   distributed under the License is distributed on an "AS IS" BASIS,
14   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   *   See the License for the specific language governing permissions and
16   *   limitations under the License.
17   * ====================================================================
18   */
19  
20  import org.apache.maven.project.Project;
21  import org.apache.maven.repository.ArtifactTypeHandler;
22  import org.apache.maven.MavenException;
23  import junit.framework.TestCase;
24  
25  /**
26   * Tests the java source artifact type handler implementation.
27   *
28   * @author <a href="mailto:snicoll@apache.org">Stephane Nicoll</a>
29   * @version $Id: JavaSourceArtifactTypeHandlerTest.java 232640 2005-08-14 20:46:54Z snicoll $
30   */
31  public class JavaSourceArtifactTypeHandlerTest
32      extends TestCase
33  {
34      private Project project;
35  
36      private ArtifactTypeHandler handler;
37  
38      private static final String VERSION = "VERSION";
39  
40      public void setUp()
41          throws Exception
42      {
43          project = new Project();
44          project.setGroupId( "groupId" );
45          project.setArtifactId( "artifactId" );
46          handler = new JavaSourceArtifactTypeHandler();
47      }
48  
49      public void testConstructRepositoryDirectoryPath()
50          throws Exception
51      {
52          assertEquals( "check artifact directory", "groupId/java-sources/",
53                        handler.constructRepositoryDirectoryPath( "java-source", project ) );
54      }
55  
56      public void testConstructRepositoryFullPath()
57          throws Exception
58      {
59          assertEquals( "check artifact path", "groupId/java-sources/artifactId-VERSION-sources.jar",
60                        handler.constructRepositoryFullPath( "java-source", project, VERSION ) );
61      }
62  
63      public void testConstructRepositoryFullPathWithInvalidType()
64          throws Exception
65      {
66          try
67          {
68              handler.constructRepositoryFullPath( "foo", project, VERSION );
69              fail( "expected exception" );
70          }
71          catch ( MavenException expected )
72          {
73              assertEquals( "Unrecognised java-source type (is foo)", expected.getMessage() );
74          }
75      }
76  }