use of org.hamcrest.TypeSafeMatcher in project linkki by linkki-framework.
the class OkCancelDialogTest method displayingMessage.
private Matcher<OkCancelDialog> displayingMessage(String text) {
return new TypeSafeMatcher<OkCancelDialog>() {
@Override
public void describeTo(Description description) {
description.appendText("an OkCancelDialog displaying a message with the text '");
description.appendText(text);
description.appendText("'");
}
@Override
protected boolean matchesSafely(OkCancelDialog dialog) {
@NonNull HorizontalLayout layout = dialog.getButtonArea();
LinkkiText message = (LinkkiText) layout.getComponentAt(0);
return text.contentEquals(message.getText());
}
};
}
use of org.hamcrest.TypeSafeMatcher in project firefox-tv by mozilla-mobile.
the class PinTileTests method childAtPosition.
private static Matcher<View> childAtPosition(final Matcher<View> parentMatcher, final int position) {
return new TypeSafeMatcher<View>() {
@Override
public void describeTo(Description description) {
description.appendText("Child at position " + position + " in parent ");
parentMatcher.describeTo(description);
}
@Override
public boolean matchesSafely(View view) {
ViewParent parent = view.getParent();
return parent instanceof ViewGroup && parentMatcher.matches(parent) && view.equals(((ViewGroup) parent).getChildAt(position));
}
};
}
use of org.hamcrest.TypeSafeMatcher in project vsphere-cloud-plugin by jenkinsci.
the class CloudProvisioningStateTest method logMessage.
private static Matcher<LogRecord> logMessage(final Matcher<String> messageMatcher, final Level expectedLevel, final Object... expectedArgs) {
final Matcher<Level> levelMatcher = equalTo(expectedLevel);
final Matcher<Object[]> parametersMatcher = arrayContaining(expectedArgs);
final Matcher<LogRecord> itemMatcher = new TypeSafeMatcher<LogRecord>(LogRecord.class) {
@Override
public boolean matchesSafely(LogRecord actual) {
final String actualMessage = actual.getMessage();
final Level actualLevel = actual.getLevel();
final Object[] actualParameters = actual.getParameters();
return messageMatcher.matches(actualMessage) && levelMatcher.matches(actualLevel) && parametersMatcher.matches(actualParameters);
}
@Override
public void describeTo(Description description) {
description.appendText("LogRecord(");
description.appendText("message ").appendDescriptionOf(messageMatcher);
description.appendText(" && level ").appendDescriptionOf(levelMatcher);
description.appendText(" && parameters ").appendDescriptionOf(parametersMatcher);
description.appendText(")");
}
@Override
protected void describeMismatchSafely(LogRecord actual, Description description) {
final String actualMessage = actual.getMessage();
final Level actualLevel = actual.getLevel();
final Object[] actualParameters = actual.getParameters();
description.appendText("was LogRecord(");
description.appendText("message=\"").appendValue(actualMessage);
description.appendText("\", level ").appendValue(actualLevel);
description.appendText(", parameters ").appendValueList("[", ",", "]", actualParameters);
description.appendText(")");
}
};
return itemMatcher;
}
use of org.hamcrest.TypeSafeMatcher in project goodies by sonatype.
the class FileMatchers method containsEntry.
public static Matcher<ZipFile> containsEntry(final String entryName) {
return new TypeSafeMatcher<ZipFile>() {
@Override
protected boolean matchesSafely(ZipFile item) {
Enumeration<? extends ZipEntry> entries = item.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
if (entry.getName().equals(entryName)) {
return true;
}
}
return false;
}
@Override
public void describeTo(Description description) {
description.appendText("zip archive contains entry named ");
description.appendValue(entryName);
}
@Override
protected void describeMismatchSafely(ZipFile item, Description mismatchDescription) {
mismatchDescription.appendText(" archive contained these entries:\n");
Enumeration<? extends ZipEntry> entries = item.entries();
while (entries.hasMoreElements()) {
mismatchDescription.appendValue(entries.nextElement().getName());
if (entries.hasMoreElements()) {
mismatchDescription.appendText("\n");
}
}
}
};
}
use of org.hamcrest.TypeSafeMatcher in project data-access by pentaho.
the class DatasourceResourceIT method testImportZipFile.
private void testImportZipFile(String filePath, final String expectedSchemaName, boolean annotated) throws Exception {
FormDataContentDisposition schemaFileInfo = mock(FormDataContentDisposition.class);
File f = new File(filePath);
when(schemaFileInfo.getFileName()).thenReturn(f.getName());
Mockery mockery = new Mockery();
final IPlatformImporter mockImporter = mockery.mock(IPlatformImporter.class);
mp.defineInstance(IPlatformImporter.class, mockImporter);
if (annotated) {
mockery.checking(new Expectations() {
{
exactly(2).of(mockImporter).importFile(with(match(new TypeSafeMatcher<IPlatformImportBundle>() {
public boolean matchesSafely(IPlatformImportBundle bundle) {
return true;
}
public void describeTo(Description description) {
description.appendText("bundle with zipped mondrian schema");
}
})));
}
});
} else {
mockery.checking(new Expectations() {
{
oneOf(mockImporter).importFile(with(match(new TypeSafeMatcher<IPlatformImportBundle>() {
public boolean matchesSafely(IPlatformImportBundle bundle) {
return bundle.getProperty("domain-id").equals(expectedSchemaName);
}
public void describeTo(Description description) {
description.appendText("bundle with zipped mondrian schema");
}
})));
}
});
}
AnalysisService service = new AnalysisService();
FileInputStream in = new FileInputStream(filePath);
try {
service.putMondrianSchema(in, schemaFileInfo, null, null, null, false, false, "Datasource=SampleData;overwrite=false", null);
mockery.assertIsSatisfied();
} finally {
IOUtils.closeQuietly(in);
}
}
Aggregations