File tree Expand file tree Collapse file tree
main/java/org/apache/commons/lang3/time
test/java/org/apache/commons/lang3/time Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -689,6 +689,7 @@ public void split() {
689689 throw new IllegalStateException ("Stopwatch is not running." );
690690 }
691691 stopTimeNanos = System .nanoTime ();
692+ stopInstant = Instant .now ();
692693 splitState = SplitState .SPLIT ;
693694 splits .add (new Split (String .valueOf (splits .size ()), Duration .ofNanos (stopTimeNanos - startTimeNanos )));
694695 }
@@ -710,6 +711,7 @@ public void split(final String label) {
710711 throw new IllegalStateException ("Stopwatch is not running." );
711712 }
712713 stopTimeNanos = System .nanoTime ();
714+ stopInstant = Instant .now ();
713715 splitState = SplitState .SPLIT ;
714716 splits .add (new Split (label , Duration .ofNanos (stopTimeNanos - startTimeNanos )));
715717 }
@@ -835,5 +837,4 @@ public void unsplit() {
835837 splitState = SplitState .UNSPLIT ;
836838 splits .remove (splits .size () - 1 );
837839 }
838-
839840}
Original file line number Diff line number Diff line change 1919import static org .junit .jupiter .api .Assertions .assertEquals ;
2020import static org .junit .jupiter .api .Assertions .assertFalse ;
2121import static org .junit .jupiter .api .Assertions .assertNotEquals ;
22+ import static org .junit .jupiter .api .Assertions .assertNotNull ;
2223import static org .junit .jupiter .api .Assertions .assertNull ;
2324import static org .junit .jupiter .api .Assertions .assertThrows ;
2425import static org .junit .jupiter .api .Assertions .assertTrue ;
@@ -422,6 +423,22 @@ void testSplitsWithStringLabels() {
422423 assertThrows (IllegalStateException .class , watch ::unsplit );
423424 }
424425
426+ @ Test
427+ void testSplitGetStopInstant () {
428+ final StopWatch watch = StopWatch .createStarted ();
429+ watch .split ();
430+ assertNotNull (watch .getStopTime ());
431+ assertNotNull (watch .getStopInstant ());
432+ }
433+
434+ @ Test
435+ void testSplitWithLabelGetStopInstant () {
436+ final StopWatch watch = StopWatch .createStarted ();
437+ watch .split ("one" );
438+ assertNotNull (watch .getStopTime ());
439+ assertNotNull (watch .getStopInstant ());
440+ }
441+
425442 @ Test
426443 void testStatic () {
427444 final StopWatch watch = StopWatch .createStarted ();
You can’t perform that action at this time.
0 commit comments