View Javadoc

1   package org.apache.maven.model.converter;
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  import org.apache.maven.model.Plugin;
24  
25  /**
26   * @author Dennis Lundberg
27   * @version $Id: PluginComparatorTest.java 661727 2008-05-30 14:21:49Z bentmann $
28   */
29  public class PluginComparatorTest
30      extends TestCase
31  {
32      Object object1;
33      Object object2;
34      Object object3;
35      Object object4;
36      Plugin plugin1;
37      Plugin plugin2;
38      Plugin plugin3;
39      Plugin plugin4;
40      Plugin plugin5;
41      Plugin plugin6;
42      Plugin plugin7;
43      Plugin plugin8;
44      Plugin plugin9;
45      Plugin plugin10;
46      PluginComparator comparator;
47  
48      protected void setUp()
49          throws Exception
50      {
51          super.setUp();
52          object3 = new Object();
53          object4 = new Object();
54          plugin1 = new Plugin();
55          plugin1.setGroupId( null );
56          plugin1.setArtifactId( null );
57          plugin2 = new Plugin();
58          plugin2.setGroupId( null );
59          plugin2.setArtifactId( null );
60          plugin3 = new Plugin();
61          plugin3.setGroupId( "a" );
62          plugin3.setArtifactId( "d" );
63          plugin4 = new Plugin();
64          plugin4.setGroupId( "a" );
65          plugin4.setArtifactId( "d" );
66          plugin5 = new Plugin();
67          plugin5.setGroupId( "a" );
68          plugin5.setArtifactId( "c" );
69          plugin6 = new Plugin();
70          plugin6.setGroupId( "a" );
71          plugin6.setArtifactId( "e" );
72          plugin7 = new Plugin();
73          plugin7.setGroupId( "b" );
74          plugin7.setArtifactId( "b" );
75          plugin8 = new Plugin();
76          plugin8.setGroupId( "b" );
77          plugin8.setArtifactId( "e" );
78          plugin9 = new Plugin();
79          plugin9.setGroupId( null );
80          plugin9.setArtifactId( "e" );
81          plugin10 = new Plugin();
82          plugin10.setGroupId( "a" );
83          plugin10.setArtifactId( null );
84          comparator = new PluginComparator();
85      }
86  
87      public void testClass()
88      {
89          assertEquals( "Test class", 0, comparator.compare( object3, object4 ) );
90          assertEquals( "Test class", 1, comparator.compare( plugin1, object4 ) );
91          assertEquals( "Test class", -1, comparator.compare( object3, plugin2 ) );
92      }
93  
94      public void testNullObjects()
95      {
96          assertEquals( "Test null objects", 0, comparator.compare( object1, object2 ) );
97          assertEquals( "Test null objects", -1, comparator.compare( object1, object3 ) );
98          assertEquals( "Test null objects", 1, comparator.compare( object3, object2 ) );
99      }
100 
101     public void testNullValues()
102     {
103         assertEquals( "Test null values", -1, comparator.compare( plugin1, plugin3 ) );
104         assertEquals( "Test null values", 1, comparator.compare( plugin3, plugin1 ) );
105         assertEquals( "Test null values", -1, comparator.compare( plugin1, plugin9 ) );
106         assertEquals( "Test null values", 1, comparator.compare( plugin9, plugin1 ) );
107         assertEquals( "Test null values", -1, comparator.compare( plugin1, plugin10 ) );
108         assertEquals( "Test null values", 1, comparator.compare( plugin10, plugin1 ) );
109         assertEquals( "Test null values", -1, comparator.compare( plugin9, plugin10 ) );
110         assertEquals( "Test null values", 1, comparator.compare( plugin10, plugin9 ) );
111     }
112 
113     public void testValues()
114     {
115         assertEquals( "Test values", 0, comparator.compare( plugin3, plugin4 ) );
116         assertEquals( "Test values", 1, comparator.compare( plugin3, plugin5 ) );
117         assertEquals( "Test values", -1, comparator.compare( plugin5, plugin3 ) );
118         assertEquals( "Test values", -1, comparator.compare( plugin3, plugin6 ) );
119         assertEquals( "Test values", 1, comparator.compare( plugin6, plugin3 ) );
120         assertEquals( "Test values", -1, comparator.compare( plugin3, plugin7 ) );
121         assertEquals( "Test values", 1, comparator.compare( plugin7, plugin3 ) );
122     }
123 }