use of org.hamcrest.Description in project sonarqube by SonarSource.
the class CoveragePerTestMediumTest method invalidCoverage.
@Test
public // SONAR-6183
void invalidCoverage() throws IOException {
File baseDir = createTestFiles();
File srcDir = new File(baseDir, "src");
File coverageFile = new File(srcDir, "sample.xoo.coverage");
FileUtils.write(coverageFile, "0:2\n");
exception.expect(IllegalStateException.class);
exception.expectMessage("Error processing line 1 of file");
exception.expectCause(new TypeSafeMatcher<Throwable>() {
@Override
public void describeTo(Description description) {
// nothing to do
}
@Override
protected boolean matchesSafely(Throwable item) {
return item.getMessage().contains("Line number must be strictly positive");
}
});
runTask(baseDir);
}
use of org.hamcrest.Description in project freud by LMAX-Exchange.
the class ClassByteCodeMethodMatchers method hasMethodInvocation.
public static FreudExtendedMatcher<ClassByteCodeMethod> hasMethodInvocation(final Class expectedOwner, final String expectedMethodName, final Class... expectedParamsDeclared) {
return new FreudExtendedMatcher<ClassByteCodeMethod>() {
private String expectedOwnerName;
private String[] expectedParamNames;
{
expectedOwnerName = typeEncoding(expectedOwner);
expectedParamNames = (expectedParamsDeclared.length == 0) ? EMPTY_ARGS : new String[expectedParamsDeclared.length];
for (int i = 0, size = expectedParamsDeclared.length; i < size; i++) {
expectedParamNames[i] = typeEncoding(expectedParamsDeclared[i]);
}
}
@Override
protected boolean matchesSafely(final ClassByteCodeMethod item) {
final boolean[] found = new boolean[] { false };
found[0] = false;
item.findInstruction(new AbstractInstructionVisitor() {
@Override
public void methodInvocation(final Instruction instruction, final String owner, final String methodName, final String... args) {
if (!found[0] && expectedOwnerName.equals(owner) && expectedMethodName.equals(methodName) && Arrays.equals(expectedParamNames, args)) {
found[0] = true;
}
}
});
return found[0];
}
@Override
public void describeTo(final Description description) {
description.appendText("hasMethodInvocation(" + expectedOwner.getName() + ", " + expectedMethodName + ", " + Arrays.toString(expectedParamNames) + ")");
}
};
}
use of org.hamcrest.Description in project freud by LMAX-Exchange.
the class CodeBlockMatchers method hasMethodCall.
public static FreudExtendedMatcher<CodeBlock> hasMethodCall(final String methodCall) {
return new FreudExtendedMatcher<CodeBlock>() {
private final String methodName;
private final String[] instanceReferences;
{
String[] values = methodCall.split("\\.");
instanceReferences = new String[values.length - 1];
System.arraycopy(values, 0, instanceReferences, 0, instanceReferences.length);
methodName = values[values.length - 1];
}
@Override
protected boolean matchesSafely(final CodeBlock toBeAnalysed) {
List<MethodCall> methodCallList = toBeAnalysed.getMethodCallListByMethodName(methodName);
if (methodCallList != null) {
for (MethodCall methodCall : methodCallList) {
if (Arrays.equals(instanceReferences, methodCall.getInstanceReferences())) {
return true;
}
}
}
return false;
}
@Override
public void describeTo(final Description description) {
description.appendText("HasMethodCall(" + methodCall + ")");
}
};
}
use of org.hamcrest.Description in project platform_frameworks_base by android.
the class MockUtils method checkUserRestrictions.
public static Bundle checkUserRestrictions(String... keys) {
final Bundle expected = DpmTestUtils.newRestrictions(Preconditions.checkNotNull(keys));
final Matcher<Bundle> m = new BaseMatcher<Bundle>() {
@Override
public boolean matches(Object item) {
if (item == null)
return false;
return UserRestrictionsUtils.areEqual((Bundle) item, expected);
}
@Override
public void describeTo(Description description) {
description.appendText("User restrictions=" + getRestrictionsAsString(expected));
}
};
return MockitoHamcrest.argThat(m);
}
use of org.hamcrest.Description in project neo4j by neo4j.
the class OnlineBackupCommandTest method exitCode.
private Matcher<CommandFailed> exitCode(final int expectedCode) {
return new BaseMatcher<CommandFailed>() {
@Override
public void describeTo(Description description) {
description.appendText("expected exit code ").appendValue(expectedCode);
}
@Override
public void describeMismatch(Object o, Description description) {
if (o instanceof CommandFailed) {
CommandFailed e = (CommandFailed) o;
description.appendText("but it was ").appendValue(e.code());
} else {
description.appendText("but exception is not a CommandFailed exception");
}
}
@Override
public boolean matches(Object o) {
if (o instanceof CommandFailed) {
CommandFailed e = (CommandFailed) o;
return expectedCode == e.code();
}
return false;
}
};
}
Aggregations