@@ -508,10 +508,10 @@ 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 ();
514- ThreadUtils .sleepQuietly (Duration .ofMillis (50 ));
514+ ThreadUtils .sleepQuietly (Duration .ofMillis (100 ));
515515
516516 watch .split (firstLabel );
517517 ThreadUtils .sleepQuietly (Duration .ofMillis (firstSleepTime ));
@@ -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,10 +555,10 @@ 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 ();
561- ThreadUtils .sleepQuietly (Duration .ofMillis (50 ));
561+ ThreadUtils .sleepQuietly (Duration .ofMillis (100 ));
562562
563563 watch .split (firstLabel );
564564 ThreadUtils .sleepQuietly (Duration .ofMillis (firstSleepTime ));
@@ -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,50 +578,50 @@ 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 }
597597
598598 @ Test
599599 void testNanoSplitsWithLabel () {
600600 final StopWatch watch = StopWatch .createStarted ();
601+ ThreadUtils .sleepQuietly (Duration .ofMillis (100 ));
601602
602603 watch .split ("coding" );
603- ThreadUtils .sleepQuietly (Duration .ofMillis (100 ));
604+ ThreadUtils .sleepQuietly (Duration .ofMillis (200 ));
604605
605606 watch .split ("eating" );
606- ThreadUtils .sleepQuietly (Duration .ofMillis (200 ));
607+ ThreadUtils .sleepQuietly (Duration .ofMillis (300 ));
607608
608- List <StopWatch .Split > splits = watch .getNanoProcessedSplits ();
609+ final List <StopWatch .Split > splits = watch .getNanoProcessedSplits ();
609610
610611 // check sizes
611612 assertEquals (2 , splits .size ());
612613
613614 // 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 );
615+ final int margin = 200_000_000 ;
616+ assertEquals ( 200_000_000 , splits .get (0 ).getDuration (), margin );
617+ assertEquals ( 300_000_000 , splits .get (1 ).getDuration (), margin );
617618
618619 // check report
619- String report = watch .getNanoReport ();
620- String updatedReport = report .replaceAll (" 10 \\ d+" , " 10 *******" ).replaceAll (" 20 \\ d+" , " 20 *******" );
620+ final String report = watch .getNanoReport ();
621+ final String updatedReport = report .replaceAll (" 2 \\ d+" , " 20 *******" ).replaceAll (" 3 \\ d+" , " 30 *******" );
621622
622- assertEquals (
623- "\n coding 10*******" +
624- "\n eating 20*******" ,
623+ assertEquals (System .lineSeparator () + "coding 20*******" +
624+ System .lineSeparator () + "eating 30*******" ,
625625 updatedReport
626626 );
627627 }
0 commit comments