本文整理汇总了Java中org.jmock.api.Action类的典型用法代码示例。如果您正苦于以下问题:Java Action类的具体用法?Java Action怎么用?Java Action使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Action类属于org.jmock.api包,在下文中一共展示了Action类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: will
import org.jmock.api.Action; //导入依赖的package包/类
void will(final Closure cl) {
will(new Action() {
public void describeTo(Description description) {
description.appendText("execute closure");
}
public Object invoke(Invocation invocation) throws Throwable {
List<Object> params = Arrays.asList(invocation.getParametersAsArray());
Object result;
try {
List<Object> subParams = params.subList(0, Math.min(invocation.getParametersAsArray().length,
cl.getMaximumNumberOfParameters()));
result = cl.call(subParams.toArray(new Object[0]));
} catch (InvokerInvocationException e) {
throw e.getCause();
}
if (invocation.getInvokedMethod().getReturnType().isInstance(result)) {
return result;
}
return null;
}
});
}
示例2: will
import org.jmock.api.Action; //导入依赖的package包/类
void will(final Closure cl) {
will(new Action() {
public void describeTo(Description description) {
description.appendText("execute closure");
}
public Object invoke(Invocation invocation) throws Throwable {
List<Object> params = Arrays.asList(invocation.getParametersAsArray());
Object result;
try {
List<Object> subParams = params.subList(0, Math.min(invocation.getParametersAsArray().length,
cl.getMaximumNumberOfParameters()));
result = cl.call(subParams.toArray(new Object[subParams.size()]));
} catch (InvokerInvocationException e) {
throw e.getCause();
}
if (invocation.getInvokedMethod().getReturnType().isInstance(result)) {
return result;
}
return null;
}
});
}
示例3: returnInstantiatedAndInitializedViewModel
import org.jmock.api.Action; //导入依赖的package包/类
private Action returnInstantiatedAndInitializedViewModel() {
return new Action() {
@Override
public Object invoke(Invocation invocation) throws Throwable {
final Class<?> cls = (Class<?>) invocation.getParameter(0);
final String memento = (String) invocation.getParameter(1);
final ViewModel viewModelInstance = (ViewModel) cls.newInstance();
viewModelInstance.viewModelInit(memento);
if(viewModelInstance instanceof UserPermissionViewModel) {
((UserPermissionViewModel) viewModelInstance).applicationPermissionRepository = mockApplicationPermissionRepository;
}
return viewModelInstance;
}
@Override
public void describeTo(Description description) {
description.appendText("return instantiated and initialized view model ");
}
};
}
示例4: addToInMemoryDB
import org.jmock.api.Action; //导入依赖的package包/类
private Action addToInMemoryDB() {
return new Action() {
@Override
public Object invoke(Invocation invocation) throws Throwable {
final InMemoryDB inMemoryDB = getVar("isis", "in-memory-db", InMemoryDB.class);
final String name = (String)invocation.getParameter(0);
final SimpleObject obj = new SimpleObject();
obj.setName(name);
inMemoryDB.put(SimpleObject.class, name, obj);
return obj;
}
@Override
public void describeTo(Description description) {
description.appendText("add to database");
}
};
}
示例5: testFailsIfInvokedMoreTimesThanThereAreActionsInTheSequence
import org.jmock.api.Action; //导入依赖的package包/类
@SuppressWarnings("cast") // Eclipse gives warning if there is a cast and if there is not!
public void testFailsIfInvokedMoreTimesThanThereAreActionsInTheSequence() throws Throwable {
MockAction[] actions = new MockAction[]{new MockAction(), new MockAction()};
ActionSequence sequence = new ActionSequence((Action[])actions);
for (int i = 0; i < actions.length; i++) sequence.invoke(invocation);
try {
sequence.invoke(invocation);
fail("should have thrown IllegalStateException");
}
catch (ExpectationError ex) {
AssertThat.stringIncludes("should describe error",
"no more actions", ex.getMessage());
return;
}
}
示例6: testDescribesItselfAsSequenceOfActions
import org.jmock.api.Action; //导入依赖的package包/类
@SuppressWarnings("cast") // Eclipse gives warning if there is a cast and if there is not!
public void testDescribesItselfAsSequenceOfActions() throws Throwable {
MockAction[] actions = new MockAction[]{new MockAction(), new MockAction()};
ActionSequence sequence = new ActionSequence((Action[])actions);
String sequenceDescription = StringDescription.toString(sequence);
for (int i = 0; i < actions.length; i++) {
AssertThat.stringIncludes("should include action " + i,
actions[i].descriptionText, sequenceDescription);
if (i > 0) {
int h = i - 1;
assertTrue("description of action " + h + " should be before that of action " + i,
sequenceDescription.indexOf(actions[h].descriptionText) <
sequenceDescription.indexOf(actions[i].descriptionText));
}
}
}
示例7: testSaveLoad
import org.jmock.api.Action; //导入依赖的package包/类
@Test(dataProvider = "editionProvider")
public void testSaveLoad(@NotNull final PowerShellEdition edition) throws IOException {
PowerShellInfo info = new PowerShellInfo(PowerShellBitness.x64, createTempDir(), "1.0", edition, "powershell.exe");
final Mockery m = new Mockery();
final BuildAgentConfiguration conf = m.mock(BuildAgentConfiguration.class);
final Map<String, String> confParams = new HashMap<String, String>();
m.checking(new Expectations(){{
allowing(conf).getConfigurationParameters(); will(returnValue(Collections.unmodifiableMap(confParams)));
allowing(conf).addConfigurationParameter(with(any(String.class)), with(any(String.class)));
will(new Action() {
public Object invoke(final Invocation invocation) throws Throwable {
final String key = (String) invocation.getParameter(0);
final String value = (String) invocation.getParameter(1);
Assert.assertNotNull(key);
Assert.assertNotNull(value);
confParams.put(key, value);
return null;
}
public void describeTo(final Description description) {
description.appendText("add Parameters");
}
});
}});
info.saveInfo(conf);
PowerShellInfo i = PowerShellInfo.loadInfo(conf, PowerShellBitness.x64);
Assert.assertNotNull(i);
Assert.assertEquals(i.getBitness(), info.getBitness());
Assert.assertEquals(i.getHome(), info.getHome());
Assert.assertEquals(i.getExecutablePath(), info.getExecutablePath());
Assert.assertEquals(i.getVersion(), info.getVersion());
Assert.assertEquals(i.getEdition(), info.getEdition());
Assert.assertEquals(i.getExecutable(), info.getExecutable());
}
示例8: countDown
import org.jmock.api.Action; //导入依赖的package包/类
public static Action countDown(final CountDownLatch latch)
{
return new CustomAction("Count Down Latch")
{
public Object invoke(Invocation invocation) throws Throwable
{
latch.countDown();
return null;
}
};
}
示例9: setupApplication
import org.jmock.api.Action; //导入依赖的package包/类
@Before
public final void setupApplication() throws Exception {
context = new JUnit4Mockery();
context.setImposteriser(ClassImposteriser.INSTANCE);
myApplication = context.mock(ApplicationEx.class, "application");
context.checking(new Expectations() {
{
allowing(myApplication).isUnitTestMode(); will(returnValue(false));
allowing(myApplication).getName(); will(returnValue("IDEA"));
// some tests leave invokeLater()'s after them
allowing(myApplication).invokeLater(with(any(Runnable.class)), with(any(ModalityState.class)));
allowing(myApplication).runReadAction(with(any(Runnable.class)));
will(new Action() {
@Override
public void describeTo(final Description description) {
description.appendText("runs runnable");
}
@Override
@Nullable
public Object invoke(final Invocation invocation) throws Throwable {
((Runnable)invocation.getParameter(0)).run();
return null;
}
});
}
});
}
示例10: executeCallableAndReturn
import org.jmock.api.Action; //导入依赖的package包/类
private static Action executeCallableAndReturn() {
return new Action() {
@Override
public Object invoke(Invocation invocation) throws Throwable {
Callable<Object> callable = (Callable<Object>) invocation.getParameter(0);
return callable.call();
}
@Override
public void describeTo(Description description) {
description.appendText("execute arg 0 as callable and return");
}
};
}
示例11: returnLeaseTerm
import org.jmock.api.Action; //导入依赖的package包/类
private Action returnLeaseTerm() {
return new Action() {
@Override
public Object invoke(Invocation invocation) throws Throwable {
LeaseItem leaseItem = (LeaseItem) invocation.getParameter(0);
LeaseTerm leaseTerm = (LeaseTerm) invocation.getParameter(1);
LocalDate startDate = (LocalDate) invocation.getParameter(2);
LocalDate endDate = (LocalDate) invocation.getParameter(3);
LeaseTermForTesting ltt = new LeaseTermForTesting();
// relationships
ltt.setLeaseItem(leaseItem);
leaseItem.getTerms().add(ltt);
ltt.setPrevious(leaseTerm);
leaseTerm.setNext(ltt);
// set values
ltt.modifyStartDate(startDate);
ltt.modifyEndDate(endDate);
ltt.clockService = mockClockService;
return ltt;
}
@Override
public void describeTo(Description description) {
description.appendText("new Lease Term under item and with previous term");
}
};
}
示例12: setupApplication
import org.jmock.api.Action; //导入依赖的package包/类
@Before
public final void setupApplication() throws Exception {
// in fact the test accesses extension points so it rather should be converted to a platform one
assumeNotNull(ApplicationManager.getApplication());
context = new JUnit4Mockery();
context.setImposteriser(ClassImposteriser.INSTANCE);
myApplication = context.mock(ApplicationEx.class, "application");
context.checking(new Expectations() {
{
allowing(myApplication).isUnitTestMode(); will(returnValue(false));
// some tests leave invokeLater()'s after them
allowing(myApplication).invokeLater(with(any(Runnable.class)), with(any(ModalityState.class)));
allowing(myApplication).runReadAction(with(any(Runnable.class)));
will(new Action() {
@Override
public void describeTo(final Description description) {
description.appendText("runs runnable");
}
@Override
@javax.annotation.Nullable
public Object invoke(final Invocation invocation) throws Throwable {
((Runnable)invocation.getParameter(0)).run();
return null;
}
});
}
});
}
示例13: buildExpectations
import org.jmock.api.Action; //导入依赖的package包/类
public void buildExpectations(Action defaultAction, ExpectationCollector collector) {
checkLastExpectationWasFullySpecified();
for (InvocationExpectationBuilder builder : builders) {
collector.add(builder.toExpectation(defaultAction));
}
}
示例14: toExpectation
import org.jmock.api.Action; //导入依赖的package包/类
public Expectation toExpectation(Action defaultAction) {
if (needsDefaultAction) {
expectation.setDefaultAction(defaultAction);
}
return expectation;
}
示例15: doSomethingDescribedAs
import org.jmock.api.Action; //导入依赖的package包/类
public Action doSomethingDescribedAs(String name) {
return new CustomAction(name) {
@Override
public Object invoke(Invocation invocation) throws Throwable {
return null;
}
};
}