How to use ActionSequence class of org.jmock.lib.action package

Best Jmock-library code snippet using org.jmock.lib.action.ActionSequence

Source:ActionSequenceTests.java Github

copy

Full Screen

...6import org.hamcrest.StringDescription;7import org.jmock.api.Action;8import org.jmock.api.ExpectationError;9import org.jmock.api.Invocation;10import org.jmock.lib.action.ActionSequence;11import org.jmock.test.unit.support.AssertThat;12import org.jmock.test.unit.support.MethodFactory;13import org.jmock.test.unit.support.MockAction;14public class ActionSequenceTests extends TestCase {15 private Object invokedObject = "INVOKED_OBJECT";16 private MethodFactory methodFactory = new MethodFactory();17 private Method invokedMethod = methodFactory.newMethodReturning(String.class);18 private Invocation invocation = new Invocation(invokedObject, invokedMethod);19 20 21 @SuppressWarnings("cast") // Eclipse gives warning if there is a cast and if there is not!22 public void testInvokesActionsInOrder() throws Throwable {23 final int sequenceLength = 4;24 25 MockAction[] actions = new MockAction[sequenceLength]; 26 for (int i = 0; i < sequenceLength; i++) {27 actions[i] = new MockAction();28 actions[i].result = "RESULT-" + i;29 if (i > 0) actions[i].previous = actions[i-1];30 }31 32 Invocation[] invocations = new Invocation[actions.length];33 for (int i = 0; i < sequenceLength; i++) {34 invocations[i] = new Invocation(invokedObject, invokedMethod);35 }36 37 ActionSequence sequence = new ActionSequence((Action[])actions);38 39 for (int current = 0; current < actions.length; current++) {40 reset(actions);41 actions[current].expectInvoke = true;42 actions[current].expectedInvocation = invocation;43 44 Object result = sequence.invoke(invocation);45 46 assertSame("should be result of actions[" + current + "]",47 actions[current].result, result);48 }49 }50 51 @SuppressWarnings("cast") // Eclipse gives warning if there is a cast and if there is not!52 public void testFailsIfInvokedMoreTimesThanThereAreActionsInTheSequence() throws Throwable {53 MockAction[] actions = new MockAction[]{new MockAction(), new MockAction()};54 ActionSequence sequence = new ActionSequence((Action[])actions);55 56 for (int i = 0; i < actions.length; i++) sequence.invoke(invocation);57 58 try {59 sequence.invoke(invocation);60 fail("should have thrown IllegalStateException");61 }62 catch (ExpectationError ex) {63 AssertThat.stringIncludes("should describe error",64 "no more actions", ex.getMessage());65 return;66 }67 }68 69 @SuppressWarnings("cast") // Eclipse gives warning if there is a cast and if there is not!70 public void testDescribesItselfAsSequenceOfActions() throws Throwable {71 MockAction[] actions = new MockAction[]{new MockAction(), new MockAction()};72 ActionSequence sequence = new ActionSequence((Action[])actions);73 74 String sequenceDescription = StringDescription.toString(sequence);75 for (int i = 0; i < actions.length; i++) {76 AssertThat.stringIncludes("should include action " + i,77 actions[i].descriptionText, sequenceDescription);78 if (i > 0) {79 int h = i - 1;80 81 assertTrue("description of action " + h + " should be before that of action " + i,82 sequenceDescription.indexOf(actions[h].descriptionText) <83 sequenceDescription.indexOf(actions[i].descriptionText));84 }85 }86 }...

Full Screen

Full Screen

Source:ActionSequence.java Github

copy

Full Screen

...14 * 15 * @author nat16 *17 */18public class ActionSequence implements Action {19 List<Action> actions;20 Iterator<Action> iterator;21 22 public ActionSequence(Action... actions) {23 this.actions = new ArrayList<Action>(Arrays.asList(actions));24 this.iterator = this.actions.iterator();25 }26 27 public Object invoke(Invocation invocation) throws Throwable {28 if (iterator.hasNext()) {29 return iterator.next().invoke(invocation);30 } 31 throw ExpectationError.unexpected("no more actions available", invocation);32 }33 34 public void describeTo(Description description) {35 description.appendList("", ", and then ", "", actions);36 }...

Full Screen

Full Screen

ActionSequence

Using AI Code Generation

copy

Full Screen

1import org.jmock.Mock;2import org.jmock.MockObjectTestCase;3import org.jmock.core.Invocation;4import org.jmock.core.Stub;5import org.jmock.lib.action.ActionSequence;6import org.jmock.lib.action.ReturnValueAction;7import org.jmock.lib.action.ThrowAction;8public class ActionSequenceTest extends MockObjectTestCase {9 public void testActionSequence() {10 Mock mock = mock(Runnable.class);11 mock.expects(once()).method("run").will(12 new ActionSequence(13 new Stub[] {14 new ReturnValueAction("one"),15 new ReturnValueAction("two"),16 new ThrowAction(new RuntimeException("three")) }));17 Runnable r = (Runnable) mock.proxy();18 assertEquals("one", r.run());19 assertEquals("two", r.run());20 try {21 r.run();22 fail("should have thrown exception");23 } catch (RuntimeException ex) {24 assertEquals("three", ex.getMessage());25 }26 }27}28import org.jmock.Mock;29import org.jmock.MockObjectTestCase;30import org.jmock.core.Invocation;31import org.jmock.core.Stub;32import org.jmock.lib.action.ActionSequence;33import org.jmock.lib.action.ReturnValueAction;34import org.jmock.lib.action.ThrowAction;35public class ActionSequenceTest extends MockObjectTestCase {36 public void testActionSequence() {37 Mock mock = mock(Runnable.class);38 mock.expects(once()).method("run").will(39 new ActionSequence(40 new Stub[] {41 new ReturnValueAction("one"),42 new ReturnValueAction("two"),43 new ThrowAction(new RuntimeException("three")) }));44 Runnable r = (Runnable) mock.proxy();45 assertEquals("one", r.run());46 assertEquals("two", r.run());47 try {48 r.run();49 fail("should have thrown exception");50 } catch (RuntimeException ex) {51 assertEquals("three", ex.getMessage());52 }53 }54}55import org.jmock.Mock;56import org.jmock.MockObjectTestCase;57import org.jmock.core.Invocation;58import org.jmock.core.Stub;59import org.jmock.lib.action.ActionSequence;60import org.jmock.lib.action.ReturnValueAction;61import org.jmock.lib.action.ThrowAction;

Full Screen

Full Screen

ActionSequence

Using AI Code Generation

copy

Full Screen

1import org.jmock.Mock;2import org.jmock.MockObjectTestCase;3import org.jmock.core.Invocation;4import org.jmock.core.Stub;5import org.jmock.core.stub.StubSequence;6import org.jmock.lib.action.ActionSequence;7import org.jmock.lib.action.ReturnValueAction;8import org.jmock.lib.action.ThrowAction;9public class ActionSequenceTest extends MockObjectTestCase {10 public void testActionSequence() {11 Mock mock = new Mock(Stub.class);12 mock.expects(once()).method("invoke").with(same(mock.proxy()))13 .will(new ActionSequence(new Stub[] {14 new ReturnValueAction("first"),15 new ThrowAction(new RuntimeException("second")),16 new ReturnValueAction("third")}));17 Stub stub = (Stub) mock.proxy();18 assertEquals("first", stub.invoke(mock.proxy()));19 try {20 stub.invoke(mock.proxy());21 fail("Should have thrown RuntimeException");22 } catch (RuntimeException e) {23 assertEquals("second", e.getMessage());24 }25 assertEquals("third", stub.invoke(mock.proxy()));26 }27}28import org.jmock.Mock;29import org.jmock.MockObjectTestCase;30import org.jmock.core.Invocation;31import org.jmock.core.Stub;32import org.jmock.core.stub.StubSequence;33import org.jmock.lib.action.ActionSequence;34import org.jmock.lib.action.ReturnValueAction;35import org.jmock.lib.action.ThrowAction;36public class ActionSequenceTest extends MockObjectTestCase {37 public void testActionSequence() {38 Mock mock = new Mock(Stub.class);39 mock.expects(once()).method("invoke").with(same(mock.proxy()))40 .will(new ActionSequence(new Stub[] {41 new ReturnValueAction("first"),42 new ThrowAction(new RuntimeException("second")),43 new ReturnValueAction("third")}));44 Stub stub = (Stub) mock.proxy();45 assertEquals("first", stub.invoke(mock.proxy()));46 try {47 stub.invoke(mock.proxy());48 fail("Should have thrown RuntimeException");49 } catch (RuntimeException e) {50 assertEquals("second", e.getMessage());51 }52 assertEquals("third", stub.invoke(mock.proxy()));53 }54}55import org.jmock.Mock;56import org.jmock.MockObjectTestCase;57import org.jmock.core.Invocation;58import org

Full Screen

Full Screen

ActionSequence

Using AI Code Generation

copy

Full Screen

1import org.jmock.Mock;2import org.jmock.MockObjectTestCase;3import org.jmock.lib.action.ActionSequence;4import org.jmock.lib.action.ReturnValue;5{6public void testActionSequence()7{8Mock mock = mock(Runnable.class);9Runnable runnable = (Runnable) mock.proxy();10mock.expects(once()).method("run").will(11new ActionSequence(new ReturnValue("Hello"), new ReturnValue("World")));12assertEquals("Hello", runnable.run());13assertEquals("World", runnable.run());14}15}16ActionSequence(Action[] actions)17ActionSequence(Action action1, Action action2, Action action3, ...)18ActionSequence(Action action1, Action action2, Action action3, ..., Action actionN)19void add(Action action)20Action[] getActions()21import org.jmock.Mock;22import org.jmock.MockObjectTestCase;23import org.jmock.lib.action.ActionSequence;24import org.jmock.lib.action.ReturnValue;25{26public void testActionSequence()27{28Mock mock = mock(Runnable.class);29Runnable runnable = (Runnable) mock.proxy();30mock.expects(once()).method("run").will(31new ActionSequence(new ReturnValue("Hello"), new ReturnValue("World")));32assertEquals("Hello", runnable.run());33assertEquals("World", runnable.run());34}35}36ActionSequence(Action[] actions)37ActionSequence(Action action1, Action action2, Action action3, ...)38ActionSequence(Action action1, Action action2, Action action3, ..., Action actionN)39void add(Action action)40Action[] getActions()

Full Screen

Full Screen

ActionSequence

Using AI Code Generation

copy

Full Screen

1import org.jmock.Mock;2import org.jmock.MockObjectTestCase;3import org.jmock.lib.action.ActionSequence;4public class 1 extends MockObjectTestCase {5 public void testActionSequence() {6 Mock mock = mock(Interface.class);7 mock.expects(once()).method("doSomething").with(eq("a")).will(8 new ActionSequence(new Action[]{9 returnValue("1"),10 returnValue("2"),11 returnValue("3")12 }));13 Interface i = (Interface) mock.proxy();14 assertEquals("1", i.doSomething("a"));15 assertEquals("2", i.doSomething("a"));16 assertEquals("3", i.doSomething("a"));17 }18}19public interface Interface {20 public String doSomething(String s);21}22junit.framework.AssertionFailedError: expected: once but: never invoked: doSomething("a") in sequence 023 at org.jmock.MockObjectTestCase.verifyExpectations(MockObjectTestCase.java:127)24 at org.jmock.MockObjectTestCase.runBare(MockObjectTestCase.java:88)25 at junit.framework.TestResult$1.protect(TestResult.java:106)26 at junit.framework.TestResult.runProtected(TestResult.java:124)27 at junit.framework.TestResult.run(TestResult.java:109)28 at junit.framework.TestCase.run(TestCase.java:124)29 at junit.framework.TestSuite.runTest(TestSuite.java:232)30 at junit.framework.TestSuite.run(TestSuite.java:227)31 at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)32 at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)33 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)34 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)35 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)36 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Full Screen

