Mercurial > hg > thermostat
changeset 2529:753e5d12c580
Avoid hardcoded date formats in NotificationsCommandTest
Reviewed-by: jkang
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2016-November/021656.html
author | Andrew Azores <aazores@redhat.com> |
---|---|
date | Wed, 16 Nov 2016 16:06:11 -0500 |
parents | 3c990cdff9ad |
children | 5c934ebd3c92 |
files | vm-jmx/client-cli/src/test/java/com/redhat/thermostat/vm/jmx/client/cli/NotificationsCommandTest.java |
diffstat | 1 files changed, 20 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/vm-jmx/client-cli/src/test/java/com/redhat/thermostat/vm/jmx/client/cli/NotificationsCommandTest.java Fri Oct 28 15:24:30 2016 -0400 +++ b/vm-jmx/client-cli/src/test/java/com/redhat/thermostat/vm/jmx/client/cli/NotificationsCommandTest.java Wed Nov 16 16:06:11 2016 -0500 @@ -70,6 +70,7 @@ import java.io.InputStream; import java.io.PrintStream; import java.util.Collections; +import java.util.Date; import java.util.List; import static org.hamcrest.CoreMatchers.is; @@ -86,8 +87,18 @@ public class NotificationsCommandTest { - private static final String NOTIFICATION_OUTPUT = "[31-Dec-1969 7:00:00 EST PM] (notification source details) : notification contents"; - private static final String FAR_FUTURE_NOTIFICATION_OUTPUT = "[17-Aug-292278994 2:12:55 EST AM] (notification source details) : notification contents"; + private static final long TIMESTAMP = 110L; + private static final long FUTURE_TIMESTAMP = Long.MAX_VALUE; + + private static final String NOTIFICATION_OUTPUT; + private static final String FAR_FUTURE_NOTIFICATION_OUTPUT; + + static { + String timestampString = Clock.DEFAULT_DATE_FORMAT.format(new Date(TIMESTAMP)); + NOTIFICATION_OUTPUT = "[" + timestampString + "] (notification source details) : notification contents"; + String futureTimestampString = Clock.DEFAULT_DATE_FORMAT.format(new Date(FUTURE_TIMESTAMP)); + FAR_FUTURE_NOTIFICATION_OUTPUT = "[" + futureTimestampString + "] (notification source details) : notification contents"; + } private static final String JMX_NOTIFICATION_MONITORING_ENABLED = "JMX notification monitoring enabled"; private static final String PRESS_ANY_KEY_TO_EXIT_FOLLOW_MODE = "Press any key to exit follow mode..."; @@ -214,7 +225,7 @@ jmxNotificationStatus.setEnabled(true); jmxNotification = new JmxNotification(FOO_AGENTID); jmxNotification.setVmId(FOO_VMID); - jmxNotification.setTimeStamp(110L); + jmxNotification.setTimeStamp(TIMESTAMP); jmxNotification.setContents("notification contents"); jmxNotification.setSourceBackend("jmxBackend"); jmxNotification.setSourceDetails("notification source details"); @@ -295,7 +306,7 @@ @Test public void testEnableWithFollowOption() throws CommandException, IOException { jmxNotificationStatus.setEnabled(false); - jmxNotification.setTimeStamp(Long.MAX_VALUE); + jmxNotification.setTimeStamp(FUTURE_TIMESTAMP); when(args.getNonOptionArguments()).thenReturn(Collections.singletonList(ENABLE_SUBCOMMAND)); when(args.hasArgument(FOLLOW_OPTION)).thenReturn(true); @@ -312,7 +323,7 @@ @Test public void testEnableWithFollowOptionWhenAlreadyEnabled() throws CommandException, IOException { - jmxNotification.setTimeStamp(Long.MAX_VALUE); + jmxNotification.setTimeStamp(FUTURE_TIMESTAMP); when(args.getNonOptionArguments()).thenReturn(Collections.singletonList(ENABLE_SUBCOMMAND)); when(args.hasArgument(FOLLOW_OPTION)).thenReturn(true); @@ -330,7 +341,7 @@ @Test public void testEnableWithFollowOptionWithExternalInterrupt() throws CommandException, IOException { jmxNotificationStatus.setEnabled(false); - jmxNotification.setTimeStamp(Long.MAX_VALUE); + jmxNotification.setTimeStamp(FUTURE_TIMESTAMP); when(args.getNonOptionArguments()).thenReturn(Collections.singletonList(ENABLE_SUBCOMMAND)); when(args.hasArgument(FOLLOW_OPTION)).thenReturn(true); @@ -350,7 +361,7 @@ @Test public void testFollowWhenDisabled() throws CommandException { jmxNotificationStatus.setEnabled(false); - jmxNotification.setTimeStamp(Long.MAX_VALUE); + jmxNotification.setTimeStamp(FUTURE_TIMESTAMP); when(args.getNonOptionArguments()).thenReturn(Collections.singletonList(FOLLOW_SUBCOMMAND)); assertThat(runCommandForOutput(), is("JMX notification monitoring is not enabled for this JVM - notifications cannot be followed")); @@ -358,7 +369,7 @@ @Test public void testFollowWhenEnabled() throws CommandException, IOException { - jmxNotification.setTimeStamp(Long.MAX_VALUE); + jmxNotification.setTimeStamp(FUTURE_TIMESTAMP); when(args.getNonOptionArguments()).thenReturn(Collections.singletonList(FOLLOW_SUBCOMMAND)); doFollowTestWithKeyboardInterrupt(); @@ -372,7 +383,7 @@ @Test public void testFollowWithExternalInterrupt() throws CommandException, IOException { - jmxNotification.setTimeStamp(Long.MAX_VALUE); + jmxNotification.setTimeStamp(FUTURE_TIMESTAMP); when(args.getNonOptionArguments()).thenReturn(Collections.singletonList(FOLLOW_SUBCOMMAND)); doFollowTestWithExternalMonitoringInterrupt();