1   package org.apache.maven.plugin.changelog;
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.scm.ChangeFile;
24  
25  import java.util.ArrayList;
26  import java.util.List;
27  
28  /**
29   * @author Edwin Punzalan
30   * @version $Id: FileActivityComparatorTest.java 803814 2009-08-13 09:24:45Z vsiveton $
31   */
32  public class FileActivityComparatorTest
33      extends TestCase
34  {
35      private FileActivityComparator comparator;
36  
37      /** {@inheritDoc} */
38      protected void setUp()
39          throws Exception
40      {
41          comparator = new FileActivityComparator();
42      }
43  
44      public void testCompareByNumberOfCommits()
45      {
46          List list1 = new ArrayList();
47          list1.add( new ChangeFile( "anything" ) );
48  
49          List list2 = new ArrayList();
50  
51          assertTrue( "Test compare by commits, less than", comparator.compare( list1, list2 ) < 0 );
52  
53          list1 = new ArrayList();
54          list1.add( new ChangeFile( "anything" ) );
55  
56          list2 = new ArrayList();
57          list2.add( new ChangeFile( "one thing" ) );
58          list2.add( new ChangeFile( "something") );
59  
60          assertTrue( "Test compare by commits, greater than", comparator.compare( list1, list2 ) > 0 );
61      }
62  
63      public void testCompareByRevision()
64      {
65          List list1 = new ArrayList();
66          list1.add( new ChangeFile( "changefile-1", "123" ) );
67          list1.add( new ChangeFile( "changefile-1", "234" ) );
68  
69          List list2 = new ArrayList();
70          list2.add( new ChangeFile( "changefile-2", "246" ) );
71          list2.add( new ChangeFile( "changefile-2", "468" ) );
72  
73          assertTrue( "Test compare by revision, less than", comparator.compare( list1, list2 ) < 0 );
74  
75          list1 = new ArrayList();
76          list1.add( new ChangeFile( "changefile-1", "246" ) );
77          list1.add( new ChangeFile( "changefile-1", "468" ) );
78  
79          list2 = new ArrayList();
80          list2.add( new ChangeFile( "changefile-2", "123" ) );
81          list2.add( new ChangeFile( "changefile-2", "234" ) );
82  
83          assertTrue( "Test compare by revision, greater than", comparator.compare( list1, list2 ) > 0 );
84      }
85  
86      public void testCompareByName()
87      {
88          List list1 = new ArrayList();
89          list1.add( new ChangeFile( "changefile-1", "123" ) );
90          list1.add( new ChangeFile( "changefile-1", "468" ) );
91  
92          List list2 = new ArrayList();
93          list2.add( new ChangeFile( "changefile-2", "246" ) );
94          list2.add( new ChangeFile( "changefile-2", "468" ) );
95  
96          assertTrue( "Test compare by name, less than", comparator.compare( list1, list2 ) < 0 );
97  
98          list1 = new ArrayList();
99          list1.add( new ChangeFile( "changefile-1", "246" ) );
100         list1.add( new ChangeFile( "changefile-1", "468" ) );
101 
102         list2 = new ArrayList();
103         list2.add( new ChangeFile( "changefile-2", "123" ) );
104         list2.add( new ChangeFile( "changefile-2", "234" ) );
105 
106         assertTrue( "Test compare by name, greater than", comparator.compare( list1, list2 ) > 0 );
107     }
108 }