Full Screen

ActionSequence

Using AI Code Generation

copy

Full Screen

1package com.jmock.test;2import org.jmock.Mock;3import org.jmock.MockObjectTestCase;4import org.jmock.core.Invocation;5import org.jmock.lib.action.ActionSequence;6import org.jmock.lib.action.ReturnValueAction;7public class ActionSequenceTest extends MockObjectTestCase {8 public void testActionSequence() {9 Mock mock = mock(Invokable.class);10 mock.expects(once()).method("invoke").with(eq("one")).will(11 new ActionSequence(new ReturnValueAction("one"),12 new ReturnValueAction("two")));13 Invokable invokable = (Invokable) mock.proxy();14 assertEquals("one", invokable.invoke("one"));15 assertEquals("two", invokable.invoke("one"));16 }17}18package com.jmock.test;19import org.jmock.Mock;20import org.jmock.MockObjectTestCase;21import org.jmock.core.Invocation;22import org.jmock.lib.action.ActionSequence;23import org.jmock.lib.action.ReturnValueAction;24public class ActionSequenceTest extends MockObjectTestCase {25 public void testActionSequence() {26 Mock mock = mock(Invokable.class);27 mock.expects(once()).method("invoke").with(eq("one")).will(28 new ActionSequence(new ReturnValueAction("one"),29 new ReturnValueAction("two")));30 Invokable invokable = (Invokable) mock.proxy();31 assertEquals("one", invokable.invoke("one"));32 assertEquals("two", invokable.invoke("one"));33 }34}35package com.jmock.test;36import org.jmock.Mock;37import org.jmock.MockObjectTestCase;38import org.jmock.core.Invocation;39import org.jmock.lib.action.ActionSequence;40import org.jmock.lib.action.ReturnValueAction;41public class ActionSequenceTest extends MockObjectTestCase {42 public void testActionSequence() {43 Mock mock = mock(Invokable.class);44 mock.expects(once()).method("invoke").with(eq("one")).will(45 new ActionSequence(new ReturnValueAction("one"),46 new ReturnValueAction("two")));47 Invokable invokable = (Invokable) mock.proxy();48 assertEquals("one", invokable.invoke("one"));49 assertEquals("two", invokable.invoke("one"));50 }51}

