diff --git a/src/test/java/systemtests/AddressBookSystemTest.java b/src/test/java/systemtests/AddressBookSystemTest.java index e39ad0fb9c70..7c690fd69fc7 100644 --- a/src/test/java/systemtests/AddressBookSystemTest.java +++ b/src/test/java/systemtests/AddressBookSystemTest.java @@ -16,10 +16,10 @@ import java.util.Date; import java.util.List; -import org.junit.ClassRule; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.api.io.TempDir; import guitests.guihandles.BrowserPanelHandle; @@ -46,8 +46,6 @@ * for test verification. */ public abstract class AddressBookSystemTest { - @ClassRule - public static ClockRule clockRule = new ClockRule(); @TempDir public static Path tempDir; @@ -55,6 +53,9 @@ public abstract class AddressBookSystemTest { public static final String SAVE_FILENAME_FOR_TESTING = "sampleData.json"; public static final String CONFIG_FILENAME_FOR_TESTING = "pref_testing.json"; + @RegisterExtension + public static ClockExtension clockExtension = new ClockExtension(); + private static final List COMMAND_BOX_DEFAULT_STYLE = Arrays.asList("text-input", "text-field"); private static final List COMMAND_BOX_ERROR_STYLE = Arrays.asList("text-input", "text-field", CommandBox.ERROR_STYLE_CLASS); @@ -137,7 +138,7 @@ protected void executeCommand(String command) { rememberStates(); // Injects a fixed clock before executing a command so that the time stamp shown in the status bar // after each command is predictable and also different from the previous command. - clockRule.setInjectedClockToCurrentTime(); + clockExtension.setInjectedClockToCurrentTime(); mainWindowHandle.getCommandBox().run(command); @@ -266,11 +267,11 @@ protected void assertStatusBarUnchanged() { /** * Asserts that only the sync status in the status bar was changed to the timing of - * {@code ClockRule#getInjectedClock()}, while the save location remains the same. + * {@code ClockExtension#getInjectedClock()}, while the save location remains the same. */ protected void assertStatusBarUnchangedExceptSyncStatus() { StatusBarFooterHandle handle = getStatusBarFooter(); - String timestamp = new Date(clockRule.getInjectedClock().millis()).toString(); + String timestamp = new Date(clockExtension.getInjectedClock().millis()).toString(); String expectedSyncStatus = String.format(SYNC_STATUS_UPDATED, timestamp); assertEquals(expectedSyncStatus, handle.getSyncStatus()); assertFalse(handle.isSaveLocationChanged()); diff --git a/src/test/java/systemtests/ClockRule.java b/src/test/java/systemtests/ClockExtension.java similarity index 63% rename from src/test/java/systemtests/ClockRule.java rename to src/test/java/systemtests/ClockExtension.java index 6beace668e61..9e22d670c25b 100644 --- a/src/test/java/systemtests/ClockRule.java +++ b/src/test/java/systemtests/ClockExtension.java @@ -4,9 +4,9 @@ import java.time.Instant; import java.time.ZoneId; -import org.junit.rules.TestRule; -import org.junit.runner.Description; -import org.junit.runners.model.Statement; +import org.junit.jupiter.api.extension.AfterEachCallback; +import org.junit.jupiter.api.extension.BeforeEachCallback; +import org.junit.jupiter.api.extension.ExtensionContext; import seedu.address.ui.StatusBarFooter; @@ -16,31 +16,18 @@ * At the end of the test, the rule restores the original clock. * @see Clock#fixed(Instant, ZoneId) */ -public class ClockRule implements TestRule { +public class ClockExtension implements BeforeEachCallback, AfterEachCallback { private Clock injectedClock; private final Clock originalClock = StatusBarFooter.getClock(); - protected void before() { - setInjectedClockToCurrentTime(); - } - - protected void after() { + @Override + public void afterEach(ExtensionContext context) throws Exception { StatusBarFooter.setClock(originalClock); } @Override - public Statement apply(final Statement base, final Description description) { - return new Statement() { - @Override - public void evaluate() throws Throwable { - before(); - try { - base.evaluate(); - } finally { - after(); - } - } - }; + public void beforeEach(ExtensionContext context) throws Exception { + setInjectedClockToCurrentTime(); } public Clock getInjectedClock() { @@ -54,4 +41,5 @@ public void setInjectedClockToCurrentTime() { injectedClock = Clock.fixed(Instant.now(), ZoneId.systemDefault()); StatusBarFooter.setClock(injectedClock); } + }