Skip to content

Commit

Permalink
Fixing admin test so it has full coverage again
Browse files Browse the repository at this point in the history
  • Loading branch information
umbernhard committed Dec 5, 2024
1 parent 0ebf4b7 commit b1dbb99
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b1dbb99

Please sign in to comment.