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;
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 {
}
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) {
- }
};
}
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;
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 {
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) {
- }
}));
}
}
*/
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;
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 {
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();
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)
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;
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 {
}
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) {
- }
};
}
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;
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"));
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;
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"));
*/
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;
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
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));
}
*/
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;
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) {
- }
}));
}