From 39f367043ff3cb6eb7deaa0edd168073c83da0e7 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Fri, 16 Aug 2013 23:17:49 +0200 Subject: [PATCH] Fix tests when timezone is not GMT+2 --- .../notification/NewIssuesEmailTemplateTest.java | 15 +++++++++++++-- .../issue/internal/IssueJsonParserTest.java | 1 + .../IssueJsonParserTest/issue-with-comments.json | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/notification/NewIssuesEmailTemplateTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/notification/NewIssuesEmailTemplateTest.java index f46723272ab..9b3b1deb392 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/notification/NewIssuesEmailTemplateTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/notification/NewIssuesEmailTemplateTest.java @@ -19,12 +19,15 @@ */ package org.sonar.plugins.core.issue.notification; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.sonar.api.config.EmailSettings; import org.sonar.api.notifications.Notification; import org.sonar.plugins.emailnotifications.api.EmailMessage; +import java.util.TimeZone; + import static org.fest.assertions.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -32,12 +35,20 @@ import static org.mockito.Mockito.when; public class NewIssuesEmailTemplateTest { NewIssuesEmailTemplate template; + TimeZone initialTimeZone = TimeZone.getDefault(); @Before public void setUp() { EmailSettings settings = mock(EmailSettings.class); when(settings.getServerBaseURL()).thenReturn("http://nemo.sonarsource.org"); template = new NewIssuesEmailTemplate(settings); + TimeZone.setDefault(TimeZone.getTimeZone("GMT")); + } + + @After + public void tearDown() { + TimeZone.setDefault(initialTimeZone); + } @Test @@ -64,7 +75,7 @@ public class NewIssuesEmailTemplateTest { .setFieldValue("count", "32") .setFieldValue("projectName", "Struts") .setFieldValue("projectKey", "org.apache:struts") - .setFieldValue("projectDate", "2010-05-18T16:50:45+0200"); + .setFieldValue("projectDate", "2010-05-18T14:50:45+0000"); EmailMessage message = template.format(notification); assertThat(message.getMessageId()).isEqualTo("new-issues/org.apache:struts"); @@ -73,7 +84,7 @@ public class NewIssuesEmailTemplateTest { "Project: Struts\n" + "32 new issues\n" + "\n" + - "See it in SonarQube: http://nemo.sonarsource.org/issues/search?componentRoots=org.apache%3Astruts&createdAt=2010-05-18T16%3A50%3A45%2B0200\n"); + "See it in SonarQube: http://nemo.sonarsource.org/issues/search?componentRoots=org.apache%3Astruts&createdAt=2010-05-18T14%3A50%3A45%2B0000\n"); } @Test diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/internal/IssueJsonParserTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/internal/IssueJsonParserTest.java index a791715c7a6..725405444ab 100644 --- a/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/internal/IssueJsonParserTest.java +++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/internal/IssueJsonParserTest.java @@ -27,6 +27,7 @@ import org.sonar.wsclient.issue.*; import org.sonar.wsclient.user.User; import java.util.List; +import java.util.TimeZone; import static org.fest.assertions.Assertions.assertThat; diff --git a/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/internal/IssueJsonParserTest/issue-with-comments.json b/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/internal/IssueJsonParserTest/issue-with-comments.json index 5118aaee009..860014b2afe 100644 --- a/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/internal/IssueJsonParserTest/issue-with-comments.json +++ b/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/internal/IssueJsonParserTest/issue-with-comments.json @@ -18,7 +18,7 @@ "key": "COMMENT-2", "login": "arthur", "htmlText": "the second comment", - "createdAt": "2013-06-19T00:02:03+0100" + "createdAt": "2013-06-19T12:02:03+0100" } ] } -- 2.39.5