50
50
import java .util .ArrayList ;
51
51
import java .util .Arrays ;
52
52
import java .util .Collections ;
53
+ import java .util .HashMap ;
53
54
import java .util .List ;
55
+ import java .util .Map ;
54
56
import java .util .Objects ;
55
57
import java .util .Set ;
56
58
import java .util .TreeSet ;
@@ -187,15 +189,18 @@ void testGetHistoryPartial() throws Exception {
187
189
* @param args {@code hg} command arguments
188
190
*/
189
191
public static void runHgCommand (File reposRoot , String ... args ) {
190
- List <String > cmdargs = new ArrayList <>();
192
+ List <String > commandWithArgs = new ArrayList <>();
191
193
MercurialRepository repo = new MercurialRepository ();
192
194
193
- cmdargs .add (repo .getRepoCommand ());
194
- cmdargs .addAll (Arrays .asList (args ));
195
+ commandWithArgs .add (repo .getRepoCommand ());
196
+ commandWithArgs .addAll (Arrays .asList (args ));
195
197
196
- Executor exec = new Executor (cmdargs , reposRoot );
198
+ final Map <String , String > env = new HashMap <>();
199
+ // Set the user to record commits in order to prevent hg commands entering interactive mode.
200
+ env .
put (
"HGUSER" ,
"Snufkin <[email protected] >" );
201
+ Executor exec = new Executor (commandWithArgs , reposRoot , env );
197
202
int exitCode = exec .exec ();
198
- assertEquals (0 , exitCode , "hg command '" + cmdargs + "' failed."
203
+ assertEquals (0 , exitCode , "command '" + commandWithArgs + "' failed."
199
204
+ "\n exit code: " + exitCode
200
205
+ "\n stdout:\n " + exec .getOutputString ()
201
206
+ "\n stderr:\n " + exec .getErrorString ());
@@ -299,10 +304,7 @@ void testGetHistoryGetRenamed() throws Exception {
299
304
String exp_str = "This is totally plaintext file.\n " ;
300
305
byte [] buffer = new byte [1024 ];
301
306
302
- /*
303
- * In our test repository the file was renamed twice since
304
- * revision 3.
305
- */
307
+ // In our test repository the file was renamed twice since revision 3.
306
308
InputStream input = mr .getHistoryGet (repositoryRoot .getCanonicalPath (),
307
309
"novel.txt" , "3" );
308
310
assertNotNull (input );
@@ -350,8 +352,7 @@ void testGetHistorySinceTillNullRev() throws Exception {
350
352
assertNotNull (history );
351
353
assertNotNull (history .getHistoryEntries ());
352
354
assertEquals (6 , history .getHistoryEntries ().size ());
353
- List <String > revisions = history .getHistoryEntries ().stream ().map (HistoryEntry ::getRevision ).
354
- collect (Collectors .toList ());
355
+ List <String > revisions = history .getHistoryEntries ().stream ().map (HistoryEntry ::getRevision ).toList ();
355
356
assertEquals (List .of (Arrays .copyOfRange (REVISIONS , 4 , REVISIONS .length )), revisions );
356
357
}
357
358
@@ -362,8 +363,7 @@ void testGetHistorySinceTillRevNull() throws Exception {
362
363
assertNotNull (history );
363
364
assertNotNull (history .getHistoryEntries ());
364
365
assertEquals (3 , history .getHistoryEntries ().size ());
365
- List <String > revisions = history .getHistoryEntries ().stream ().map (HistoryEntry ::getRevision ).
366
- collect (Collectors .toList ());
366
+ List <String > revisions = history .getHistoryEntries ().stream ().map (HistoryEntry ::getRevision ).toList ();
367
367
assertEquals (List .of (Arrays .copyOfRange (REVISIONS , 0 , 3 )), revisions );
368
368
}
369
369
@@ -374,8 +374,7 @@ void testGetHistorySinceTillRevRev() throws Exception {
374
374
assertNotNull (history );
375
375
assertNotNull (history .getHistoryEntries ());
376
376
assertEquals (5 , history .getHistoryEntries ().size ());
377
- List <String > revisions = history .getHistoryEntries ().stream ().map (HistoryEntry ::getRevision ).
378
- collect (Collectors .toList ());
377
+ List <String > revisions = history .getHistoryEntries ().stream ().map (HistoryEntry ::getRevision ).toList ();
379
378
assertEquals (List .of (Arrays .copyOfRange (REVISIONS , 2 , 7 )), revisions );
380
379
}
381
380
@@ -389,8 +388,7 @@ void testGetHistoryRenamedFileTillRev() throws Exception {
389
388
assertNotNull (history );
390
389
assertNotNull (history .getHistoryEntries ());
391
390
assertEquals (5 , history .getHistoryEntries ().size ());
392
- List <String > revisions = history .getHistoryEntries ().stream ().map (HistoryEntry ::getRevision ).
393
- collect (Collectors .toList ());
391
+ List <String > revisions = history .getHistoryEntries ().stream ().map (HistoryEntry ::getRevision ).toList ();
394
392
assertEquals (List .of (Arrays .copyOfRange (REVISIONS , 2 , 7 )), revisions );
395
393
}
396
394
@@ -443,8 +441,10 @@ void testAnnotationNegative() throws Exception {
443
441
}
444
442
445
443
private static Stream <Triple <String , List <String >, List <String >>> provideParametersForPositiveAnnotationTest () {
446
- return Stream .of (Triple .of ("8:6a8c423f5624" , List .of ("7" , "8" ), List .of ("8:6a8c423f5624" , "7:db1394c05268" )),
447
- Triple .of ("7:db1394c05268" , List .of ("7" ), List .of ("7:db1394c05268" )));
444
+ return Stream .of (
445
+ Triple .of ("8:6a8c423f5624" , List .of ("7" , "8" ), List .of ("8:6a8c423f5624" , "7:db1394c05268" )),
446
+ Triple .of ("7:db1394c05268" , List .of ("7" ), List .of ("7:db1394c05268" ))
447
+ );
448
448
}
449
449
450
450
@ ParameterizedTest
@@ -579,7 +579,7 @@ void testBuildTagListOneMore() throws Exception {
579
579
assertNotNull (tags );
580
580
assertEquals (3 , tags .size ());
581
581
expectedTags = List .of ("start_of_novel" , newTagName , branchTagName );
582
- assertEquals (expectedTags , tags .stream ().map (TagEntry ::getTags ).collect ( Collectors . toList () ));
582
+ assertEquals (expectedTags , tags .stream ().map (TagEntry ::getTags ).toList ());
583
583
584
584
// cleanup
585
585
IOUtils .removeRecursive (repositoryRootPath );
0 commit comments