diff options
author | David Gageot <david@gageot.net> | 2012-05-25 09:09:52 +0200 |
---|---|---|
committer | David Gageot <david@gageot.net> | 2012-05-25 09:10:09 +0200 |
commit | c6dc564b20d039045b6f5ce90232c19dab520abb (patch) | |
tree | c692278d37b9e101101577efee075990b82e9230 /plugins | |
parent | 7c03664400952bb5497e07a76e4d26bd9a22b7d3 (diff) | |
download | sonarqube-c6dc564b20d039045b6f5ce90232c19dab520abb.tar.gz sonarqube-c6dc564b20d039045b6f5ce90232c19dab520abb.zip |
Technical debt : Replace BaseMatcher with ArgumentMatcher
Diffstat (limited to 'plugins')
5 files changed, 45 insertions, 48 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")); |