summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2014-06-20 09:48:24 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2014-06-20 09:48:33 +0200
commit59dadf101b95c690312877e2164413a6b2274606 (patch)
tree7cd59570489607a12ce04108e28a25f036ca78be /plugins
parent3e2c93fa36af82323fb0f46904c2d4e8ca3a248d (diff)
downloadsonarqube-59dadf101b95c690312877e2164413a6b2274606.tar.gz
sonarqube-59dadf101b95c690312877e2164413a6b2274606.zip
Fix compatibility of hamcrest with java 6
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/DbCleanerTestUtils.java27
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/DeleteAllFilterTest.java12
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/KeepOneFilterTest.java34
3 files changed, 29 insertions, 44 deletions
diff --git a/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/DbCleanerTestUtils.java b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/DbCleanerTestUtils.java
index 55e7d54ae1b..944c34b3e95 100644
--- a/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/DbCleanerTestUtils.java
+++ b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/DbCleanerTestUtils.java
@@ -19,8 +19,6 @@
*/
package org.sonar.plugins.dbcleaner;
-import org.hamcrest.BaseMatcher;
-import org.hamcrest.Description;
import org.sonar.api.utils.DateUtils;
import org.sonar.core.purge.PurgeableSnapshotDto;
@@ -37,25 +35,10 @@ public final class DbCleanerTestUtils {
}
public static PurgeableSnapshotDto createSnapshotWithDateTime(long snapshotId, String datetime) {
- PurgeableSnapshotDto snapshot = new PurgeableSnapshotDto();
- snapshot.setSnapshotId(snapshotId);
- snapshot.setDate(DateUtils.parseDateTime(datetime));
- return snapshot;
- }
-
- public static final class SnapshotMatcher extends BaseMatcher<PurgeableSnapshotDto> {
- long snapshotId;
-
- public SnapshotMatcher(long snapshotId) {
- this.snapshotId = snapshotId;
- }
-
- public boolean matches(Object o) {
- return ((PurgeableSnapshotDto) o).getSnapshotId() == snapshotId;
- }
-
- public void describeTo(Description description) {
- description.appendText("snapshotId").appendValue(snapshotId);
- }
+ PurgeableSnapshotDto snapshot = new PurgeableSnapshotDto();
+ snapshot.setSnapshotId(snapshotId);
+ snapshot.setDate(DateUtils.parseDateTime(datetime));
+ return snapshot;
}
+
}
diff --git a/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/DeleteAllFilterTest.java b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/DeleteAllFilterTest.java
index 5367c3675b8..12967c16951 100644
--- a/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/DeleteAllFilterTest.java
+++ b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/DeleteAllFilterTest.java
@@ -27,9 +27,7 @@ import org.sonar.plugins.dbcleaner.DbCleanerTestUtils;
import java.util.Arrays;
import java.util.List;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-import static org.hamcrest.Matchers.hasItem;
+import static org.fest.assertions.Assertions.assertThat;
public class DeleteAllFilterTest {
@@ -37,14 +35,12 @@ public class DeleteAllFilterTest {
public void shouldDeleteAllSnapshotsPriorToDate() {
Filter filter = new DeleteAllFilter(DateUtils.parseDate("2011-12-25"));
- List<PurgeableSnapshotDto> toDelete = filter.filter(Arrays.<PurgeableSnapshotDto>asList(
+ List<PurgeableSnapshotDto> toDelete = filter.filter(Arrays.asList(
DbCleanerTestUtils.createSnapshotWithDate(1L, "2010-01-01"),
DbCleanerTestUtils.createSnapshotWithDate(2L, "2010-12-25"),
DbCleanerTestUtils.createSnapshotWithDate(3L, "2012-01-01")
- ));
+ ));
- assertThat(toDelete.size(), is(2));
- assertThat(toDelete, hasItem(new DbCleanerTestUtils.SnapshotMatcher(1L)));
- assertThat(toDelete, hasItem(new DbCleanerTestUtils.SnapshotMatcher(2L)));
+ assertThat(toDelete).onProperty("snapshotId").containsOnly(1L, 2L);
}
}
diff --git a/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/KeepOneFilterTest.java b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/KeepOneFilterTest.java
index cd1624644a5..937133577cf 100644
--- a/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/KeepOneFilterTest.java
+++ b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/KeepOneFilterTest.java
@@ -19,18 +19,15 @@
*/
package org.sonar.plugins.dbcleaner.period;
-import org.hamcrest.core.IsCollectionContaining;
import org.junit.Test;
import org.sonar.api.utils.DateUtils;
import org.sonar.core.purge.PurgeableSnapshotDto;
-import org.sonar.plugins.dbcleaner.DbCleanerTestUtils;
import java.util.Arrays;
import java.util.Calendar;
import java.util.List;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
+import static org.fest.assertions.Assertions.assertThat;
import static org.sonar.plugins.dbcleaner.DbCleanerTestUtils.createSnapshotWithDate;
public class KeepOneFilterTest {
@@ -39,7 +36,7 @@ public class KeepOneFilterTest {
public void shouldOnlyOneSnapshotPerInterval() {
Filter filter = new KeepOneFilter(DateUtils.parseDate("2011-03-25"), DateUtils.parseDate("2011-08-25"), Calendar.MONTH, "month");
- List<PurgeableSnapshotDto> toDelete = filter.filter(Arrays.<PurgeableSnapshotDto>asList(
+ List<PurgeableSnapshotDto> toDelete = filter.filter(Arrays.asList(
createSnapshotWithDate(1L, "2010-01-01"), // out of scope -> keep
createSnapshotWithDate(2L, "2011-05-01"), // may -> keep
createSnapshotWithDate(3L, "2011-05-02"), // may -> to be deleted
@@ -48,9 +45,9 @@ public class KeepOneFilterTest {
createSnapshotWithDate(6L, "2012-01-01") // out of scope -> keep
));
- assertThat(toDelete.size(), is(2));
- assertThat(toDelete, IsCollectionContaining.hasItem(new DbCleanerTestUtils.SnapshotMatcher(3L)));
- assertThat(toDelete, IsCollectionContaining.hasItem(new DbCleanerTestUtils.SnapshotMatcher(4L)));
+ assertThat(toDelete).hasSize(2);
+ assertThat(getById(toDelete, 3L)).isNotNull();
+ assertThat(getById(toDelete, 4L)).isNotNull();
}
@Test
@@ -64,15 +61,24 @@ public class KeepOneFilterTest {
createSnapshotWithDate(4L, "2011-05-23") // to be deleted
));
- assertThat(toDelete.size(), is(2));
- assertThat(toDelete, IsCollectionContaining.hasItem(new DbCleanerTestUtils.SnapshotMatcher(1L)));
- assertThat(toDelete, IsCollectionContaining.hasItem(new DbCleanerTestUtils.SnapshotMatcher(4L)));
+ assertThat(toDelete).hasSize(2);
+ assertThat(getById(toDelete, 1L)).isNotNull();
+ assertThat(getById(toDelete, 4L)).isNotNull();
}
@Test
public void test_isDeletable() {
- assertThat(KeepOneFilter.isDeletable(createSnapshotWithDate(1L, "2011-05-01")), is(true));
- assertThat(KeepOneFilter.isDeletable(createSnapshotWithDate(1L, "2011-05-01").setLast(true)), is(false));
- assertThat(KeepOneFilter.isDeletable(createSnapshotWithDate(1L, "2011-05-01").setHasEvents(true)), is(false));
+ assertThat(KeepOneFilter.isDeletable(createSnapshotWithDate(1L, "2011-05-01"))).isTrue();
+ assertThat(KeepOneFilter.isDeletable(createSnapshotWithDate(1L, "2011-05-01").setLast(true))).isFalse();
+ assertThat(KeepOneFilter.isDeletable(createSnapshotWithDate(1L, "2011-05-01").setHasEvents(true))).isFalse();
+ }
+
+ private static PurgeableSnapshotDto getById(List<PurgeableSnapshotDto> snapshots, long id) {
+ for (PurgeableSnapshotDto snapshot : snapshots) {
+ if (snapshot.getSnapshotId() == id) {
+ return snapshot;
+ }
+ }
+ return null;
}
}