1818
1919import io .microsphere .logging .Logger ;
2020import io .microsphere .logging .LoggerFactory ;
21+ import io .microsphere .util .StopWatch .Task ;
2122import org .junit .jupiter .api .BeforeEach ;
2223import org .junit .jupiter .api .Test ;
2324
2627import static java .util .concurrent .TimeUnit .MILLISECONDS ;
2728import static org .junit .jupiter .api .Assertions .assertEquals ;
2829import static org .junit .jupiter .api .Assertions .assertFalse ;
30+ import static org .junit .jupiter .api .Assertions .assertNotEquals ;
2931import static org .junit .jupiter .api .Assertions .assertNull ;
3032import static org .junit .jupiter .api .Assertions .assertSame ;
3133import static org .junit .jupiter .api .Assertions .assertThrows ;
@@ -42,11 +44,14 @@ class StopWatchTest {
4244
4345 private static final Logger logger = LoggerFactory .getLogger (StopWatchTest .class );
4446
47+ private static final String testName = "test" ;
48+
49+
4550 private StopWatch stopWatch ;
4651
4752 @ BeforeEach
4853 void setUp () {
49- stopWatch = new StopWatch ("test" );
54+ stopWatch = new StopWatch (testName );
5055 }
5156
5257 @ Test
@@ -57,12 +62,12 @@ void test() throws InterruptedException {
5762 Thread .sleep (10 );
5863 stopWatch .stop ();
5964 stopWatch .stop ();
60- StopWatch . Task currentTask = stopWatch .getCurrentTask ();
65+ Task currentTask = stopWatch .getCurrentTask ();
6166 assertNull (currentTask );
62- assertEquals ("test" , stopWatch .getId ());
67+ assertEquals (testName , stopWatch .getId ());
6368 assertEquals (0 , stopWatch .getRunningTasks ().size ());
6469 assertEquals (2 , stopWatch .getCompletedTasks ().size ());
65- StopWatch . Task task = stopWatch .getCompletedTasks ().get (1 );
70+ Task task = stopWatch .getCompletedTasks ().get (1 );
6671 assertEquals ("1" , task .getTaskName ());
6772 assertFalse (task .isReentrant ());
6873 assertTrue (task .getStartTimeNanos () > 0 );
@@ -74,18 +79,32 @@ void test() throws InterruptedException {
7479
7580 @ Test
7681 void testTask () {
77- String testName = "test" ;
78- StopWatch .Task task = start (testName );
82+ Task task = start (testName );
7983 task .stop ();
8084 assertSame (testName , task .getTaskName ());
8185 assertFalse (task .isReentrant ());
8286 assertTrue (task .getStartTimeNanos () > 0 );
8387 assertTrue (task .getElapsedNanos () > 0 );
88+ }
89+
90+ @ Test
91+ void testTaskOnEquals () {
92+ Task task = start (testName );
93+ assertEquals (task , task );
8494 assertEquals (task , start (testName ));
85- assertEquals ( task . hashCode (), start ( testName ). hashCode ());
95+ }
8696
97+ @ Test
98+ void testTaskOnNotEquals () {
99+ Task task = start (testName );
100+ assertNotEquals (task , testName );
87101 }
88102
103+ @ Test
104+ void testTaskHashCode () {
105+ Task task = start (testName );
106+ assertEquals (task .hashCode (), start (testName ).hashCode ());
107+ }
89108
90109 @ Test
91110 void testStartOnNullTaskName () {
0 commit comments