use of org.hamcrest.TypeSafeMatcher in project openhab-android by openhab.
the class TestUtils method childAtPosition.
public 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 pixabayapp by gkaffka.
the class MainActivityTest 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 SEProject by NicholasBarreyre.
the class Matchers method withAdaptedData.
/**
* AdapterView matcher
* https://developer.android.com/training/testing/espresso/recipes.html
*
* @param dataMatcher
* @return
*/
public static Matcher<View> withAdaptedData(final Matcher<Object> dataMatcher) {
return new TypeSafeMatcher<View>() {
@Override
public void describeTo(Description description) {
description.appendText("with class name: ");
dataMatcher.describeTo(description);
}
@Override
public boolean matchesSafely(View view) {
if (!(view instanceof AdapterView)) {
return false;
}
@SuppressWarnings("rawtypes") Adapter adapter = ((AdapterView) view).getAdapter();
for (int i = 0; i < adapter.getCount(); i++) {
if (dataMatcher.matches(adapter.getItem(i))) {
return true;
}
}
return false;
}
};
}
use of org.hamcrest.TypeSafeMatcher in project keycloak by keycloak.
the class AssertEvents method defaultUserId.
public Matcher<String> defaultUserId() {
return new TypeSafeMatcher<String>() {
private String userId;
@Override
protected boolean matchesSafely(String item) {
return item.equals(getUserId());
}
@Override
public void describeTo(Description description) {
description.appendText(getUserId());
}
private String getUserId() {
if (userId == null) {
UserRepresentation user = getUser(DEFAULT_USERNAME);
if (user == null) {
throw new RuntimeException("Default user does not exist: " + DEFAULT_USERNAME + ". Make sure to add it to your test realm.");
}
userId = user.getId();
}
return userId;
}
};
}
use of org.hamcrest.TypeSafeMatcher in project JSCover by tntim96.
the class MainTest method shouldRunCoberturaXmlReport.
@Test
public void shouldRunCoberturaXmlReport() throws IOException {
given(config.getReportFormat()).willReturn(ReportFormat.COBERTURAXML);
given(config.getVersion()).willReturn("version");
File jsonDirectory = new File("jsonDir");
File srcDir = new File("src");
given(config.getJsonDirectory()).willReturn(jsonDirectory);
given(config.getSourceDirectory()).willReturn(srcDir);
String json = "json";
given(ioUtils.loadFromFileSystem(new File(jsonDirectory, "jscoverage.json"))).willReturn(json);
doReturn(srcDir.getCanonicalPath()).when(ioUtils).getCanonicalPath(srcDir);
SortedMap<String, FileData> list = new TreeMap<>();
given(jsonDataMerger.jsonToMap(json)).willReturn(list);
given(coberturaXmlGenerator.generateXml(ArgumentMatchers.any(), anyString(), anyString())).willReturn("<xml/>");
main.runMain(new String[] {});
TypeSafeMatcher<CoberturaData> coberturaDataMatcher = new TypeSafeMatcher<CoberturaData>() {
@Override
protected boolean matchesSafely(CoberturaData coverable) {
return true;
}
public void describeTo(Description description) {
}
};
File xmlFile = new File(jsonDirectory, "cobertura-coverage.xml");
verify(coberturaXmlGenerator).generateXml(argThat(coberturaDataMatcher), argThat(is(srcDir.getCanonicalPath())), argThat(is("version")));
verify(ioUtils).copy("<xml/>", xmlFile);
verifyNoInteractions(exitHelper);
}
Aggregations