5050import java .util .ArrayList ;
5151import java .util .Arrays ;
5252import java .util .Collections ;
53+ import java .util .HashMap ;
5354import java .util .List ;
55+ import java .util .Map ;
5456import java .util .Objects ;
5557import java .util .Set ;
5658import java .util .TreeSet ;
@@ -187,15 +189,18 @@ void testGetHistoryPartial() throws Exception {
187189 * @param args {@code hg} command arguments
188190 */
189191 public static void runHgCommand (File reposRoot , String ... args ) {
190- List <String > cmdargs = new ArrayList <>();
192+ List <String > commandWithArgs = new ArrayList <>();
191193 MercurialRepository repo = new MercurialRepository ();
192194
193- cmdargs .add (repo .getRepoCommand ());
194- cmdargs .addAll (Arrays .asList (args ));
195+ commandWithArgs .add (repo .getRepoCommand ());
196+ commandWithArgs .addAll (Arrays .asList (args ));
195197
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 <snufkin@example.com>" );
201+ Executor exec = new Executor (commandWithArgs , reposRoot , env );
197202 int exitCode = exec .exec ();
198- assertEquals (0 , exitCode , "hg command '" + cmdargs + "' failed."
203+ assertEquals (0 , exitCode , "command '" + commandWithArgs + "' failed."
199204 + "\n exit code: " + exitCode
200205 + "\n stdout:\n " + exec .getOutputString ()
201206 + "\n stderr:\n " + exec .getErrorString ());
@@ -299,10 +304,7 @@ void testGetHistoryGetRenamed() throws Exception {
299304 String exp_str = "This is totally plaintext file.\n " ;
300305 byte [] buffer = new byte [1024 ];
301306
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.
306308 InputStream input = mr .getHistoryGet (repositoryRoot .getCanonicalPath (),
307309 "novel.txt" , "3" );
308310 assertNotNull (input );
@@ -350,8 +352,7 @@ void testGetHistorySinceTillNullRev() throws Exception {
350352 assertNotNull (history );
351353 assertNotNull (history .getHistoryEntries ());
352354 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 ();
355356 assertEquals (List .of (Arrays .copyOfRange (REVISIONS , 4 , REVISIONS .length )), revisions );
356357 }
357358
@@ -362,8 +363,7 @@ void testGetHistorySinceTillRevNull() throws Exception {
362363 assertNotNull (history );
363364 assertNotNull (history .getHistoryEntries ());
364365 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 ();
367367 assertEquals (List .of (Arrays .copyOfRange (REVISIONS , 0 , 3 )), revisions );
368368 }
369369
@@ -374,8 +374,7 @@ void testGetHistorySinceTillRevRev() throws Exception {
374374 assertNotNull (history );
375375 assertNotNull (history .getHistoryEntries ());
376376 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 ();
379378 assertEquals (List .of (Arrays .copyOfRange (REVISIONS , 2 , 7 )), revisions );
380379 }
381380
@@ -389,8 +388,7 @@ void testGetHistoryRenamedFileTillRev() throws Exception {
389388 assertNotNull (history );
390389 assertNotNull (history .getHistoryEntries ());
391390 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 ();
394392 assertEquals (List .of (Arrays .copyOfRange (REVISIONS , 2 , 7 )), revisions );
395393 }
396394
@@ -443,8 +441,10 @@ void testAnnotationNegative() throws Exception {
443441 }
444442
445443 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+ );
448448 }
449449
450450 @ ParameterizedTest
@@ -579,7 +579,7 @@ void testBuildTagListOneMore() throws Exception {
579579 assertNotNull (tags );
580580 assertEquals (3 , tags .size ());
581581 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 ());
583583
584584 // cleanup
585585 IOUtils .removeRecursive (repositoryRootPath );
0 commit comments