1818 */
1919
2020/*
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.
2222 * Portions Copyright (c) 2018, 2019, Chris Fraire <cfraire@me.com>.
2323 */
2424package org .opengrok .indexer .history ;
3131import java .net .URISyntaxException ;
3232import java .nio .channels .FileChannel ;
3333import java .util .ArrayList ;
34+ import java .util .Arrays ;
3435import java .util .Collections ;
3536import java .util .List ;
37+ import java .util .stream .Collectors ;
3638
3739import org .junit .jupiter .api .AfterEach ;
3840import org .junit .jupiter .api .BeforeEach ;
@@ -113,12 +115,10 @@ public static void runCvsCommand(File reposRoot, String... args) {
113115 }
114116
115117 /**
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.
119119 */
120120 @ Test
121- public void testGetBranchNoBranch () throws Exception {
121+ void testGetBranchNoBranch () throws Exception {
122122 setUpTestRepository ();
123123 File root = new File (repository .getSourceRoot (), "cvs_test/cvsrepo" );
124124 CVSRepository cvsrepo = (CVSRepository ) RepositoryFactory .getRepository (root );
@@ -131,10 +131,9 @@ public void testGetBranchNoBranch() throws Exception {
131131 * with branch revision numbers.
132132 * Last, check that history entries of the file follow through before the
133133 * branch was created.
134- * @throws Exception
135134 */
136135 @ Test
137- public void testNewBranch () throws Exception {
136+ void testNewBranch () throws Exception {
138137 setUpTestRepository ();
139138 File root = new File (repository .getSourceRoot (), "cvs_test/cvsrepo" );
140139
@@ -145,8 +144,7 @@ public void testNewBranch() throws Exception {
145144
146145 // Now the repository object can be instantiated so that determineBranch()
147146 // will be called.
148- CVSRepository cvsrepo
149- = (CVSRepository ) RepositoryFactory .getRepository (root );
147+ CVSRepository cvsrepo = (CVSRepository ) RepositoryFactory .getRepository (root );
150148
151149 assertEquals ("mybranch" , cvsrepo .getBranch ());
152150
@@ -171,11 +169,35 @@ public void testNewBranch() throws Exception {
171169 assertEquals ("1.1" , mainCHistory .getHistoryEntries ().get (2 ).getRevision ());
172170 }
173171
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+
174196 /**
175197 * Test of fileHasAnnotation method, of class CVSRepository.
176198 */
177199 @ Test
178- public void testFileHasAnnotation () {
200+ void testFileHasAnnotation () {
179201 boolean result = instance .fileHasAnnotation (null );
180202 assertTrue (result );
181203 }
@@ -184,17 +206,16 @@ public void testFileHasAnnotation() {
184206 * Test of fileHasHistory method, of class CVSRepository.
185207 */
186208 @ Test
187- public void testFileHasHistory () {
209+ void testFileHasHistory () {
188210 boolean result = instance .fileHasHistory (null );
189211 assertTrue (result );
190212 }
191213
192214 /**
193215 * Test of parseAnnotation method, of class CVSRepository.
194- * @throws java.lang.Exception
195216 */
196217 @ Test
197- public void testParseAnnotation () throws Exception {
218+ void testParseAnnotation () throws Exception {
198219 String revId1 = "1.1" ;
199220 String revId2 = "1.2.3" ;
200221 String revId3 = "1.0" ;
@@ -226,5 +247,4 @@ public void testParseAnnotation() throws Exception {
226247 assertEquals (revId2 .length (), result .getWidestRevision ());
227248 assertEquals (fileName , result .getFilename ());
228249 }
229-
230250}
0 commit comments