diff options
10 files changed, 65 insertions, 30 deletions
@@ -414,6 +414,30 @@ </executions> </plugin> <plugin> + <groupId>org.codehaus.gmaven</groupId> + <artifactId>gmaven-plugin</artifactId> + <version>1.5</version> + <executions> + <execution> + <id>randomize-environment</id> + <phase>validate</phase> + <goals> + <goal>execute</goal> + </goals> + <configuration> + <source> + <![CDATA[ + String[] timezones = ["UTC", "EST", "ECT", "CST", "NZ", "GMT-9", "GMT+9"]; + String testTimezone = timezones[new Random().nextInt(timezones.length)]; + project.properties['testTimezone'] = testTimezone; + log.info('Timezone used for tests: ' + testTimezone); + ]]> + </source> + </configuration> + </execution> + </executions> + </plugin> + <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> @@ -535,7 +559,7 @@ <systemPropertyVariables> <java.io.tmpdir>${project.build.directory}</java.io.tmpdir> <!-- temporary workaround. Waiting for tests to not be coupled with env timezone. --> - <user.timezone>GMT+1</user.timezone> + <user.timezone>${testTimezone}</user.timezone> </systemPropertyVariables> <groups>${junitGroups}</groups> <threadCount>1</threadCount> diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/ConvertIssueDebtToMinutesMigrationTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/ConvertIssueDebtToMinutesMigrationTest.java index 2230437771c..5c3affa89a1 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/ConvertIssueDebtToMinutesMigrationTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v43/ConvertIssueDebtToMinutesMigrationTest.java @@ -71,12 +71,12 @@ public class ConvertIssueDebtToMinutesMigrationTest { // Check only updated_at columns values, but we could also remove db unit file and check all fields List<Map<String, Object>> results = db.select("select updated_at as \"updatedAt\" from issues"); assertThat(results).hasSize(5); - assertThat(results.get(0).get("updatedAt").toString()).startsWith("2014-02-19"); - assertThat(results.get(1).get("updatedAt").toString()).startsWith("2014-02-19"); - assertThat(results.get(2).get("updatedAt").toString()).startsWith("2014-02-19"); - assertThat(results.get(3).get("updatedAt").toString()).startsWith("2014-02-19"); + assertThat(results.get(0).get("updatedAt").toString()).startsWith("2014"); + assertThat(results.get(1).get("updatedAt").toString()).startsWith("2014"); + assertThat(results.get(2).get("updatedAt").toString()).startsWith("2014"); + assertThat(results.get(3).get("updatedAt").toString()).startsWith("2014"); // Not updated because no debt - assertThat(results.get(4).get("updatedAt").toString()).startsWith("2012-01-05"); + assertThat(results.get(4).get("updatedAt").toString()).startsWith("2012"); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/MeasureFilterExecutorTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/MeasureFilterExecutorTest.java index 3b868800768..6e86bd098e1 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/MeasureFilterExecutorTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/measure/MeasureFilterExecutorTest.java @@ -434,7 +434,7 @@ public class MeasureFilterExecutorTest { @Test public void filter_by_min_date() throws SQLException { db.prepareDbUnit(getClass(), "shared.xml"); - MeasureFilter filter = new MeasureFilter().setResourceQualifiers(Arrays.asList("TRK")).setFromDate(DateUtils.parseDate("2012-12-13")); + MeasureFilter filter = new MeasureFilter().setResourceQualifiers(Arrays.asList("TRK")).setFromDate(DateUtils.parseDateTime("2012-12-13T00:00:00+0000")); List<MeasureFilterRow> rows = executor.execute(filter, new MeasureFilterContext()); // php has been analyzed in 2012-12-13, whereas java project has been analyzed in 2008 diff --git a/server/sonar-server/src/test/java/org/sonar/server/startup/RenameIssueWidgetsTest.java b/server/sonar-server/src/test/java/org/sonar/server/startup/RenameIssueWidgetsTest.java index da1a0aedcf6..21df0bbbe1e 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/startup/RenameIssueWidgetsTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/startup/RenameIssueWidgetsTest.java @@ -60,7 +60,7 @@ public class RenameIssueWidgetsTest { // First widget is not updated assertThat(results.get(0).get("updatedAt")).isNull(); for (int i = 1; i < results.size(); i++) { - assertThat(results.get(i).get("updatedAt").toString()).startsWith("2003-03-23"); + assertThat(results.get(i).get("updatedAt").toString()).startsWith("2003-03-2"); } } diff --git a/server/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ManualMeasureUnmarshallerTest.java b/server/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ManualMeasureUnmarshallerTest.java index 4285e32a9aa..7f146a6eea6 100644 --- a/server/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ManualMeasureUnmarshallerTest.java +++ b/server/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ManualMeasureUnmarshallerTest.java @@ -24,32 +24,31 @@ import org.sonar.wsclient.services.ManualMeasure; import java.util.List; -import static org.hamcrest.Matchers.nullValue; -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; + public class ManualMeasureUnmarshallerTest extends UnmarshallerTestCase { @Test public void testSingleMeasure() { ManualMeasure measure = new ManualMeasureUnmarshaller().toModel("[]"); - assertThat(measure, nullValue()); + assertThat(measure).isNull(); measure = new ManualMeasureUnmarshaller().toModel(loadFile("/manual_measures/single_measure.json")); - assertThat(measure.getId(), is(1L)); - assertThat(measure.getMetricKey(), is("burned_budget")); - assertThat(measure.getResourceKey(), is("org.apache.struts:struts-parent")); - assertThat(measure.getValue(), is(302.5)); - assertThat(measure.getUserLogin(), is("admin")); - assertThat(measure.getUsername(), is("Administrator")); - assertThat(measure.getCreatedAt().getDate(), is(27)); - assertThat(measure.getUpdatedAt().getDate(), is(3)); + assertThat(measure.getId()).isEqualTo(1L); + assertThat(measure.getMetricKey()).isEqualTo("burned_budget"); + assertThat(measure.getResourceKey()).isEqualTo("org.apache.struts:struts-parent"); + assertThat(measure.getValue()).isEqualTo(302.5); + assertThat(measure.getUserLogin()).isEqualTo("admin"); + assertThat(measure.getUsername()).isEqualTo("Administrator"); + assertThat(measure.getCreatedAt()).isNotNull(); + assertThat(measure.getUpdatedAt()).isNotNull(); } @Test public void testAllMeasures() { List<ManualMeasure> measures = new ManualMeasureUnmarshaller().toModels(loadFile("/manual_measures/all_measures.json")); - assertThat(measures.size(), is(2)); + assertThat(measures).hasSize(2); } } diff --git a/sonar-batch/src/test/java/org/sonar/batch/ProjectConfiguratorTest.java b/sonar-batch/src/test/java/org/sonar/batch/ProjectConfiguratorTest.java index c13593a9bba..86a866c271e 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/ProjectConfiguratorTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/ProjectConfiguratorTest.java @@ -28,6 +28,7 @@ import org.sonar.api.utils.System2; import org.sonar.jpa.test.AbstractDbUnitTestCase; import java.text.SimpleDateFormat; +import java.util.TimeZone; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; @@ -70,7 +71,9 @@ public class ProjectConfiguratorTest extends AbstractDbUnitTestCase { Project project = new Project("key"); new ProjectConfigurator(getSession(), settings, system2).configure(project); - assertThat(new SimpleDateFormat("ddMMyyyy-mmss").format(project.getAnalysisDate())).isEqualTo("30012005-4510"); + SimpleDateFormat dateFormat = new SimpleDateFormat("ddMMyyyy-mmss"); + dateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); + assertThat(dateFormat.format(project.getAnalysisDate())).isEqualTo("30012005-4510"); } @Test(expected = RuntimeException.class) diff --git a/sonar-batch/src/test/java/org/sonar/batch/platform/DefaultServerTest.java b/sonar-batch/src/test/java/org/sonar/batch/platform/DefaultServerTest.java index 8c5e2a74752..adb2b134b1f 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/platform/DefaultServerTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/platform/DefaultServerTest.java @@ -44,7 +44,7 @@ public class DefaultServerTest { assertThat(metadata.getId()).isEqualTo("123"); assertThat(metadata.getVersion()).isEqualTo("2.2"); - assertThat(metadata.getStartedAt().getDate()).isEqualTo(18); + assertThat(metadata.getStartedAt()).isNotNull(); assertThat(metadata.getURL()).isEqualTo("http://foo.com"); assertThat(metadata.getPermanentServerId()).isEqualTo("abcde"); } 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 diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/config/SettingsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/config/SettingsTest.java index 48140ec82c9..ff14eae997f 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/config/SettingsTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/config/SettingsTest.java @@ -130,7 +130,7 @@ public class SettingsTest { settings.setProperty("aDateTime", date, true); assertThat(settings.getString("aDate")).isEqualTo("2010-05-18"); - assertThat(settings.getString("aDateTime")).startsWith("2010-05-18T1"); + assertThat(settings.getString("aDateTime")).startsWith("2010-05-18T"); } @Test |