Search in sources :

Example 26 with Matcher

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));
    }
}
Also used : JobHolder(com.birbit.android.jobqueue.JobHolder) Matcher(org.hamcrest.Matcher)

Example 27 with Matcher

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);
        }
    };
}
Also used : Matcher(org.hamcrest.Matcher) View(android.view.View)

Example 28 with Matcher

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);
    }
}
Also used : Serializable(java.io.Serializable) Matcher(org.hamcrest.Matcher) AttributeType(ddf.catalog.data.AttributeType) Test(org.junit.Test)

Aggregations

Matcher (org.hamcrest.Matcher)28 Description (org.hamcrest.Description)7 View (android.view.View)6 Test (org.junit.Test)6 Espresso.onView (android.support.test.espresso.Espresso.onView)4 UiController (android.support.test.espresso.UiController)4 ViewAction (android.support.test.espresso.ViewAction)4 TextView (android.widget.TextView)4 MockedPulsarServiceBaseTest (com.yahoo.pulsar.broker.auth.MockedPulsarServiceBaseTest)4 NamespaceBundle (com.yahoo.pulsar.common.naming.NamespaceBundle)4 NamespaceName (com.yahoo.pulsar.common.naming.NamespaceName)4 URL (java.net.URL)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 Test (org.testng.annotations.Test)4 RestException (com.yahoo.pulsar.broker.web.RestException)3 ArrayList (java.util.ArrayList)3 Resources (android.content.res.Resources)2 ColorInt (android.support.annotation.ColorInt)2 MediumTest (android.support.test.filters.MediumTest)2 ViewGroup (android.view.ViewGroup)2