View Javadoc

1   package org.apache.maven.shared.runtime;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import junit.framework.TestCase;
23  
24  /**
25   * Tests {@code MavenProjectProperties}.
26   * 
27   * @author <a href="mailto:markh@apache.org">Mark Hobson</a>
28   * @version $Id: MavenProjectPropertiesTest.java 831910 2009-11-02 15:05:33Z markh $
29   * @see MavenProjectProperties
30   */
31  public class MavenProjectPropertiesTest extends TestCase
32  {
33      // tests ------------------------------------------------------------------
34  
35      public void testConstructor()
36      {
37          MavenProjectProperties properties = new MavenProjectProperties( "a", "b", "c" );
38  
39          assertEquals( "Group id", "a", properties.getGroupId() );
40          assertEquals( "Artifact id", "b", properties.getArtifactId() );
41          assertEquals( "Version", "c", properties.getVersion() );
42      }
43  
44      public void testConstructorNullGroupId()
45      {
46          try
47          {
48              new MavenProjectProperties( null, "b", "c" );
49  
50              fail( "IllegalArgumentException expected" );
51          }
52          catch ( IllegalArgumentException exception )
53          {
54              assertEquals( "groupId cannot be null", exception.getMessage() );
55          }
56      }
57  
58      public void testConstructorNullArtifactId()
59      {
60          try
61          {
62              new MavenProjectProperties( "a", null, "c" );
63  
64              fail( "IllegalArgumentException expected" );
65          }
66          catch ( IllegalArgumentException exception )
67          {
68              assertEquals( "artifactId cannot be null", exception.getMessage() );
69          }
70      }
71  
72      public void testConstructorNullVersion()
73      {
74          try
75          {
76              new MavenProjectProperties( "a", "b", null );
77  
78              fail( "IllegalArgumentException expected" );
79          }
80          catch ( IllegalArgumentException exception )
81          {
82              assertEquals( "version cannot be null", exception.getMessage() );
83          }
84      }
85  
86      public void testHashCodeEqual()
87      {
88          MavenProjectProperties properties1 = new MavenProjectProperties( "a", "b", "c" );
89          MavenProjectProperties properties2 = new MavenProjectProperties( "a", "b", "c" );
90  
91          assertEquals( properties1.hashCode(), properties2.hashCode() );
92      }
93  
94      public void testEqualsEqual()
95      {
96          MavenProjectProperties properties1 = new MavenProjectProperties( "a", "b", "c" );
97          MavenProjectProperties properties2 = new MavenProjectProperties( "a", "b", "c" );
98  
99          assertEquals( properties1, properties2 );
100     }
101 
102     public void testEqualsDifferentGroupId()
103     {
104         MavenProjectProperties properties1 = new MavenProjectProperties( "a", "b", "c" );
105         MavenProjectProperties properties2 = new MavenProjectProperties( "x", "b", "c" );
106 
107         assertFalse( properties1.equals( properties2 ) );
108     }
109 
110     public void testEqualsDifferentArtifactId()
111     {
112         MavenProjectProperties properties1 = new MavenProjectProperties( "a", "b", "c" );
113         MavenProjectProperties properties2 = new MavenProjectProperties( "a", "x", "c" );
114 
115         assertFalse( properties1.equals( properties2 ) );
116     }
117 
118     public void testEqualsDifferentVersion()
119     {
120         MavenProjectProperties properties1 = new MavenProjectProperties( "a", "b", "c" );
121         MavenProjectProperties properties2 = new MavenProjectProperties( "a", "b", "x" );
122 
123         assertFalse( properties1.equals( properties2 ) );
124     }
125 
126     public void testEqualsDifferentClass()
127     {
128         MavenProjectProperties properties = new MavenProjectProperties( "a", "b", "c" );
129 
130         assertFalse( properties.equals( new Object() ) );
131     }
132 
133     public void testToString()
134     {
135         MavenProjectProperties properties = new MavenProjectProperties( "a", "b", "c" );
136 
137         assertEquals( "org.apache.maven.shared.runtime.MavenProjectProperties[groupId=a,artifactId=b,version=c]",
138                       properties.toString() );
139     }
140 }