Skip to content

Commit e31b12b

Browse files
committed
Add Expiration Task state test (should be sleeping after it is woken)
1 parent 986130a commit e31b12b

File tree

1 file changed

+40
-3
lines changed
  • server-session/src/test/java/com.iluwatar.sessionserver

1 file changed

+40
-3
lines changed

server-session/src/test/java/com.iluwatar.sessionserver/AppTest.java

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,37 +24,74 @@
2424
*/
2525
package com.iluwatar.sessionserver;
2626

27+
import static java.lang.Thread.State.TIMED_WAITING;
2728
import static java.lang.Thread.State.WAITING;
2829
import static org.junit.jupiter.api.Assertions.assertEquals;
30+
import static org.mockito.Mockito.when;
2931

3032
import java.io.IOException;
3133
import lombok.extern.slf4j.Slf4j;
34+
import org.junit.Before;
35+
import org.junit.jupiter.api.BeforeAll;
3236
import org.junit.jupiter.api.BeforeEach;
37+
import org.junit.jupiter.api.MethodOrderer;
38+
import org.junit.jupiter.api.Order;
3339
import org.junit.jupiter.api.Test;
40+
import org.junit.jupiter.api.TestMethodOrder;
3441
import org.mockito.MockitoAnnotations;
3542

3643
/**
3744
* LoginHandlerTest.
3845
*/
3946
@Slf4j
47+
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
4048
public class AppTest {
4149

50+
/**
51+
* Start App before tests
52+
* @throws IOException
53+
*/
54+
55+
@BeforeAll
56+
public static void init() throws IOException {
57+
App.main(new String [] {});
58+
}
59+
4260
/**
4361
* Setup tests.
4462
*/
63+
4564
@BeforeEach
46-
public void setUp() throws IOException {
65+
public void setUp() {
4766
MockitoAnnotations.initMocks(this);
48-
App.main(new String [] {});
4967
}
5068

69+
/**
70+
* Run the Start state test first
71+
* Checks that the session expiration task is waiting when the app is first started
72+
*/
73+
5174
@Test
75+
@Order(1)
5276
public void expirationTaskStartStateTest() {
53-
5477
//assert
5578
LOGGER.info("Expiration Task Status: "+String.valueOf(App.getExpirationTaskState()));
5679
assertEquals(App.getExpirationTaskState(),WAITING);
80+
}
5781

82+
83+
/**
84+
* Run the wake state test second
85+
* Test whether expiration Task is currently sleeping or not (should sleep when woken)
86+
*/
87+
88+
@Test
89+
@Order(2)
90+
public void expirationTaskWakeStateTest() throws InterruptedException {
91+
App.expirationTaskWake();
92+
Thread.sleep(200); // Wait until sessionExpirationTask is sleeping
93+
LOGGER.info("Expiration Task Status: "+String.valueOf(App.getExpirationTaskState()));
94+
assertEquals(App.getExpirationTaskState(),TIMED_WAITING);
5895
}
5996

6097
}

0 commit comments

Comments
 (0)