1   /*
2       StatCvs - CVS statistics generation 
3       Copyright (C) 2002  Lukasz Pekacki <lukasz@pekacki.de>
4       http://statcvs.sf.net/
5       
6       This library is free software; you can redistribute it and/or
7       modify it under the terms of the GNU Lesser General Public
8       License as published by the Free Software Foundation; either
9       version 2.1 of the License, or (at your option) any later version.
10  
11      This library is distributed in the hope that it will be useful,
12      but WITHOUT ANY WARRANTY; without even the implied warranty of
13      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14      Lesser General Public License for more details.
15  
16      You should have received a copy of the GNU Lesser General Public
17      License along with this library; if not, write to the Free Software
18      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19      
20  	$Name:  $ 
21  	Created on $Date: 2008/04/02 11:22:15 $ 
22  */
23  package net.sf.statcvs.model;
24  
25  import java.util.Date;
26  import java.util.Iterator;
27  
28  import junit.framework.TestCase;
29  
30  /**
31   * Tests for {@link Author} 
32   * @author Richard Cyganiak
33   * @version $Id: AuthorTest.java,v 1.8 2008/04/02 11:22:15 benoitx Exp $
34   */
35  public class AuthorTest extends TestCase {
36  
37      /**
38       * Constructor
39       * @param arg0 input
40       */
41      public AuthorTest(final String arg0) {
42          super(arg0);
43      }
44  
45      public void testCreation() {
46          final Author author = new Author("author1");
47          assertEquals("author1", author.getName());
48          assertTrue(author.getDirectories().isEmpty());
49          assertTrue(author.getRevisions().isEmpty());
50      }
51  
52      public void testCompare() {
53          final Author author1 = new Author("author1");
54          final Author author2 = new Author("author2");
55          assertEquals(-1, author1.compareTo(author2));
56          assertEquals(1, author2.compareTo(author1));
57          assertEquals(0, author2.compareTo(author2));
58      }
59  
60      public void testDirectories() {
61          final Author author1 = new Author("author1");
62          final Author author2 = new Author("author2");
63          final Date date = new Date(100000000);
64          final Directory root = Directory.createRoot();
65          final Directory dir1 = root.createSubdirectory("dir1");
66          final Directory dir2 = root.createSubdirectory("dir2");
67          final Directory dir3 = root.createSubdirectory("dir3");
68          final Directory dir1subdir = dir1.createSubdirectory("subdir");
69          final VersionedFile file1 = new VersionedFile("dir1/file", dir1);
70          final VersionedFile file2 = new VersionedFile("dir2/file", dir2);
71          final VersionedFile file3 = new VersionedFile("dir3/file", dir3);
72          final VersionedFile file4 = new VersionedFile("dir1/subdir/file", dir1subdir);
73          new Revision(file1, "1.1", Revision.TYPE_CREATION, author2, date, null, 0, 0, 0, null);
74          new Revision(file2, "1.2", Revision.TYPE_CHANGE, author1, date, null, 0, 0, 0, null);
75          new Revision(file2, "1.1", Revision.TYPE_CREATION, author1, date, null, 0, 0, 0, null);
76          new Revision(file3, "1.1", Revision.TYPE_CREATION, author2, date, null, 0, 0, 0, null);
77          new Revision(file4, "1.1", Revision.TYPE_CREATION, author1, date, null, 0, 0, 0, null);
78          assertTrue(author1.getDirectories().contains(dir2));
79          assertTrue(author1.getDirectories().contains(dir1subdir));
80          assertEquals(2, author1.getDirectories().size());
81          assertTrue(author2.getDirectories().contains(dir1));
82          assertTrue(author2.getDirectories().contains(dir3));
83          assertEquals(2, author2.getDirectories().size());
84      }
85  
86      public void testRevisions() {
87          final Author author = new Author("author1");
88          final Directory root = Directory.createRoot();
89          final Date date1 = new Date(100000000);
90          final Date date2 = new Date(200000000);
91          final Date date3 = new Date(300000000);
92          final VersionedFile file1 = new VersionedFile("file1", root);
93          final VersionedFile file2 = new VersionedFile("file2", root);
94          final Revision rev13 = new Revision(file1, "1.3", Revision.TYPE_CHANGE, author, date3, null, 0, 0, 0, null);
95          final Revision rev12 = new Revision(file1, "1.2", Revision.TYPE_CHANGE, author, date2, null, 0, 0, 0, null);
96          final Revision rev11 = new Revision(file1, "1.1", Revision.TYPE_CREATION, author, date1, null, 0, 0, 0, null);
97          final Revision rev21 = new Revision(file2, "1.1", Revision.TYPE_CREATION, author, date2, null, 0, 0, 0, null);
98          final Iterator it = author.getRevisions().iterator();
99          assertTrue(it.hasNext());
100         assertSame(rev11, it.next());
101         assertTrue(it.hasNext());
102         final Revision r1 = (Revision) it.next();
103         assertTrue(r1 == rev12 || r1 == rev21);
104         assertTrue(it.hasNext());
105         final Revision r2 = (Revision) it.next();
106         assertTrue(r2 == rev12 || r2 == rev21);
107         assertTrue(r1 != r2);
108         assertTrue(it.hasNext());
109         assertSame(rev13, it.next());
110         assertTrue(!it.hasNext());
111     }
112 }