@@ -508,8 +508,8 @@ void testSplitsWithStringLabels() {
508508 final String secondLabel = "two" ;
509509 final String thirdLabel = "three" ;
510510 final int firstSleepTime = 400 ;
511- final int secondSleepTime = 200 ;
512- final int thirdSleepTime = 100 ;
511+ final int secondSleepTime = 300 ;
512+ final int thirdSleepTime = 200 ;
513513 watch .start ();
514514 ThreadUtils .sleepQuietly (Duration .ofMillis (50 ));
515515
@@ -520,7 +520,7 @@ void testSplitsWithStringLabels() {
520520 watch .split (thirdLabel );
521521 ThreadUtils .sleepQuietly (Duration .ofMillis (thirdSleepTime ));
522522
523- List <StopWatch .Split > splits = watch .getProcessedSplits ();
523+ final List <StopWatch .Split > splits = watch .getProcessedSplits ();
524524
525525 // check sizes
526526 assertEquals (3 , splits .size ());
@@ -531,19 +531,19 @@ void testSplitsWithStringLabels() {
531531 assertEquals (splits .get (2 ).getLabel (), thirdLabel );
532532
533533 // check duration
534- final int margin = 20 ;
535- assertTrue ( splits . get ( 0 ). getDuration () >= 400 && splits .get (0 ).getDuration () < 400 + margin );
536- assertTrue ( splits . get ( 1 ). getDuration () >= 200 && splits .get (1 ).getDuration () < 200 + margin );
537- assertTrue ( splits . get ( 2 ). getDuration () >= 100 && splits .get (2 ).getDuration () < 100 + margin );
534+ final int margin = 200 ;
535+ assertEquals ( firstSleepTime , splits .get (0 ).getDuration (), margin );
536+ assertEquals ( secondSleepTime , splits .get (1 ).getDuration (), margin );
537+ assertEquals ( thirdSleepTime , splits .get (2 ).getDuration (), margin );
538538
539539 // check report
540- String report = watch .getReport ();
541- String updatedReport = report .replaceAll ("4\\ d\\ d" , "4**" ).replaceAll ("2 \\ d\\ d" , "2 **" ).replaceAll ("1 \\ d\\ d" , "1 **" );
540+ final String report = watch .getReport ();
541+ final String updatedReport = report .replaceAll ("4\\ d\\ d" , "4**" ).replaceAll ("3 \\ d\\ d" , "3 **" ).replaceAll ("2 \\ d\\ d" , "2 **" );
542542
543543 assertEquals (
544- " \n one 00:00:00.4**" +
545- " \n two 00:00:00.2 **" +
546- " \n three 00:00:00.1 **" ,
544+ System . lineSeparator () + "one 00:00:00.4**" +
545+ System . lineSeparator () + "two 00:00:00.3 **" +
546+ System . lineSeparator () + "three 00:00:00.2 **" ,
547547 updatedReport
548548 );
549549 }
@@ -555,8 +555,8 @@ void testSplitsWithIntLabels() {
555555 final int secondLabel = 2 ;
556556 final int thirdLabel = 3 ;
557557 final int firstSleepTime = 400 ;
558- final int secondSleepTime = 200 ;
559- final int thirdSleepTime = 100 ;
558+ final int secondSleepTime = 300 ;
559+ final int thirdSleepTime = 200 ;
560560 watch .start ();
561561 ThreadUtils .sleepQuietly (Duration .ofMillis (50 ));
562562
@@ -567,7 +567,7 @@ void testSplitsWithIntLabels() {
567567 watch .split (thirdLabel );
568568 ThreadUtils .sleepQuietly (Duration .ofMillis (thirdSleepTime ));
569569
570- List <StopWatch .Split > splits = watch .getProcessedSplits ();
570+ final List <StopWatch .Split > splits = watch .getProcessedSplits ();
571571
572572 // check sizes
573573 assertEquals (3 , splits .size ());
@@ -578,19 +578,19 @@ void testSplitsWithIntLabels() {
578578 assertEquals (splits .get (2 ).getLabel (), String .valueOf (thirdLabel ));
579579
580580 // check duration
581- final int margin = 20 ;
582- assertTrue ( splits . get ( 0 ). getDuration () >= 400 && splits .get (0 ).getDuration () < 400 + margin );
583- assertTrue ( splits . get ( 1 ). getDuration () >= 200 && splits .get (1 ).getDuration () < 200 + margin );
584- assertTrue ( splits . get ( 2 ). getDuration () >= 100 && splits .get (2 ).getDuration () < 100 + margin );
581+ final int margin = 200 ;
582+ assertEquals ( firstSleepTime , splits .get (0 ).getDuration (), margin );
583+ assertEquals ( secondSleepTime , splits .get (1 ).getDuration (), margin );
584+ assertEquals ( thirdSleepTime , splits .get (2 ).getDuration (), margin );
585585
586586 // check report
587- String report = watch .getReport ();
588- String updatedReport = report .replaceAll ("4\\ d\\ d" , "4**" ).replaceAll ("2 \\ d\\ d" , "2 **" ).replaceAll ("1 \\ d\\ d" , "1 **" );
587+ final String report = watch .getReport ();
588+ final String updatedReport = report .replaceAll ("4\\ d\\ d" , "4**" ).replaceAll ("3 \\ d\\ d" , "3 **" ).replaceAll ("2 \\ d\\ d" , "2 **" );
589589
590590 assertEquals (
591- " \n 1 00:00:00.4**" +
592- " \n 2 00:00:00.2 **" +
593- " \n 3 00:00:00.1 **" ,
591+ System . lineSeparator () + "1 00:00:00.4**" +
592+ System . lineSeparator () + "2 00:00:00.3 **" +
593+ System . lineSeparator () + "3 00:00:00.2 **" ,
594594 updatedReport
595595 );
596596 }
@@ -600,28 +600,27 @@ void testNanoSplitsWithLabel() {
600600 final StopWatch watch = StopWatch .createStarted ();
601601
602602 watch .split ("coding" );
603- ThreadUtils .sleepQuietly (Duration .ofMillis (100 ));
603+ ThreadUtils .sleepQuietly (Duration .ofMillis (200 ));
604604
605605 watch .split ("eating" );
606- ThreadUtils .sleepQuietly (Duration .ofMillis (200 ));
606+ ThreadUtils .sleepQuietly (Duration .ofMillis (300 ));
607607
608- List <StopWatch .Split > splits = watch .getNanoProcessedSplits ();
608+ final List <StopWatch .Split > splits = watch .getNanoProcessedSplits ();
609609
610610 // check sizes
611611 assertEquals (2 , splits .size ());
612612
613613 // check duration
614- final int margin = 20000000 ;
615- assertTrue ( splits . get ( 0 ). getDuration () >= 100000000 && splits .get (0 ).getDuration () < 100000000 + margin );
616- assertTrue ( splits . get ( 1 ). getDuration () >= 200000000 && splits .get (1 ).getDuration () < 200000000 + margin );
614+ final int margin = 200_000_000 ;
615+ assertEquals ( 200_000_000 , splits .get (0 ).getDuration (), margin );
616+ assertEquals ( 300_000_000 , splits .get (1 ).getDuration (), margin );
617617
618618 // check report
619- String report = watch .getNanoReport ();
620- String updatedReport = report .replaceAll (" 10 \\ d+" , " 10 *******" ).replaceAll (" 20 \\ d+" , " 20 *******" );
619+ final String report = watch .getNanoReport ();
620+ final String updatedReport = report .replaceAll (" 2 \\ d+" , " 20 *******" ).replaceAll (" 3 \\ d+" , " 30 *******" );
621621
622- assertEquals (
623- "\n coding 10*******" +
624- "\n eating 20*******" ,
622+ assertEquals (System .lineSeparator () + "coding 20*******" +
623+ System .lineSeparator () + "eating 30*******" ,
625624 updatedReport
626625 );
627626 }
0 commit comments