18
18
*/
19
19
20
20
/*
21
- * Copyright (c) 2008, 2021 , Oracle and/or its affiliates. All rights reserved.
21
+ * Copyright (c) 2008, 2022 , Oracle and/or its affiliates. All rights reserved.
22
22
* Portions Copyright (c) 2018, 2019, Chris Fraire <[email protected] >.
23
23
*/
24
24
package org .opengrok .indexer .history ;
31
31
import java .net .URISyntaxException ;
32
32
import java .nio .channels .FileChannel ;
33
33
import java .util .ArrayList ;
34
+ import java .util .Arrays ;
34
35
import java .util .Collections ;
35
36
import java .util .List ;
37
+ import java .util .stream .Collectors ;
36
38
37
39
import org .junit .jupiter .api .AfterEach ;
38
40
import org .junit .jupiter .api .BeforeEach ;
@@ -113,12 +115,10 @@ public static void runCvsCommand(File reposRoot, String... args) {
113
115
}
114
116
115
117
/**
116
- * Get the CVS repository, test that getBranch() returns null if there is
117
- * no branch.
118
- * @throws Exception
118
+ * Get the CVS repository, test that getBranch() returns null if there is no branch.
119
119
*/
120
120
@ Test
121
- public void testGetBranchNoBranch () throws Exception {
121
+ void testGetBranchNoBranch () throws Exception {
122
122
setUpTestRepository ();
123
123
File root = new File (repository .getSourceRoot (), "cvs_test/cvsrepo" );
124
124
CVSRepository cvsrepo = (CVSRepository ) RepositoryFactory .getRepository (root );
@@ -131,10 +131,9 @@ public void testGetBranchNoBranch() throws Exception {
131
131
* with branch revision numbers.
132
132
* Last, check that history entries of the file follow through before the
133
133
* branch was created.
134
- * @throws Exception
135
134
*/
136
135
@ Test
137
- public void testNewBranch () throws Exception {
136
+ void testNewBranch () throws Exception {
138
137
setUpTestRepository ();
139
138
File root = new File (repository .getSourceRoot (), "cvs_test/cvsrepo" );
140
139
@@ -145,8 +144,7 @@ public void testNewBranch() throws Exception {
145
144
146
145
// Now the repository object can be instantiated so that determineBranch()
147
146
// will be called.
148
- CVSRepository cvsrepo
149
- = (CVSRepository ) RepositoryFactory .getRepository (root );
147
+ CVSRepository cvsrepo = (CVSRepository ) RepositoryFactory .getRepository (root );
150
148
151
149
assertEquals ("mybranch" , cvsrepo .getBranch ());
152
150
@@ -171,11 +169,35 @@ public void testNewBranch() throws Exception {
171
169
assertEquals ("1.1" , mainCHistory .getHistoryEntries ().get (2 ).getRevision ());
172
170
}
173
171
172
+ /**
173
+ * Assert that revision strings in history entries are sorted semantically.
174
+ * This is necessary for displaying revisions on a branch in correct order.
175
+ */
176
+ @ Test
177
+ void testRevisionSorting () {
178
+ HistoryEntry [] entries = {
179
+ new HistoryEntry ("1.1" ),
180
+ new HistoryEntry ("1.12.200.2.2.3.50.2" ),
181
+ new HistoryEntry ("1.9" ),
182
+ new HistoryEntry ("1.12.200.2.2.3" ),
183
+ new HistoryEntry ("1.2" ),
184
+ new HistoryEntry ("1.12.200.1" ),
185
+ new HistoryEntry ("1.12.200.2.2.2" ),
186
+ };
187
+ History history = new History (Arrays .stream (entries ).collect (Collectors .toList ()));
188
+ CVSHistoryParser .sortHistoryEntries (history );
189
+ List <String > revisionsActual = history .getHistoryEntries ().stream ().
190
+ map (HistoryEntry ::getRevision ).collect (Collectors .toList ());
191
+ List <String > revisionsExpected = List .of ("1.12.200.2.2.3.50.2" ,
192
+ "1.12.200.2.2.3" , "1.12.200.2.2.2" , "1.12.200.1" , "1.9" , "1.2" , "1.1" );
193
+ assertEquals (revisionsExpected , revisionsActual );
194
+ }
195
+
174
196
/**
175
197
* Test of fileHasAnnotation method, of class CVSRepository.
176
198
*/
177
199
@ Test
178
- public void testFileHasAnnotation () {
200
+ void testFileHasAnnotation () {
179
201
boolean result = instance .fileHasAnnotation (null );
180
202
assertTrue (result );
181
203
}
@@ -184,17 +206,16 @@ public void testFileHasAnnotation() {
184
206
* Test of fileHasHistory method, of class CVSRepository.
185
207
*/
186
208
@ Test
187
- public void testFileHasHistory () {
209
+ void testFileHasHistory () {
188
210
boolean result = instance .fileHasHistory (null );
189
211
assertTrue (result );
190
212
}
191
213
192
214
/**
193
215
* Test of parseAnnotation method, of class CVSRepository.
194
- * @throws java.lang.Exception
195
216
*/
196
217
@ Test
197
- public void testParseAnnotation () throws Exception {
218
+ void testParseAnnotation () throws Exception {
198
219
String revId1 = "1.1" ;
199
220
String revId2 = "1.2.3" ;
200
221
String revId3 = "1.0" ;
@@ -226,5 +247,4 @@ public void testParseAnnotation() throws Exception {
226
247
assertEquals (revId2 .length (), result .getWidestRevision ());
227
248
assertEquals (fileName , result .getFilename ());
228
249
}
229
-
230
250
}
0 commit comments