1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package net.sf.statcvs.input;
24
25 import java.util.Date;
26 import java.util.List;
27 import java.util.TreeSet;
28
29 import junit.framework.TestCase;
30 import net.sf.statcvs.model.Author;
31 import net.sf.statcvs.model.Commit;
32 import net.sf.statcvs.model.Directory;
33 import net.sf.statcvs.model.Revision;
34 import net.sf.statcvs.model.VersionedFile;
35
36 /**
37 * @author Anja Jentzsch
38 * @author Richard Cyganiak
39 * @version $Id: CommitListBuilderTest.java,v 1.10 2008/04/02 11:22:14 benoitx Exp $
40 */
41 public class CommitListBuilderTest extends TestCase {
42
43 private static final int DATE = 10000000;
44
45 private Revision rev1;
46 private Revision rev2;
47 private Revision rev3;
48 private Revision rev4;
49 private Revision rev4b;
50 private Revision rev5;
51 private Revision rev6;
52 private Revision rev6b;
53 private Revision rev7;
54 private Revision rev8;
55 private List commits;
56 private Author author1;
57 private Author author2;
58 private Author author3;
59
60 /**
61 * Constructor for CommitListBuilderTest.
62 * @param arg0 input argument
63 */
64 public CommitListBuilderTest(final String arg0) {
65 super(arg0);
66 }
67
68 /**
69 * @see TestCase#setUp()
70 */
71 protected void setUp() throws Exception {
72 super.setUp();
73 author1 = new Author("author1");
74 author2 = new Author("author2");
75 author3 = new Author("author3");
76 final Directory root = Directory.createRoot();
77 final VersionedFile file1 = new VersionedFile("file1", root);
78 final VersionedFile file2 = new VersionedFile("file2", root);
79 final VersionedFile file3 = new VersionedFile("file3", root);
80 final VersionedFile file4 = new VersionedFile("file4", root);
81 final VersionedFile file4b = new VersionedFile("file4b", root);
82 final VersionedFile file5 = new VersionedFile("file5", root);
83 final VersionedFile file6 = new VersionedFile("file6", root);
84 rev1 = createRevision(file1, "rev1", DATE, author1, "message1");
85 rev2 = createRevision(file2, "rev2", DATE + 100, author2, "message1");
86 rev3 = createRevision(file3, "rev3", DATE + 200, author1, "message2");
87 rev4 = createRevision(file4, "rev4", DATE + 100000, author3, "message1");
88 rev4b = createRevision(file4b, "rev4b", DATE + 100000, author1, "message1");
89 rev5 = createRevision(file5, "rev5", DATE + 200000, author1, "message1");
90 rev6 = createRevision(file6, "rev6", DATE + 250000, author2, "message1");
91 rev6b = createRevision(file6, "rev6b", DATE + 400000, author2, "message1");
92 rev7 = createRevision(file2, "rev7", DATE + 650000, author1, "message1");
93 rev8 = createRevision(file4, "rev8", DATE + 900000, author1, "message1");
94 }
95
96 /**
97 * Method testCreation.
98 */
99 public void testCreation() {
100 runBuilder(null);
101 assertEquals(0, commits.size());
102 }
103
104 /**
105 * Method testOneRevision.
106 */
107 public void testOneRevision() {
108 final Revision[] revs = { rev1 };
109 runBuilder(revs);
110 assertEquals(1, commits.size());
111 assertEquals(1, getCommit(0).getRevisions().size());
112 assertTrue(getCommit(0).getRevisions().contains(rev1));
113 }
114
115 /**
116 * Method testOneCommitMultipleRevisions.
117 */
118 public void testOneCommitMultipleRevisions() {
119 final Revision[] revs = { rev1, rev4b, rev5 };
120 runBuilder(revs);
121 assertEquals(1, commits.size());
122 assertEquals(3, getCommit(0).getRevisions().size());
123 assertTrue(getCommit(0).getRevisions().contains(rev1));
124 assertTrue(getCommit(0).getRevisions().contains(rev4b));
125 assertTrue(getCommit(0).getRevisions().contains(rev5));
126 }
127
128 /**
129 * Method testMultipleCommits.
130 */
131 public void testMultipleCommits() {
132 final Revision[] revs = { rev1, rev2, rev3 };
133 runBuilder(revs);
134 assertEquals(3, commits.size());
135 assertEquals(1, getCommit(0).getRevisions().size());
136 assertEquals(1, getCommit(1).getRevisions().size());
137 assertEquals(1, getCommit(2).getRevisions().size());
138 assertTrue(getCommit(0).getRevisions().contains(rev1));
139 assertTrue(getCommit(1).getRevisions().contains(rev2));
140 assertTrue(getCommit(2).getRevisions().contains(rev3));
141 }
142
143 /**
144 * Method testSimultaneousCommits.
145 */
146 public void testSimultaneousCommits() {
147 final Revision[] revs = { rev1, rev2, rev4, rev5, rev6 };
148 runBuilder(revs);
149 assertEquals(3, commits.size());
150 assertEquals(2, getCommit(0).getRevisions().size());
151 assertEquals(2, getCommit(1).getRevisions().size());
152 assertEquals(1, getCommit(2).getRevisions().size());
153 assertTrue(getCommit(0).getRevisions().contains(rev1));
154 assertTrue(getCommit(0).getRevisions().contains(rev5));
155 assertTrue(getCommit(1).getRevisions().contains(rev2));
156 assertTrue(getCommit(1).getRevisions().contains(rev6));
157 assertTrue(getCommit(2).getRevisions().contains(rev4));
158 }
159
160 /**
161 * Method testIsSameCommit.
162 */
163 public void testIsSameCommit() {
164 final Commit commit = new Commit(rev1);
165 assertTrue("has different author", !CommitListBuilder.isSameCommit(commit, rev2));
166 assertTrue("has different comment", !CommitListBuilder.isSameCommit(commit, rev3));
167 assertTrue("is same commit", CommitListBuilder.isSameCommit(commit, rev4b));
168 }
169
170 /**
171 * Method testIsInTimeFrame1.
172 */
173 public void testIsInTimeFrame1() {
174 final Commit commit = new Commit(rev6b);
175 assertTrue("rev5 should be in time frame", CommitListBuilder.isInTimeFrame(commit, rev5.getDate()));
176 assertTrue("rev7 should be in time frame", CommitListBuilder.isInTimeFrame(commit, rev7.getDate()));
177 assertTrue("rev1 should not be in time frame", !CommitListBuilder.isInTimeFrame(commit, rev1.getDate()));
178 assertTrue("rev8 should not be in time frame", !CommitListBuilder.isInTimeFrame(commit, rev8.getDate()));
179 }
180
181 private Commit getCommit(final int index) {
182 return (Commit) commits.get(index);
183 }
184
185 private Revision createRevision(final VersionedFile file, final String revision, final long time, final Author author, final String message) {
186 return file.addChangeRevision(revision, author, new Date(time), message, 0, 0, 0, null);
187 }
188
189 private void runBuilder(final Revision[] revisions) {
190 final TreeSet revList = new TreeSet();
191 if (revisions != null) {
192 for (int i = 0; i < revisions.length; i++) {
193 revList.add(revisions[i]);
194 }
195 }
196 commits = new CommitListBuilder(revList).createCommitList();
197 }
198 }