Full Screen

Full Screen

ActionSequence

Using AI Code Generation

copy

Full Screen

1import org.jmock.*;2import org.jmock.lib.action.*;3import org.jmock.lib.legacy.ClassImposteriser;4{5 public void testActionSequence()6 {7 Mock mock = mock(Interface.class, "mock");8 mock.stubs().method("method").will(new ActionSequence(new Action[]{9 returnValue("1"),10 returnValue("2"),11 returnValue("3")12 }));13 Interface i = (Interface)mock.proxy();14 assertEquals("1", i.method());15 assertEquals("2", i.method());16 assertEquals("3", i.method());17 }18 {19 String method();20 }21}22import org.jmock.*;23import org.jmock.core.action.*;24import org.jmock.lib.legacy.ClassImposteriser;25{26 public void testActionSequence()27 {28 Mock mock = mock(Interface.class, "mock");29 mock.stubs().method("method").will(new ActionSequence(new Action[]{30 returnValue("1"),31 returnValue("2"),32 returnValue("3")33 }));34 Interface i = (Interface)mock.proxy();35 assertEquals("1", i.method());36 assertEquals("2", i.method());37 assertEquals("3", i.method());38 }39 {40 String method();41 }42}43import org.jmock.*;44import org.jmock.core.action.*;45import org.jmock.lib.legacy.ClassImposteriser;46{47 public void testActionSequence()48 {49 Mock mock = mock(Interface.class, "mock");50 mock.stubs().method("method").will(new ActionSequence(new Action[]{51 returnValue("1"),52 returnValue("2"),53 returnValue("3")54 }));55 Interface i = (Interface)mock.proxy();56 assertEquals("1", i.method());57 assertEquals("2", i.method());58 assertEquals("3", i.method());59 }60 {61 String method();62 }63}64import org.jmock.*;65import org.jmock.lib.action.*;66import org.j

