diff --git a/server/eclipse-project/src/main/java/us/freeandfair/corla/model/Administrator.java b/server/eclipse-project/src/main/java/us/freeandfair/corla/model/Administrator.java index 3129b458..ab1ea86f 100644 --- a/server/eclipse-project/src/main/java/us/freeandfair/corla/model/Administrator.java +++ b/server/eclipse-project/src/main/java/us/freeandfair/corla/model/Administrator.java @@ -227,9 +227,9 @@ public Instant lastLogoutTime() { */ public void updateLastLogoutTime() { if (my_clock == null) { - my_last_login_time = Instant.now(); + my_last_logout_time = Instant.now(); } else { - my_last_login_time = Instant.now(my_clock); + my_last_logout_time = Instant.now(my_clock); } } diff --git a/server/eclipse-project/src/test/java/us/freeandfair/corla/model/AdministratorTest.java b/server/eclipse-project/src/test/java/us/freeandfair/corla/model/AdministratorTest.java index 899b1c28..66e4723c 100644 --- a/server/eclipse-project/src/test/java/us/freeandfair/corla/model/AdministratorTest.java +++ b/server/eclipse-project/src/test/java/us/freeandfair/corla/model/AdministratorTest.java @@ -7,6 +7,7 @@ import java.time.Clock; import java.time.Instant; +import static org.testng.Assert.assertNotEquals; import static org.testng.AssertJUnit.*; import static us.freeandfair.corla.util.EqualsHashcodeHelper.nullableHashCode; @@ -60,6 +61,24 @@ public static void testGettersAndSetters() { ", last_logout_time=" + expectedTime + "]"; assertEquals(expected_string, admin.toString()); + + /** + * Now test an admin without a clock set. This means we can't test timing-specific things, + * but we can at least test that the code paths behave the way we expect. + */ + admin = new Administrator(expectedUsername, + expectedType, + expectedFullname, + null); + + assertNull(admin.lastLoginTime()); + assertNull(admin.lastLogoutTime()); + + admin.updateLastLoginTime(); + assertNotNull(admin.lastLoginTime()); + admin.updateLastLogoutTime(); + assertNotNull(admin.lastLogoutTime()); + assert(admin.lastLoginTime() != admin.lastLogoutTime()); } @Test