Updated Branches: refs/heads/trunk e3722e9b7 -> 6343a9011
AMBARI-4243. Fix test which is specific to a timezone. Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/6343a901 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/6343a901 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/6343a901 Branch: refs/heads/trunk Commit: 6343a9011665517d5b8c84fd677b033c0151e8fc Parents: e3722e9 Author: John Speidel <[email protected]> Authored: Fri Jan 10 16:35:27 2014 -0500 Committer: John Speidel <[email protected]> Committed: Mon Jan 13 10:50:34 2014 -0500 ---------------------------------------------------------------------- .../org/apache/ambari/server/utils/TestDateUtils.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/6343a901/ambari-server/src/test/java/org/apache/ambari/server/utils/TestDateUtils.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/utils/TestDateUtils.java b/ambari-server/src/test/java/org/apache/ambari/server/utils/TestDateUtils.java index c9eed52..e250db2 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/utils/TestDateUtils.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/utils/TestDateUtils.java @@ -18,9 +18,9 @@ package org.apache.ambari.server.utils; import junit.framework.Assert; -import org.junit.Ignore; import org.junit.Test; +import java.text.*; import java.util.Calendar; import java.util.Date; import java.util.TimeZone; @@ -31,7 +31,14 @@ public class TestDateUtils { public void testConvertToReadableTime() throws Exception { Long timestamp = 1389125737000L; String readableTime = DateUtils.convertToReadableTime(timestamp); - Assert.assertEquals("2014-01-07 12:15:37", readableTime); + + // expected format with tz set to utc + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + sdf.setTimeZone(TimeZone.getTimeZone("UTC")); + + //parse using formatter with TZ=local and format using above formatter with TZ=UTC + Assert.assertEquals("2014-01-07 20:15:37", + sdf.format(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(readableTime))); } @Test
