Search in sources :

Example 26 with Description

use of org.hamcrest.Description in project gradle by gradle.

the class DefaultScriptRunnerFactoryTest method setsUpAndTearsDownWhenNonEmptyScriptIsRun.

@Test
public void setsUpAndTearsDownWhenNonEmptyScriptIsRun() {
    ScriptRunner<?, Void> scriptRunner = factory.create(compiledScriptMock, scriptSourceDummy, classLoaderDummy);
    expectScriptInstantiated();
    context.checking(new Expectations() {

        {
            Sequence sequence = context.sequence("seq");
            allowing(compiledScriptMock).getRunDoesSomething();
            will(returnValue(true));
            one(scriptExecutionListenerMock).scriptClassLoaded(scriptSourceDummy, Script.class);
            inSequence(sequence);
            one(scriptMock).init(target, scriptServices);
            inSequence(sequence);
            one(standardOutputCaptureMock).start();
            inSequence(sequence);
            one(scriptMock).run();
            inSequence(sequence);
            will(doAll(new Action() {

                public void describeTo(Description description) {
                    description.appendValue("check context classloader");
                }

                public Object invoke(Invocation invocation) throws Throwable {
                    assertThat(Thread.currentThread().getContextClassLoader(), sameInstance(classLoaderDummy));
                    return null;
                }
            }));
            one(standardOutputCaptureMock).stop();
            inSequence(sequence);
        }
    });
    ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
    assertThat(originalClassLoader, not(sameInstance(classLoaderDummy)));
    scriptRunner.run(target, scriptServices);
    assertThat(Thread.currentThread().getContextClassLoader(), sameInstance(originalClassLoader));
}
Also used : Expectations(org.jmock.Expectations) Script(org.gradle.groovy.scripts.Script) Action(org.jmock.api.Action) Description(org.hamcrest.Description) Invocation(org.jmock.api.Invocation) Sequence(org.jmock.Sequence) Test(org.junit.Test)

Example 27 with Description

use of org.hamcrest.Description in project gocd by gocd.

the class RemoteRegistrationRequesterTest method hasAllParams.

private TypeSafeMatcher<HttpRequestBase> hasAllParams(final String uuid, final String elasticAgentId, final String elasticPluginId) {
    return new TypeSafeMatcher<HttpRequestBase>() {

        @Override
        public boolean matchesSafely(HttpRequestBase item) {
            try {
                HttpEntityEnclosingRequestBase postMethod = (HttpEntityEnclosingRequestBase) item;
                List<NameValuePair> params = URLEncodedUtils.parse(postMethod.getEntity());
                assertThat(getParameter(params, "hostname"), is("cruise.com"));
                assertThat(getParameter(params, "uuid"), is(uuid));
                String workingDir = SystemUtil.currentWorkingDirectory();
                assertThat(getParameter(params, "location"), is(workingDir));
                assertThat(getParameter(params, "operatingSystem"), not(nullValue()));
                assertThat(getParameter(params, "agentAutoRegisterKey"), is("t0ps3cret"));
                assertThat(getParameter(params, "agentAutoRegisterResources"), is("linux, java"));
                assertThat(getParameter(params, "agentAutoRegisterEnvironments"), is("uat, staging"));
                assertThat(getParameter(params, "agentAutoRegisterHostname"), is("agent01.example.com"));
                assertThat(getParameter(params, "elasticAgentId"), is(elasticAgentId));
                assertThat(getParameter(params, "elasticPluginId"), is(elasticPluginId));
                return true;
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }

        private String getParameter(List<NameValuePair> params, String paramName) {
            for (NameValuePair param : params) {
                if (param.getName().equals(paramName)) {
                    return param.getValue();
                }
            }
            return null;
        }

        public void describeTo(Description description) {
            description.appendText("params containing");
        }
    };
}
Also used : NameValuePair(org.apache.http.NameValuePair) HttpRequestBase(org.apache.http.client.methods.HttpRequestBase) HttpEntityEnclosingRequestBase(org.apache.http.client.methods.HttpEntityEnclosingRequestBase) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) List(java.util.List) IOException(java.io.IOException)

Example 28 with Description

use of org.hamcrest.Description in project gocd by gocd.

the class GoConfigServiceTest method isAPipelineSelectionsInstanceWith.

private Matcher<PipelineSelections> isAPipelineSelectionsInstanceWith(final boolean isBlacklist, final String... pipelineSelectionsInInstance) {
    return new BaseMatcher<PipelineSelections>() {

        public boolean matches(Object o) {
            PipelineSelections pipelineSelections = (PipelineSelections) o;
            assertThat(pipelineSelections.isBlacklist(), is(isBlacklist));
            List<String> expectedSelectionsAsList = Arrays.asList(pipelineSelectionsInInstance);
            assertEquals(pipelineSelections.getSelections(), ListUtil.join(expectedSelectionsAsList, ","));
            return true;
        }

        public void describeTo(Description description) {
        }
    };
}
Also used : PipelineSelections(com.thoughtworks.go.server.domain.user.PipelineSelections) Description(org.hamcrest.Description) BaseMatcher(org.hamcrest.BaseMatcher) StringContains.containsString(org.hamcrest.core.StringContains.containsString)

