use of org.hamcrest.TypeSafeMatcher in project data-access by pentaho.
the class DatasourceResourceIT method testImportFile.
private void testImportFile(String filePath, final String expectedSchemaName) throws Exception {
FormDataContentDisposition schemaFileInfo = mock(FormDataContentDisposition.class);
when(schemaFileInfo.getFileName()).thenReturn("stubFileName");
Mockery mockery = new Mockery();
final IPlatformImporter mockImporter = mockery.mock(IPlatformImporter.class);
mp.defineInstance(IPlatformImporter.class, mockImporter);
mockery.checking(new Expectations() {
{
oneOf(mockImporter).importFile(with(match(new TypeSafeMatcher<IPlatformImportBundle>() {
public boolean matchesSafely(IPlatformImportBundle bundle) {
return bundle.getProperty("domain-id").equals(expectedSchemaName) && bundle.getMimeType().equals("application/vnd.pentaho.mondrian+xml");
}
public void describeTo(Description description) {
description.appendText("bundle with 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);
}
}
use of org.hamcrest.TypeSafeMatcher in project collect by getodk.
the class RecyclerViewMatcher method atPositionOnView.
public Matcher<View> atPositionOnView(final int position, final int targetViewId) {
return new TypeSafeMatcher<View>() {
Resources resources;
View childView;
public void describeTo(Description description) {
String idDescription = Integer.toString(recyclerViewId);
if (this.resources != null) {
try {
idDescription = this.resources.getResourceName(recyclerViewId);
} catch (Resources.NotFoundException var4) {
idDescription = String.format("%s (resource name not found)", recyclerViewId);
}
}
description.appendText("RecyclerView with id: " + idDescription + " at position: " + position);
}
public boolean matchesSafely(View view) {
this.resources = view.getResources();
if (childView == null) {
RecyclerView recyclerView = view.getRootView().findViewById(recyclerViewId);
if (recyclerView != null && recyclerView.getId() == recyclerViewId) {
RecyclerView.ViewHolder viewHolder = recyclerView.findViewHolderForAdapterPosition(position);
if (viewHolder != null) {
childView = viewHolder.itemView;
}
} else {
return false;
}
}
if (targetViewId == -1) {
return view == childView;
} else {
View targetView = childView.findViewById(targetViewId);
return view == targetView;
}
}
};
}
use of org.hamcrest.TypeSafeMatcher in project android-test by android.
the class DomMatchersTest method testWithBody_DocumentWithNoBody.
@Test
public void testWithBody_DocumentWithNoBody() throws Exception {
Document documentWithNoBody = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new StringBufferInputStream(HTML_NO_BODY));
Matcher<Element> alwaysMatch = new TypeSafeMatcher<Element>() {
@Override
public void describeTo(Description description) {
description.appendText("always a match");
}
@Override
public boolean matchesSafely(Element element) {
return true;
}
};
assertFalse(withBody(alwaysMatch).matches(documentWithNoBody));
}
use of org.hamcrest.TypeSafeMatcher in project Catroid by Catrobat.
the class RecyclerViewMatcher method atPositionOnView.
public Matcher<View> atPositionOnView(final int position, final int targetViewId) {
return new TypeSafeMatcher<View>() {
Resources resources = null;
View childView;
public void describeTo(Description description) {
String idDescription = Integer.toString(recyclerViewId);
if (this.resources != null) {
try {
idDescription = this.resources.getResourceName(recyclerViewId);
} catch (Resources.NotFoundException ignored) {
idDescription = String.format("%s (resource name not found)", recyclerViewId);
}
}
description.appendText("with id: " + idDescription);
}
public boolean matchesSafely(View view) {
this.resources = view.getResources();
if (childView == null) {
RecyclerView recyclerView = view.getRootView().findViewById(recyclerViewId);
if (recyclerView != null && recyclerView.getId() == recyclerViewId) {
childView = recyclerView.findViewHolderForAdapterPosition(position).itemView;
} else {
return false;
}
}
if (targetViewId == -1) {
return view == childView;
} else {
View targetView = childView.findViewById(targetViewId);
return view == targetView;
}
}
};
}
use of org.hamcrest.TypeSafeMatcher in project pay-connector by alphagov.
the class XMLUnmarshallerSecurityTest method unmarshalExceptionWithLinkedSAXParseException.
private Matcher<Throwable> unmarshalExceptionWithLinkedSAXParseException(final String expectedMessage) {
return new TypeSafeMatcher<Throwable>() {
@Override
protected boolean matchesSafely(Throwable throwable) {
if (throwable instanceof UnmarshalException) {
UnmarshalException ex = (UnmarshalException) throwable;
Throwable linkedException = ex.getLinkedException();
if (linkedException instanceof SAXParseException) {
return expectedMessage.equals(linkedException.getMessage());
}
}
return false;
}
@Override
public void describeTo(Description description) {
description.appendText("UnmarshalException with linked exception to be SAXParseException").appendText(" and message: '").appendValue(expectedMessage).appendText("'");
}
};
}
Aggregations