43
43
import java .io .IOException ;
44
44
import java .io .InputStream ;
45
45
import java .net .URISyntaxException ;
46
+ import java .net .URL ;
46
47
import java .nio .file .Files ;
47
48
import java .nio .file .Path ;
48
49
import java .nio .file .Paths ;
@@ -149,8 +150,9 @@ void testGetHistory() throws Exception {
149
150
@ Test
150
151
void testGetHistorySubdir () throws Exception {
151
152
// Add a subdirectory with some history.
152
- runHgCommand (repositoryRoot , "import" ,
153
- Paths .get (getClass ().getResource ("/history/hg-export-subdir.txt" ).toURI ()).toString ());
153
+ URL exportURL = getClass ().getResource ("/history/hg-export-subdir.txt" );
154
+ assertNotNull (exportURL );
155
+ runHgCommand (repositoryRoot , "import" , Paths .get (exportURL .toURI ()).toString ());
154
156
155
157
MercurialRepository mr = (MercurialRepository ) RepositoryFactory .getRepository (repositoryRoot );
156
158
History hist = mr .getHistory (new File (repositoryRoot , "subdir" ));
@@ -206,8 +208,9 @@ public static void runHgCommand(File reposRoot, String... args) {
206
208
@ Test
207
209
void testGetHistoryBranch () throws Exception {
208
210
// Branch the repo and add one changeset.
209
- runHgCommand (repositoryRoot , "unbundle" ,
210
- Paths .get (getClass ().getResource ("/history/hg-branch.bundle" ).toURI ()).toString ());
211
+ URL bundleURL = getClass ().getResource ("/history/hg-branch.bundle" );
212
+ assertNotNull (bundleURL );
213
+ runHgCommand (repositoryRoot , "unbundle" , Paths .get (bundleURL .toURI ()).toString ());
211
214
// Switch to the branch.
212
215
runHgCommand (repositoryRoot , "update" , "mybranch" );
213
216
@@ -249,26 +252,28 @@ void testGetHistoryBranch() throws Exception {
249
252
@ Test
250
253
void testGetHistoryGet () throws Exception {
251
254
MercurialRepository mr = (MercurialRepository ) RepositoryFactory .getRepository (repositoryRoot );
252
- String exp_str = "This will be a first novel of mine.\n "
253
- + "\n "
254
- + "Chapter 1.\n "
255
- + "\n "
256
- + "Let's write some words. It began like this:\n "
257
- + "\n "
258
- + "...\n " ;
255
+ String exp_str = """
256
+ This will be a first novel of mine.
257
+
258
+ Chapter 1.
259
+
260
+ Let's write some words. It began like this:
261
+
262
+ ...
263
+ """ ;
259
264
byte [] buffer = new byte [1024 ];
260
265
261
266
InputStream input = mr .getHistoryGet (repositoryRoot .getCanonicalPath (),
262
267
"novel.txt" , REVISIONS [0 ]);
263
268
assertNotNull (input );
264
269
265
- String str = "" ;
270
+ StringBuilder stringBuilder = new StringBuilder () ;
266
271
int len ;
267
272
while ((len = input .read (buffer )) > 0 ) {
268
- str += new String (buffer , 0 , len );
273
+ stringBuilder . append ( new String (buffer , 0 , len ) );
269
274
}
270
- assertNotSame (0 , str .length ());
271
- assertEquals (exp_str , str );
275
+ assertNotSame (0 , stringBuilder .length ());
276
+ assertEquals (exp_str , stringBuilder . toString () );
272
277
}
273
278
274
279
/**
@@ -403,8 +408,9 @@ void testGetLastHistoryEntry() throws Exception {
403
408
@ ValueSource (booleans = {true , false })
404
409
void testMergeCommits (boolean isMergeCommitsEnabled ) throws Exception {
405
410
// The bundle will add a branch and merge commit in the default branch.
406
- runHgCommand (repositoryRoot , "unbundle" ,
407
- Paths .get (getClass ().getResource ("/history/hg-merge.bundle" ).toURI ()).toString ());
411
+ URL mergeURL = getClass ().getResource ("/history/hg-merge.bundle" );
412
+ assertNotNull (mergeURL );
413
+ runHgCommand (repositoryRoot , "unbundle" , Paths .get (mergeURL .toURI ()).toString ());
408
414
runHgCommand (repositoryRoot , "update" );
409
415
410
416
RuntimeEnvironment env = RuntimeEnvironment .getInstance ();
@@ -463,7 +469,7 @@ void testAnnotationPositive(Triple<String, List<String>, List<String>> triple) t
463
469
HistoryGuru .completeAnnotationWithHistory (annotation , history , hgRepo );
464
470
List <HistoryEntry > relevantEntries = history .getHistoryEntries ().stream ().
465
471
filter (e -> annotation .getRevisions ().contains (e .getRevision ())).
466
- collect ( Collectors . toList () );
472
+ toList ();
467
473
assertFalse (relevantEntries .isEmpty ());
468
474
for (HistoryEntry entry : relevantEntries ) {
469
475
assertTrue (annotation .getRevisions ().contains (entry .getRevision ()));
@@ -485,7 +491,9 @@ void testBuildTagListEmpty() throws Exception {
485
491
MercurialRepository hgRepo = (MercurialRepository ) RepositoryFactory .getRepository (repositoryRoot );
486
492
assertNotNull (hgRepo );
487
493
hgRepo .buildTagList (new File (hgRepo .getDirectoryName ()), CommandTimeoutType .INDEXER );
488
- assertEquals (0 , hgRepo .getTagList ().size ());
494
+ Set <TagEntry > tags = hgRepo .getTagList ();
495
+ assertNotNull (tags );
496
+ assertEquals (0 , tags .size ());
489
497
IOUtils .removeRecursive (repositoryRootPath );
490
498
}
491
499
@@ -498,6 +506,7 @@ void testBuildTagListInitial() throws Exception {
498
506
assertNotNull (hgRepo );
499
507
hgRepo .buildTagList (new File (hgRepo .getDirectoryName ()), CommandTimeoutType .INDEXER );
500
508
var tags = hgRepo .getTagList ();
509
+ assertNotNull (tags );
501
510
assertEquals (1 , tags .size ());
502
511
Set <TagEntry > expectedTags = new TreeSet <>();
503
512
TagEntry tagEntry = new MercurialTagEntry (7 , "start_of_novel" );
@@ -525,8 +534,9 @@ void testBuildTagListOneMore() throws Exception {
525
534
runHgCommand (this .repositoryRoot , "clone" , this .repositoryRoot .toString (), repositoryRootPath .toString ());
526
535
527
536
// Branch the repo and add one changeset.
528
- runHgCommand (repositoryRoot , "unbundle" ,
529
- Paths .get (getClass ().getResource ("/history/hg-branch.bundle" ).toURI ()).toString ());
537
+ URL bundleURL = getClass ().getResource ("/history/hg-branch.bundle" );
538
+ assertNotNull (bundleURL );
539
+ runHgCommand (repositoryRoot , "unbundle" , Paths .get (bundleURL .toURI ()).toString ());
530
540
531
541
// Switch to the branch and add tag.
532
542
final String myBranch = "mybranch" ;
0 commit comments