Example 29 with Description

use of org.hamcrest.Description in project gradle by gradle.

the class TaskReportTaskTest method task.

private Task task(final String name, final String taskGroup, final Task... dependencies) {
    final Task task = context.mock(Task.class);
    context.checking(new Expectations() {

        {
            allowing(task).getName();
            will(returnValue(name));
            allowing(task).getPath();
            will(returnValue(':' + name));
            allowing(task).getProject();
            will(returnValue(project));
            allowing(project).relativeProjectPath(':' + name);
            will(returnValue(name));
            allowing(task).getGroup();
            will(returnValue(taskGroup));
            allowing(task).compareTo(with(Matchers.notNullValue(Task.class)));
            will(new Action() {

                public Object invoke(Invocation invocation) throws Throwable {
                    Task other = (Task) invocation.getParameter(0);
                    return name.compareTo(other.getName());
                }

                public void describeTo(Description description) {
                    description.appendText("compare to");
                }
            });
            TaskDependency dependency = context.mock(TaskDependency.class);
            allowing(task).getTaskDependencies();
            will(returnValue(dependency));
            allowing(dependency).getDependencies(task);
            will(returnValue(toSet(dependencies)));
        }
    });
    return task;
}
Also used : Expectations(org.jmock.Expectations) TaskDependency(org.gradle.api.tasks.TaskDependency) Task(org.gradle.api.Task) Action(org.jmock.api.Action) Description(org.hamcrest.Description) Invocation(org.jmock.api.Invocation)

Example 30 with Description

use of org.hamcrest.Description in project pulsar by yahoo.

the class NamespacesTest method testUnloadNamespaces.

@Test
public void testUnloadNamespaces() throws Exception {
    final NamespaceName testNs = this.testLocalNamespaces.get(1);
    URL localWebServiceUrl = new URL(pulsar.getWebServiceAddress());
    doReturn(localWebServiceUrl).when(nsSvc).getWebServiceUrl(Mockito.argThat(new Matcher<NamespaceBundle>() {

        @Override
        public void describeTo(Description description) {
        // TODO Auto-generated method stub
        }

        @Override
        public boolean matches(Object item) {
            if (item instanceof NamespaceName) {
                NamespaceName ns = (NamespaceName) item;
                return ns.equals(testNs);
            }
            return false;
        }

        @Override
        public void _dont_implement_Matcher___instead_extend_BaseMatcher_() {
        // TODO Auto-generated method stub
        }
    }), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anyBoolean());
    doReturn(true).when(nsSvc).isServiceUnitOwned(Mockito.argThat(new Matcher<NamespaceBundle>() {

        @Override
        public void describeTo(Description description) {
        // TODO Auto-generated method stub
        }

        @Override
        public boolean matches(Object item) {
            if (item instanceof NamespaceName) {
                NamespaceName ns = (NamespaceName) item;
                return ns.equals(testNs);
            }
            return false;
        }

        @Override
        public void _dont_implement_Matcher___instead_extend_BaseMatcher_() {
        // TODO Auto-generated method stub
        }
    }));
    doNothing().when(nsSvc).unloadNamespace(testNs);
    NamespaceBundle bundle = nsSvc.getNamespaceBundleFactory().getFullBundle(testNs);
    doNothing().when(namespaces).validateBundleOwnership(bundle, false, true);
    try {
        namespaces.unloadNamespace(testNs.getProperty(), testNs.getCluster(), testNs.getLocalName());
        fail("should have failed as bydefault bundle is activated and can't be unloaded");
    } catch (RestException re) {
    // ok
    }
    verify(nsSvc, times(0)).unloadNamespace(testNs);
}
Also used : NamespaceBundle(com.yahoo.pulsar.common.naming.NamespaceBundle) NamespaceName(com.yahoo.pulsar.common.naming.NamespaceName) Description(org.hamcrest.Description) Matcher(org.hamcrest.Matcher) RestException(com.yahoo.pulsar.broker.web.RestException) URL(java.net.URL) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(com.yahoo.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Aggregations

Description (org.hamcrest.Description)117 Test (org.junit.Test)37 TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)35 StringDescription (org.hamcrest.StringDescription)26 BaseMatcher (org.hamcrest.BaseMatcher)25 View (android.view.View)22 ViewParent (android.view.ViewParent)11 TextView (android.widget.TextView)11 ViewGroup (android.view.ViewGroup)8 Expectations (org.jmock.Expectations)8 URL (java.net.URL)7 Matcher (org.hamcrest.Matcher)7 Invocation (org.jmock.api.Invocation)7 BoundedMatcher (android.support.test.espresso.matcher.BoundedMatcher)6 ImageView (android.widget.ImageView)6 File (java.io.File)6 IOException (java.io.IOException)6 URI (java.net.URI)6 List (java.util.List)6 JsonNode (org.codehaus.jackson.JsonNode)6