Full Screen

Full Screen

ActionSequence

Using AI Code Generation

copy

Full Screen

1import org.jmock.*;2import org.jmock.lib.action.*;3public class 1 {4 public static void main(String[] args) {5 Mock mock = new Mock(MockedInterface.class);6 MockedInterface mocked = (MockedInterface) mock.proxy();7 mock.expects(once()).method("method1").with(eq("arg1")).will(returnValue("result1"));8 mock.expects(once()).method("method2").with(eq("arg2")).will(returnValue("result2"));9 ActionSequence actionSequence = new ActionSequence();10 actionSequence.add(new InvokeMethodAction("method1", new Object[]{"arg1"}));11 actionSequence.add(new InvokeMethodAction("method2", new Object[]{"arg2"}));12 mock.expects(once()).method("method3").with(eq("arg3")).will(actionSequence);13 System.out.println(mocked.method3("arg3"));14 }15}16import org.jmock.*;17import org.jmock.lib.action.*;18public class 2 {19 public static void main(String[] args) {20 Mock mock = new Mock(MockedInterface.class);21 MockedInterface mocked = (MockedInterface) mock.proxy();22 mock.expects(once()).method("method1").with(eq("arg1")).will(returnValue("result1"));23 mock.expects(once()).method("method2").with(eq("arg2")).will(returnValue("result2"));24 ActionSequence actionSequence = new ActionSequence();25 actionSequence.add(new InvokeMethodAction("method1", new Object[]{"arg1"}));26 actionSequence.add(new InvokeMethodAction("method2", new Object[]{"arg2"}));27 mock.expects(once()).method("method3").with(eq("arg3")).will(actionSequence);28 System.out.println(mocked.method3("arg3"));29 }30}31import org.jmock.*;32import org.jmock.lib.action.*;33public class 3 {34 public static void main(String[] args) {35 Mock mock = new Mock(MockedInterface.class);36 MockedInterface mocked = (MockedInterface) mock.proxy();37 mock.expects(once()).method("method1").with(eq("arg1")).will(returnValue("result1"));

Full Screen

Full Screen

ActionSequence

Using AI Code Generation

copy

Full Screen

1import junit.framework.TestCase;2import org.jmock.Mock;3import org.jmock.MockObjectTestCase;4import org.jmock.core.Invocation;5import org.jmock.core.InvocationMatcher;6import org.jmock.core.Stub;7import org.jmock.core.constraint.IsEqual;8import org.jmock.core.constraint.IsAnything;9import org.jmock.core.constraint.IsEqual;10import org.jmock.core.constraint.IsSame;11import org.jmock.core.matcher.InvokeOnceMatcher;12import org.jmock.core.matcher.InvokeAtLeastOnceMatcher;13import org.jmock.core.matcher.InvokeAtMostOnceMatcher;14import org.jmock.core.matcher.InvokeAtLeastMatcher;15import org.jmock.core.matcher.InvokeAtMostMatcher;16import org.jmock.core.matcher.InvokeCountMatcher;17import org.jmock.core.matcher.InvokeBetweenMatcher;18import org.jmock.core.matcher.InvokeExactlyMatcher;19import org.jmock.core.matcher.InvokeOnceOrMoreMatcher;20import org.jmock.core.matcher.InvokeOnceOrLessMatcher;21import org.jmock.core.matcher.InvokeNeverMatcher;22import org.jmock.core.matcher.InvokeRangeMatcher;23import org.jmock.core.matcher.InvokeAtLeastOnceOrMoreMatcher;24import org.jmock.core.matcher.InvokeAtLeastOnceOrLessMatcher;25import org.jmock.core.matcher.InvokeAtLeastOrMoreMatcher;26import org.jmock.core.matcher.InvokeAtLeastOrLessMatcher;27import org.jmock.core.matcher.InvokeAtMostOnceOrMoreMatcher;28import org.jmock.core.matcher.InvokeAtMostOnceOrLessMatcher;29import org.jmock.core.matcher.InvokeAtMostOrMoreMatcher;30import org.jmock.core.matcher.InvokeAtMostOrLessMatcher;31import org.jmock.core.matcher.InvokeExactlyOrMoreMatcher;32import org.jmock.core.matcher.InvokeExactlyOrLessMatcher;33import org.jmock.core.matcher.InvokeBetweenOrMoreMatcher;34import org.jmock.core.matcher.InvokeBetweenOrLessMatcher;35import org.jmock.core.matcher.InvokeRangeOrMoreMatcher;36import org.jmock.core.matcher.InvokeRangeOrLessMatcher;37import org.jmock.core.matcher.InvokeCountOrMoreMatcher;38import org.jmock.core.matcher.InvokeCountOrLessMatcher;39import org.jmock.core.matcher.InvokeAtLeastOnceAndAtMostOnceMatcher;40import org.jmock.core.matcher.InvokeAtLeastAndAtMostMatcher;41import org.jmock.core.matcher.InvokeAtLeastOnceAndAtMostMatcher;42import org.jmock.core.matcher.InvokeAtLeastAndAtMostOnceMatcher;43import org.jmock.core.matcher.InvokeAtLeastOnceAndAtMostOnceOrMoreMatcher

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Jmock-library automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in ActionSequence

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful