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));
}
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");
}
};
}
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) {
}
};
}
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;
}
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);
}
Aggregations