aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleExecutorTest.java21
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ManualViolationInjectorTest.java17
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/NewCoverageAggregatorTest.java25
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/DefaultPeriodCleanerTest.java20
-rw-r--r--plugins/sonar-surefire-plugin/src/test/java/org/sonar/plugins/surefire/api/AbstractSurefireParserTest.java10
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderTest.java10
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/components/TimeMachineConfigurationTest.java23
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/AbstractSourceImporterTest.java11
8 files changed, 62 insertions, 75 deletions
diff --git a/plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleExecutorTest.java b/plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleExecutorTest.java
index 6aa825974fa..f92e2259af3 100644
--- a/plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleExecutorTest.java
+++ b/plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleExecutorTest.java
@@ -23,8 +23,8 @@ import com.puppycrawl.tools.checkstyle.api.AuditEvent;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.hamcrest.BaseMatcher;
-import org.hamcrest.Description;
import org.junit.Test;
+import org.mockito.ArgumentMatcher;
import java.io.File;
import java.nio.charset.Charset;
@@ -35,7 +35,12 @@ import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static org.junit.internal.matchers.StringContains.containsString;
import static org.mockito.Matchers.anyObject;
-import static org.mockito.Mockito.*;
+import static org.mockito.Matchers.argThat;
+import static org.mockito.Mockito.atLeast;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class CheckstyleExecutorTest {
@@ -69,26 +74,22 @@ public class CheckstyleExecutorTest {
}
private BaseMatcher<AuditEvent> newErrorMatcher(final String filename, final String rule) {
- return new BaseMatcher<AuditEvent>(){
+ return new ArgumentMatcher<AuditEvent>() {
+ @Override
public boolean matches(Object o) {
AuditEvent event = (AuditEvent)o;
return StringUtils.endsWith(event.getFileName(), filename) && StringUtils.equals(event.getSourceName(), rule);
}
-
- public void describeTo(Description description) {
- }
};
}
private BaseMatcher<AuditEvent> newFilenameMatcher(final String filename) {
- return new BaseMatcher<AuditEvent>(){
+ return new ArgumentMatcher<AuditEvent>() {
+ @Override
public boolean matches(Object o) {
AuditEvent event = (AuditEvent)o;
return StringUtils.endsWith(event.getFileName(), filename);
}
-
- public void describeTo(Description description) {
- }
};
}
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ManualViolationInjectorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ManualViolationInjectorTest.java
index 2c5691ea995..984af9eae14 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ManualViolationInjectorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ManualViolationInjectorTest.java
@@ -21,9 +21,8 @@ package org.sonar.plugins.core.sensors;
import com.google.common.base.Predicate;
import com.google.common.collect.Lists;
-import org.hamcrest.BaseMatcher;
-import org.hamcrest.Description;
import org.junit.Test;
+import org.mockito.ArgumentMatcher;
import org.sonar.api.batch.DecoratorContext;
import org.sonar.api.resources.Project;
import org.sonar.api.rules.Rule;
@@ -36,7 +35,13 @@ import org.sonar.core.review.ReviewDto;
import java.util.Date;
-import static org.mockito.Mockito.*;
+import static org.mockito.Matchers.anyVararg;
+import static org.mockito.Matchers.argThat;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class ManualViolationInjectorTest {
@@ -53,15 +58,13 @@ public class ManualViolationInjectorTest {
injector.decorate(new Project("key").setId(100), context);
- verify(context, times(1)).saveViolation(argThat(new BaseMatcher<Violation>() {
+ verify(context, times(1)).saveViolation(argThat(new ArgumentMatcher<Violation>() {
+ @Override
public boolean matches(Object o) {
Violation v = (Violation) o;
return v.getPermanentId() == 100 && v.getRule() != null && v.isManual() && v.getCreatedAt().equals(createdAt)
&& v.getSeverity().equals(RulePriority.BLOCKER);
}
-
- public void describeTo(Description description) {
- }
}));
}
}
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/NewCoverageAggregatorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/NewCoverageAggregatorTest.java
index 51f17c74271..c2110f86c10 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/NewCoverageAggregatorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/NewCoverageAggregatorTest.java
@@ -19,9 +19,8 @@
*/
package org.sonar.plugins.core.timemachine;
-import org.hamcrest.BaseMatcher;
-import org.hamcrest.Description;
import org.junit.Test;
+import org.mockito.ArgumentMatcher;
import org.mockito.Matchers;
import org.sonar.api.batch.DecoratorContext;
import org.sonar.api.measures.CoreMetrics;
@@ -30,7 +29,11 @@ import org.sonar.api.measures.Measure;
import java.util.Arrays;
import java.util.Collections;
-import static org.mockito.Mockito.*;
+import static org.mockito.Matchers.argThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class NewCoverageAggregatorTest {
@@ -53,19 +56,15 @@ public class NewCoverageAggregatorTest {
aggregator.aggregate(context, CoreMetrics.NEW_LINES_TO_COVER, 3);
- verify(context).saveMeasure(argThat(new BaseMatcher<Measure>() {
+ verify(context).saveMeasure(argThat(new ArgumentMatcher<Measure>() {
+ @Override
public boolean matches(Object o) {
Measure m = (Measure)o;
return m.getVariation1()==null;
}
-
- public void describeTo(Description description) {
-
- }
}));
}
-
@Test
public void shouldSumValues() {
NewCoverageAggregator aggregator = new NewCoverageAggregator();
@@ -74,19 +73,15 @@ public class NewCoverageAggregatorTest {
aggregator.aggregate(context, CoreMetrics.NEW_LINES_TO_COVER, 3);
- verify(context).saveMeasure(argThat(new BaseMatcher<Measure>() {
+ verify(context).saveMeasure(argThat(new ArgumentMatcher<Measure>() {
+ @Override
public boolean matches(Object o) {
Measure m = (Measure)o;
return m.getVariation2()==16.0 && m.getVariation3()==2.0;
}
-
- public void describeTo(Description description) {
-
- }
}));
}
-
private Measure newMeasure(Double variation1, Double variation2, Double variation3) {
return new Measure(CoreMetrics.NEW_LINES_TO_COVER)
.setVariation1(variation1)
diff --git a/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/DefaultPeriodCleanerTest.java b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/DefaultPeriodCleanerTest.java
index c9f27bc979e..1e3aabbd571 100644
--- a/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/DefaultPeriodCleanerTest.java
+++ b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/DefaultPeriodCleanerTest.java
@@ -21,8 +21,8 @@ package org.sonar.plugins.dbcleaner.period;
import org.apache.commons.lang.ObjectUtils;
import org.hamcrest.BaseMatcher;
-import org.hamcrest.Description;
import org.junit.Test;
+import org.mockito.ArgumentMatcher;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.sonar.api.config.Settings;
@@ -33,8 +33,12 @@ import org.sonar.core.purge.PurgeableSnapshotDto;
import java.util.Arrays;
import java.util.Date;
+import static org.mockito.Matchers.anyListOf;
import static org.mockito.Matchers.argThat;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class DefaultPeriodCleanerTest {
@@ -57,26 +61,22 @@ public class DefaultPeriodCleanerTest {
}
private BaseMatcher<PurgeSnapshotQuery> newRootSnapshotQuery() {
- return new BaseMatcher<PurgeSnapshotQuery>() {
+ return new ArgumentMatcher<PurgeSnapshotQuery>() {
+ @Override
public boolean matches(Object o) {
PurgeSnapshotQuery query = (PurgeSnapshotQuery) o;
return ObjectUtils.equals(query.getRootSnapshotId(), 999L);
}
-
- public void describeTo(Description description) {
- }
};
}
private BaseMatcher<PurgeSnapshotQuery> newSnapshotIdQuery() {
- return new BaseMatcher<PurgeSnapshotQuery>() {
+ return new ArgumentMatcher<PurgeSnapshotQuery>() {
+ @Override
public boolean matches(Object o) {
PurgeSnapshotQuery query = (PurgeSnapshotQuery) o;
return ObjectUtils.equals(query.getId(), 999L);
}
-
- public void describeTo(Description description) {
- }
};
}
diff --git a/plugins/sonar-surefire-plugin/src/test/java/org/sonar/plugins/surefire/api/AbstractSurefireParserTest.java b/plugins/sonar-surefire-plugin/src/test/java/org/sonar/plugins/surefire/api/AbstractSurefireParserTest.java
index 5a7cf367a88..b85b96a7910 100644
--- a/plugins/sonar-surefire-plugin/src/test/java/org/sonar/plugins/surefire/api/AbstractSurefireParserTest.java
+++ b/plugins/sonar-surefire-plugin/src/test/java/org/sonar/plugins/surefire/api/AbstractSurefireParserTest.java
@@ -30,11 +30,11 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import org.mockito.ArgumentMatcher;
+
import java.net.URISyntaxException;
import java.util.Arrays;
-import org.hamcrest.BaseMatcher;
-import org.hamcrest.Description;
import org.junit.Test;
import org.sonar.api.batch.SensorContext;
import org.sonar.api.measures.CoreMetrics;
@@ -120,13 +120,11 @@ public class AbstractSurefireParserTest {
AbstractSurefireParser parser = newParser();
SensorContext context = mock(SensorContext.class);
- when(context.isIndexed(argThat(new BaseMatcher<Resource>() {
+ when(context.isIndexed(argThat(new ArgumentMatcher<Resource>() {
+ @Override
public boolean matches(Object o) {
return !((Resource) o).getName().contains("$");
}
-
- public void describeTo(Description description) {
- }
}), eq(false))).thenReturn(true);
parser.collect(new Project("foo"), context, getDir("innerClasses"));
diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderTest.java b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderTest.java
index 2ab6d29a945..5f03dce9160 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderTest.java
@@ -20,10 +20,9 @@
package org.sonar.batch.components;
import org.apache.commons.configuration.PropertiesConfiguration;
-import org.hamcrest.BaseMatcher;
-import org.hamcrest.Description;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.ArgumentMatcher;
import org.sonar.api.CoreProperties;
import org.sonar.api.database.model.Snapshot;
@@ -89,14 +88,11 @@ public class PastSnapshotFinderTest {
PastSnapshot variationSnapshot = finder.find(null, 2, "2010-05-18");
- verify(finderByDate).findByDate((Snapshot) anyObject(), argThat(new BaseMatcher<Date>() {
+ verify(finderByDate).findByDate((Snapshot) anyObject(), argThat(new ArgumentMatcher<Date>() {
+ @Override
public boolean matches(Object o) {
return o.equals(date);
}
-
- public void describeTo(Description description) {
-
- }
}));
assertThat(variationSnapshot.getIndex(), is(2));
assertThat(variationSnapshot.getMode(), is("date"));
diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/TimeMachineConfigurationTest.java b/sonar-batch/src/test/java/org/sonar/batch/components/TimeMachineConfigurationTest.java
index 68468e09e7e..7f378eef08a 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/components/TimeMachineConfigurationTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/components/TimeMachineConfigurationTest.java
@@ -19,6 +19,14 @@
*/
package org.sonar.batch.components;
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.junit.Test;
+import org.mockito.ArgumentMatcher;
+import org.sonar.api.CoreProperties;
+import org.sonar.api.database.model.Snapshot;
+import org.sonar.api.resources.Project;
+import org.sonar.jpa.test.AbstractDbUnitTestCase;
+
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Matchers.argThat;
@@ -27,15 +35,6 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
-import org.apache.commons.configuration.PropertiesConfiguration;
-import org.hamcrest.BaseMatcher;
-import org.hamcrest.Description;
-import org.junit.Test;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.database.model.Snapshot;
-import org.sonar.api.resources.Project;
-import org.sonar.jpa.test.AbstractDbUnitTestCase;
-
public class TimeMachineConfigurationTest extends AbstractDbUnitTestCase {
@Test
@@ -63,13 +62,11 @@ public class TimeMachineConfigurationTest extends AbstractDbUnitTestCase {
new TimeMachineConfiguration(getSession(), new Project("my:project"), conf, pastSnapshotFinder);
- verify(pastSnapshotFinder).find(argThat(new BaseMatcher<Snapshot>() {
+ verify(pastSnapshotFinder).find(argThat(new ArgumentMatcher<Snapshot>() {
+ @Override
public boolean matches(Object o) {
return ((Snapshot) o).getResourceId() == 2 /* see database in shared.xml */;
}
-
- public void describeTo(Description description) {
- }
}), eq(conf), eq(1));
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/AbstractSourceImporterTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/AbstractSourceImporterTest.java
index 59bc02e8359..8bb9f0c57f7 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/AbstractSourceImporterTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/AbstractSourceImporterTest.java
@@ -19,12 +19,12 @@
*/
package org.sonar.api.batch;
+import org.mockito.ArgumentMatcher;
+
import com.google.common.collect.Lists;
import org.apache.commons.configuration.MapConfiguration;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.lang.CharEncoding;
-import org.hamcrest.BaseMatcher;
-import org.hamcrest.Description;
import org.junit.Before;
import org.junit.Test;
import org.mockito.exceptions.verification.junit.ArgumentsAreDifferent;
@@ -132,15 +132,12 @@ public class AbstractSourceImporterTest {
importer.analyse(project, context);
- verify(context).saveSource(eq(FakeSourceImporter.TEST_RESOURCE), argThat(new BaseMatcher<String>() {
-
+ verify(context).saveSource(eq(FakeSourceImporter.TEST_RESOURCE), argThat(new ArgumentMatcher<String>() {
+ @Override
public boolean matches(Object arg0) {
String source = (String) arg0;
return source.contains(aClaess) && source.contains(explicacao);
}
-
- public void describeTo(Description arg0) {
- }
}));
}