Test against one suspected case of #1424

This commit is contained in:
Risto Lahtela 2020-05-04 20:10:02 +03:00
parent 5570a2b938
commit 18e8ccca95

View File

@ -25,20 +25,20 @@ import utilities.TestConstants;
import java.util.Optional;
import java.util.UUID;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.*;
class SessionCacheTest {
private Session session;
private final UUID uuid = TestConstants.PLAYER_ONE_UUID;
private final UUID serverUUID = TestConstants.SERVER_UUID;
private SessionCache sessionCache;
@BeforeEach
void setUp() {
session = new Session(uuid, serverUUID, 12345L, "World1", "SURVIVAL");
SessionCache sessionCache = new SessionCache();
sessionCache = new SessionCache();
sessionCache.cacheSession(uuid, session);
}
@ -53,4 +53,24 @@ class SessionCacheTest {
assertTrue(cachedSession.isPresent());
assertEquals(session, cachedSession.get());
}
@Test
void sessionsAreRemovedFromCacheOnEnd() {
Optional<Session> ended = new SessionCache().endSession(uuid, System.currentTimeMillis());
assertTrue(ended.isPresent());
for (Session session : SessionCache.getActiveSessions().values()) {
fail("Session was still in cache: " + session);
}
}
@Test
void sessionsAreRemovedFromCacheOnStart() {
Optional<Session> ended = new SessionCache().cacheSession(uuid, new Session(uuid, serverUUID, 52345L, "World1", "SURVIVAL"));
assertTrue(ended.isPresent());
for (Session session : SessionCache.getActiveSessions().values()) {
if (session.getDate() == 12345L) {
fail("Session was still in cache: " + session);
}
}
}
}