]> source.dussan.org Git - sonarqube.git/commitdiff
Technical debt : Replace BaseMatcher with ArgumentMatcher
authorDavid Gageot <david@gageot.net>
Fri, 25 May 2012 07:09:52 +0000 (09:09 +0200)
committerDavid Gageot <david@gageot.net>
Fri, 25 May 2012 07:10:09 +0000 (09:10 +0200)
plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleExecutorTest.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ManualViolationInjectorTest.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/NewCoverageAggregatorTest.java
plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/DefaultPeriodCleanerTest.java
plugins/sonar-surefire-plugin/src/test/java/org/sonar/plugins/surefire/api/AbstractSurefireParserTest.java
sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderTest.java
sonar-batch/src/test/java/org/sonar/batch/components/TimeMachineConfigurationTest.java
sonar-plugin-api/src/test/java/org/sonar/api/batch/AbstractSourceImporterTest.java

index 6aa825974fa20f1dc4df0393c5d8ff7afc9a3c46..f92e2259af380c184bf1ca55d7f28baa5a42c436 100644 (file)
@@ -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) {
-      }
     };
   }
 
index 2c5691ea99546e11e7ebecdb8b1a6766221d14f1..984af9eae1445e61af5ae164d4452e9301a4226b 100644 (file)
@@ -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) {
-      }
     }));
   }
 }
index 51f17c74271585cc6180df8fe3a936c798a80f4f..c2110f86c10776c5205b2b25c60873825c45b2bb 100644 (file)
@@ -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)
index c9f27bc979e5529cea1e02e2cc6dd8b04e2a18d9..1e3aabbd571c02971e6ba7e2aab1a4810f53a7c9 100644 (file)
@@ -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) {
-      }
     };
   }
 
index 5a7cf367a885342c0a93faf6169a4d22a9b820ff..b85b96a7910819de70923f001183318f878f9b0f 100644 (file)
@@ -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"));
index 2ab6d29a945b1019a637d78767ea889c1574e073..5f03dce9160a24d248357cf2ec7457b0afde02d8 100644 (file)
 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"));
index 68468e09e7ef9801c09c599eb34889d0fd3ea3b1..7f378eef08ab7bc8327edd39b150b34270917519 100644 (file)
  */
 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));
   }
 
index 59bc02e835942f01a2a9f08933f6b2c7a18e4bea..8bb9f0c57f796ffd8a4df53b56dc83a123f96ff2 100644 (file)
  */
 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) {
-      }
     }));
   }