use of org.hamcrest.Matcher in project android-priority-jobqueue by yigit.
the class JobQueueTestBase method assertTags.
private void assertTags(String msg, JobQueue jobQueue, JobHolder holder) {
Set<JobHolder> result;
String wrongTag;
final String id = holder.getId();
boolean found;
Matcher allTagsMatcher = CoreMatchers.hasItems(holder.getTags().toArray(new String[holder.getTags().size()]));
do {
wrongTag = UUID.randomUUID().toString();
found = false;
if (holder.getTags() != null) {
for (String tag : holder.getTags()) {
if (tag.equals(wrongTag)) {
found = true;
break;
}
}
}
} while (found);
result = jobQueue.findJobs(forTags(mockTimer, ANY, Collections.<String>emptyList(), wrongTag));
found = false;
for (JobHolder received : result) {
if (received.getId().equals(holder.getId())) {
found = true;
}
}
assertThat(msg + " when wrong tag is given, our job should not return", found, is(false));
if (holder.getTags() == null) {
// done
return;
}
Collection<String> exclude = Arrays.asList(holder.getId());
for (String[] tags : combinations(holder.getTags())) {
result = jobQueue.findJobs(forTags(mockTimer, TagConstraint.ANY, Collections.<String>emptyList(), tags));
if (tags.length == 0) {
assertThat(msg + " empty tag list, should return 0 jobs", result.size(), is(0));
} else {
assertThat(msg + " any combinations: when correct tag is given, it should return one", result.size(), is(1));
assertThat(msg + " any combinations: returned job should be the correct one", result.iterator().next().getId(), is(id));
assertThat(msg + " returned holder should have all tags:", result.iterator().next().getTags(), allTagsMatcher);
}
result = jobQueue.findJobs(forTags(mockTimer, TagConstraint.ANY, exclude, tags));
assertThat(msg + " when excluded, holder should not show up in results", result.size(), is(0));
}
for (String[] tags : combinations(holder.getTags())) {
result = jobQueue.findJobs(forTags(mockTimer, ALL, Collections.<String>emptyList(), tags));
if (tags.length == 0) {
assertThat(msg + " empty tag list, should return 0 jobs", result.size(), is(0));
} else {
assertThat(msg + " all combinations: when correct tag is given, it should return one", result.size(), is(1));
assertThat(msg + " all combinations: returned job should be the correct one", result.iterator().next().getId(), is(id));
assertThat(msg + " returned holder should have all tags:", result.iterator().next().getTags(), allTagsMatcher);
}
result = jobQueue.findJobs(forTags(mockTimer, ALL, exclude, tags));
assertThat(msg + " when excluded, holder should not show up in results", result.size(), is(0));
}
for (String[] tags : combinations(holder.getTags())) {
String[] tagsWithAdditional = new String[tags.length + 1];
System.arraycopy(tags, 0, tagsWithAdditional, 0, tags.length);
tagsWithAdditional[tags.length] = wrongTag;
result = jobQueue.findJobs(forTags(mockTimer, TagConstraint.ANY, Collections.<String>emptyList(), tagsWithAdditional));
if (tags.length == 0) {
assertThat(msg + " empty tag list, should return 0 jobs", result.size(), is(0));
} else {
assertThat(msg + " any combinations with wrong tag: when correct tag is given, it should return one", result.size(), is(1));
assertThat(msg + " any combinations with wrong tag: returned job should be the correct one", result.iterator().next().getId(), is(id));
assertThat(msg + " returned holder should have all tags:", result.iterator().next().getTags(), allTagsMatcher);
}
result = jobQueue.findJobs(forTags(mockTimer, ALL, Collections.<String>emptyList(), tagsWithAdditional));
assertThat(msg + " all combinations with wrong tag: when an additional wrong tag is given, it should return 0", result.size(), is(0));
result = jobQueue.findJobs(forTags(mockTimer, ALL, exclude, tagsWithAdditional));
assertThat(msg + " when excluded, holder should not show up in results", result.size(), is(0));
}
}
use of org.hamcrest.Matcher in project double-espresso by JakeWharton.
the class ViewInteractionTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
initMocks(this);
realLifecycleMonitor = ActivityLifecycleMonitorRegistry.getInstance();
rootView = new View(getContext());
targetView = new View(getContext());
viewMatcher = is(targetView);
actionConstraint = Matchers.<View>notNullValue();
rootMatcherRef = new AtomicReference<Matcher<Root>>(RootMatchers.DEFAULT);
when(mockAction.getDescription()).thenReturn("A Mock!");
failureHandler = new FailureHandler() {
@Override
public void handle(Throwable error, Matcher<View> viewMatcher) {
propagate(error);
}
};
}
use of org.hamcrest.Matcher in project ddf by codice.
the class TestCswUnmarshallHelper method testConvertStringValueToMetacardValue.
@Test
public void testConvertStringValueToMetacardValue() {
valueMap.put(AttributeType.AttributeFormat.BINARY, null);
valueMap.put(AttributeType.AttributeFormat.GEOMETRY, null);
matcherMap.put(AttributeType.AttributeFormat.BINARY, nullValue());
matcherMap.put(AttributeType.AttributeFormat.GEOMETRY, nullValue());
Serializable ser = CswUnmarshallHelper.convertStringValueToMetacardValue(null, "XYZ");
assertThat(ser, nullValue());
AttributeType.AttributeFormat[] attributeFormats = AttributeType.AttributeFormat.values();
for (AttributeType.AttributeFormat attributeFormat : attributeFormats) {
Matcher m = matcherMap.get(attributeFormat);
String value = valueMap.get(attributeFormat);
ser = CswUnmarshallHelper.convertStringValueToMetacardValue(attributeFormat, value);
assertThat(ser, m);
}
}
Aggregations