aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2015-04-02 15:17:31 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2015-04-02 16:53:38 +0200
commitd5b84364c57fd4f1f160661e3da105527ead4c28 (patch)
tree446b481d6ff94ddc0949b4997d5b2cceeb561ed8 /sonar-core
parent9d98b11d4ed298aa9a6c312f9f34b51f32bfd481 (diff)
downloadsonarqube-d5b84364c57fd4f1f160661e3da105527ead4c28.tar.gz
sonarqube-d5b84364c57fd4f1f160661e3da105527ead4c28.zip
Use random timezone when executing tests from maven
This allows to fail-fast if a test is heavily coupled with local timezone.
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/test/java/org/sonar/core/computation/dbcleaner/period/IntervalTest.java13
-rw-r--r--sonar-core/src/test/java/org/sonar/core/i18n/DefaultI18nTest.java8
2 files changed, 15 insertions, 6 deletions
diff --git a/sonar-core/src/test/java/org/sonar/core/computation/dbcleaner/period/IntervalTest.java b/sonar-core/src/test/java/org/sonar/core/computation/dbcleaner/period/IntervalTest.java
index c04bc36662d..07b0bc19579 100644
--- a/sonar-core/src/test/java/org/sonar/core/computation/dbcleaner/period/IntervalTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/computation/dbcleaner/period/IntervalTest.java
@@ -79,7 +79,8 @@ public class IntervalTest {
DbCleanerTestUtils.createSnapshotWithDate(2L, "2011-04-13")
);
- List<Interval> intervals = Interval.group(snapshots, DateUtils.parseDate("2010-01-01"), DateUtils.parseDate("2011-12-31"), Calendar.MONTH);
+ List<Interval> intervals = Interval.group(snapshots,
+ DateUtils.parseDateTime("2010-01-01T00:00:00+0100"), DateUtils.parseDateTime("2011-12-31T00:00:00+0100"), Calendar.MONTH);
assertThat(intervals.size(), is(2));
assertThat(intervals.get(0).count(), is(1));
@@ -94,12 +95,14 @@ public class IntervalTest {
@Test
public void shouldIgnoreTimeWhenGroupingByIntervals() {
List<PurgeableSnapshotDto> snapshots = Arrays.asList(
- DbCleanerTestUtils.createSnapshotWithDateTime(1L, "2011-05-25T16:16:48+0100"),
- DbCleanerTestUtils.createSnapshotWithDateTime(2L, "2012-01-26T16:16:48+0100"),
- DbCleanerTestUtils.createSnapshotWithDateTime(3L, "2012-01-27T16:16:48+0100")
+ DbCleanerTestUtils.createSnapshotWithDateTime(1L, "2011-05-25T00:16:48+0100"),
+ DbCleanerTestUtils.createSnapshotWithDateTime(2L, "2012-01-26T00:16:48+0100"),
+ DbCleanerTestUtils.createSnapshotWithDateTime(3L, "2012-01-27T00:16:48+0100")
);
- List<Interval> intervals = Interval.group(snapshots, DateUtils.parseDate("2011-05-25"), DateUtils.parseDate("2012-01-26"), Calendar.MONTH);
+ List<Interval> intervals = Interval.group(snapshots,
+ DateUtils.parseDateTime("2011-05-25T00:00:00+0100"),
+ DateUtils.parseDateTime("2012-01-26T00:00:00+0100"), Calendar.MONTH);
assertThat(intervals.size(), is(1));
assertThat(intervals.get(0).count(), is(1));
assertThat(intervals.get(0).get().get(0).getSnapshotId(), is(2L));
diff --git a/sonar-core/src/test/java/org/sonar/core/i18n/DefaultI18nTest.java b/sonar-core/src/test/java/org/sonar/core/i18n/DefaultI18nTest.java
index d787b0e6983..b3acbde594a 100644
--- a/sonar-core/src/test/java/org/sonar/core/i18n/DefaultI18nTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/i18n/DefaultI18nTest.java
@@ -34,6 +34,7 @@ import java.net.URLClassLoader;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
+import java.util.TimeZone;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
@@ -169,13 +170,18 @@ public class DefaultI18nTest {
@Test
public void format_date_time() {
- // JVM timezone is set to UTC in this test (see method before())
+ TimeZone initialTz = TimeZone.getDefault();
+ TimeZone.setDefault(TimeZone.getTimeZone("GMT+1"));
assertThat(manager.formatDateTime(Locale.ENGLISH, DateUtils.parseDateTime("2014-01-22T19:10:03+0100"))).startsWith("Jan 22, 2014");
+ TimeZone.setDefault(initialTz);
}
@Test
public void format_date() {
+ TimeZone initialTz = TimeZone.getDefault();
+ TimeZone.setDefault(TimeZone.getTimeZone("GMT+1"));
assertThat(manager.formatDate(Locale.ENGLISH, DateUtils.parseDateTime("2014-01-22T19:10:03+0100"))).isEqualTo("Jan 22, 2014");
+ TimeZone.setDefault(initialTz);
}
@Test