summaryrefslogtreecommitdiffstats
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
parent3e2c93fa36af82323fb0f46904c2d4e8ca3a248d (diff)
downloadsonarqube-59dadf101b95c690312877e2164413a6b2274606.tar.gz
sonarqube-59dadf101b95c690312877e2164413a6b2274606.zip
Fix compatibility of hamcrest with java 6
-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
-rw-r--r--sonar-core/src/test/java/org/sonar/core/purge/PurgeDaoTest.java52
4 files changed, 47 insertions, 78 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;
}
}
diff --git a/sonar-core/src/test/java/org/sonar/core/purge/PurgeDaoTest.java b/sonar-core/src/test/java/org/sonar/core/purge/PurgeDaoTest.java
index fc918286a03..fa19f41100a 100644
--- a/sonar-core/src/test/java/org/sonar/core/purge/PurgeDaoTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/purge/PurgeDaoTest.java
@@ -19,8 +19,6 @@
*/
package org.sonar.core.purge;
-import org.hamcrest.BaseMatcher;
-import org.hamcrest.Description;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.resources.Scopes;
@@ -31,9 +29,7 @@ import org.sonar.core.resource.ResourceDao;
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;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -68,7 +64,7 @@ public class PurgeDaoTest extends AbstractDaoTestCase {
@Test
public void shouldDeleteHistoricalDataOfDirectoriesAndFiles() {
setupData("shouldDeleteHistoricalDataOfDirectoriesAndFiles");
- dao.purge(new PurgeConfiguration(1L, new String[]{Scopes.DIRECTORY, Scopes.FILE}, 30));
+ dao.purge(new PurgeConfiguration(1L, new String[] {Scopes.DIRECTORY, Scopes.FILE}, 30));
checkTables("shouldDeleteHistoricalDataOfDirectoriesAndFiles", "projects", "snapshots");
}
@@ -91,10 +87,22 @@ public class PurgeDaoTest extends AbstractDaoTestCase {
setupData("shouldSelectPurgeableSnapshots");
List<PurgeableSnapshotDto> snapshots = dao.selectPurgeableSnapshots(1L);
- assertThat(snapshots, hasItem(new SnapshotMatcher(1L, true, false)));
- assertThat(snapshots, hasItem(new SnapshotMatcher(4L, false, false)));
- assertThat(snapshots, hasItem(new SnapshotMatcher(5L, false, true)));
- assertThat(snapshots.size(), is(3));
+ assertThat(snapshots).hasSize(3);
+ assertThat(getById(snapshots, 1L).isLast()).isTrue();
+ assertThat(getById(snapshots, 1L).hasEvents()).isFalse();
+ assertThat(getById(snapshots, 4L).isLast()).isFalse();
+ assertThat(getById(snapshots, 4L).hasEvents()).isFalse();
+ assertThat(getById(snapshots, 5L).isLast()).isFalse();
+ assertThat(getById(snapshots, 5L).hasEvents()).isTrue();
+ }
+
+ private static PurgeableSnapshotDto getById(List<PurgeableSnapshotDto> snapshots, long id) {
+ for (PurgeableSnapshotDto snapshot : snapshots) {
+ if (snapshot.getSnapshotId() == id) {
+ return snapshot;
+ }
+ }
+ return null;
}
@Test
@@ -117,28 +125,4 @@ public class PurgeDaoTest extends AbstractDaoTestCase {
dao.purge(new PurgeConfiguration(1L, new String[0], 0));
checkTables("should_delete_all_closed_issues", "issues", "issue_changes");
}
-
- static final class SnapshotMatcher extends BaseMatcher<PurgeableSnapshotDto> {
- long snapshotId;
- boolean isLast;
- boolean hasEvents;
-
- SnapshotMatcher(long snapshotId, boolean last, boolean hasEvents) {
- this.snapshotId = snapshotId;
- this.isLast = last;
- this.hasEvents = hasEvents;
- }
-
- public boolean matches(Object o) {
- PurgeableSnapshotDto obj = (PurgeableSnapshotDto) o;
- return obj.getSnapshotId() == snapshotId && obj.isLast() == isLast && obj.hasEvents() == hasEvents;
- }
-
- public void describeTo(Description description) {
- description
- .appendText("snapshotId").appendValue(snapshotId)
- .appendText("isLast").appendValue(isLast)
- .appendText("hasEvents").appendValue(hasEvents);
- }
- }
}