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

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

Source:ReturnEnumerationActionTests.java Github

copy

Full Screen

...5import junit.framework.TestCase;6import org.hamcrest.StringDescription;7import org.jmock.api.Action;8import org.jmock.api.Invocation;9import org.jmock.lib.action.ReturnEnumerationAction;10public class ReturnEnumerationActionTests extends TestCase {11 private static final Object[] resultElements = {"0", "1", "2", "3"};12 13 public void testReturnsIteratorOverContentsOfCollection() throws Throwable {14 Collection<Object> collection = collectionOf(resultElements);15 ReturnEnumerationAction action = new ReturnEnumerationAction(collection);16 17 assertEnumerationOverSequence(action.invoke(ANY_INVOCATION), resultElements);18 }19 20 public void testReturnsNewIteratorOnEachInvocation() throws Throwable {21 Collection<?> collection = collectionOf(resultElements);22 ReturnEnumerationAction action = new ReturnEnumerationAction(collection);23 24 assertEnumerationOverSequence(action.invoke(ANY_INVOCATION), resultElements);25 assertEnumerationOverSequence(action.invoke(ANY_INVOCATION), resultElements);26 assertEnumerationOverSequence(action.invoke(ANY_INVOCATION), resultElements);27 }28 29 public void testCanReturnIteratorOverArray() throws Throwable {30 ReturnEnumerationAction action = new ReturnEnumerationAction(resultElements);31 32 assertEnumerationOverSequence(action.invoke(ANY_INVOCATION), resultElements);33 }34 35 public void testHasAReadableDescription() {36 Action action = new ReturnEnumerationAction(resultElements);37 38 assertEquals("return enumeration over \"0\", \"1\", \"2\", \"3\"", 39 StringDescription.toString(action));40 }41 42 private <T> Collection<T> collectionOf(T... values) {43 return Arrays.asList(values);44 }45 46 private <T> void assertEnumerationOverSequence(Enumeration<?> e, T[] values) {47 for (int i = 0; i < values.length; i++) {48 assertEquals("element " + i,49 values[i], e.nextElement());50 }...

Full Screen

Full Screen

Source:ReturnEnumerationAction.java Github

copy

Full Screen

...10 * Returns an {@link Enumeration} over a collection.11 * 12 * @author nat13 */14public class ReturnEnumerationAction implements Action {15 private Collection<?> collection;16 17 public ReturnEnumerationAction(Collection<?> collection) {18 this.collection = collection;19 }20 21 public ReturnEnumerationAction(Object... array) {22 this.collection = Arrays.asList(array);23 }24 25 public Enumeration<?> invoke(Invocation invocation) throws Throwable {26 return enumeration(collection);27 }28 29 public void describeTo(Description description) {30 description.appendValueList("return enumeration over ", ", ", "", collection);31 }32}...

Full Screen

Full Screen

ReturnEnumerationAction

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.ReturnEnumerationAction;6import java.util.Enumeration;7import java.util.Vector;8{9 public void testReturnEnumerationAction()10 {11 Mock mock = mock(Stub.class);12 mock.expects(once()).method("invoke").will(returnEnumeration(new String[]{"Hello", "World"}));13 Enumeration enumeration = (Enumeration) mock.proxy();14 assertTrue(enumeration.hasMoreElements());15 assertEquals("Hello", enumeration.nextElement());16 assertTrue(enumeration.hasMoreElements());17 assertEquals("World", enumeration.nextElement());18 assertFalse(enumeration.hasMoreElements());19 }20 public void testReturnEnumerationActionWithNull()21 {22 Mock mock = mock(Stub.class);23 mock.expects(once()).method("invoke").will(returnEnumeration(null));24 Enumeration enumeration = (Enumeration) mock.proxy();25 assertFalse(enumeration.hasMoreElements());26 }27 public void testReturnEnumerationActionWithEmptyArray()28 {29 Mock mock = mock(Stub.class);30 mock.expects(once()).method("invoke").will(returnEnumeration(new String[0]));31 Enumeration enumeration = (Enumeration) mock.proxy();32 assertFalse(enumeration.hasMoreElements());33 }34 public void testReturnEnumerationActionWithNullArray()35 {36 Mock mock = mock(Stub.class);37 mock.expects(once()).method("invoke").will(returnEnumeration((Object[]) null));38 Enumeration enumeration = (Enumeration) mock.proxy();39 assertFalse(enumeration.hasMoreElements());40 }41 public void testReturnEnumerationActionWithVector()42 {43 Mock mock = mock(Stub.class);44 Vector vector = new Vector();45 vector.add("Hello");46 vector.add("World");47 mock.expects(once()).method("invoke").will(returnEnumeration(vector));48 Enumeration enumeration = (Enumeration) mock.proxy();49 assertTrue(enumeration.hasMoreElements());50 assertEquals("Hello", enumeration.nextElement());51 assertTrue(enumeration.hasMoreElements());52 assertEquals("World", enumeration.nextElement());53 assertFalse(enumeration.hasMoreElements());54 }55 public void testReturnEnumerationActionWithNullVector()56 {57 Mock mock = mock(Stub.class);58 mock.expects(once()).method("invoke").will(returnEnumeration((Vector) null));59 Enumeration enumeration = (Enumeration) mock.proxy();60 assertFalse(

Full Screen

Full Screen

ReturnEnumerationAction

Using AI Code Generation

copy

Full Screen

1package com.ack.jmock;2import org.jmock.Mock;3import org.jmock.MockObjectTestCase;4import org.jmock.core.Invocation;5import org.jmock.core.Stub;6import org.jmock.lib.action.ReturnEnumerationAction;7import java.util.Enumeration;8public class ReturnEnumerationActionTest extends MockObjectTestCase {9 public void testReturnEnumerationAction() {10 Mock mock = mock( Stub.class );11 Enumeration e = new Enumeration() {12 private int count = 0;13 public boolean hasMoreElements() {14 return count < 3;15 }16 public Object nextElement() {17 count++;18 return new Integer( count );19 }20 };21 ReturnEnumerationAction returnEnumerationAction = new ReturnEnumerationAction( e );22 mock.expects( once() ).method( "invoke" ).with( ANYTHING )23 .will( returnEnumerationAction );24 Stub stub = (Stub) mock.proxy();25 Invocation invocation = new Invocation( this, "method", new Object[]{},26 0 );27 assertEquals( new Integer( 1 ), stub.invoke( invocation ) );28 assertEquals( new Integer( 2 ), stub.invoke( invocation ) );29 assertEquals( new Integer( 3 ), stub.invoke( invocation ) );30 assertEquals( new Integer( 1 ), stub.invoke( invocation ) );31 assertEquals( new Integer( 2 ), stub.invoke( invocation ) );32 assertEquals( new Integer( 3 ), stub.invoke( invocation ) );33 }34}35package com.ack.jmock;36import org.jmock.Mock;37import org.jmock.MockObjectTestCase;38import org.jmock.core.Invocation;39import org.jmock.core.Stub;40import org.jmock.lib.action.ReturnEnumerationAction;41import java.util.Enumeration;42public class ReturnEnumerationActionTest extends MockObjectTestCase {43 public void testReturnEnumerationAction() {44 Mock mock = mock( Stub.class );45 Enumeration e = new Enumeration() {46 private int count = 0;47 public boolean hasMoreElements() {48 return count < 3;49 }50 public Object nextElement() {51 count++;52 return new Integer( count );53 }54 };55 ReturnEnumerationAction returnEnumerationAction = new ReturnEnumerationAction( e );56 mock.expects( once() ).method( "invoke" ).with( ANYTHING )57 .will(

Full Screen

Full Screen

ReturnEnumerationAction

Using AI Code Generation

copy

Full Screen

1package com.jmock;2import org.jmock.Mock;3import org.jmock.MockObjectTestCase;4import org.jmock.lib.action.ReturnEnumerationAction;5import java.util.Enumeration;6import java.util.Vector;7{8 public void testReturnEnumerationAction()9 {10 Mock mock = mock(Enumeration.class);11 Enumeration enumeration = (Enumeration) mock.proxy();12 Vector vector = new Vector();13 vector.add("hello");14 vector.add("world");15 Enumeration expectedEnumeration = vector.elements();16 mock.expects(once()).method("nextElement").will(17 new ReturnEnumerationAction(expectedEnumeration));18 assertEquals("hello", enumeration.nextElement());19 assertEquals("world", enumeration.nextElement());20 }21}22 Enumeration expectedEnumeration = vector.elements();

Full Screen

Full Screen

ReturnEnumerationAction

Using AI Code Generation

copy

Full Screen

1package com.jmock;2import junit.framework.TestCase;3import org.jmock.Mock;4import org.jmock.MockObjectTestCase;5import org.jmock.core.Constraint;6import org.jmock.core.constraint.IsEqual;7import org.jmock.core.constraint.IsAnything;8import org.jmock.core.constraint.IsSame;9import org.jmock.core.matcher.InvokeOnceMatcher;10import org.jmock.core.matcher.InvokeAtLeastOnceMatcher;11import org.jmock.core.matcher.InvokeAtMostOnceMatcher;12import org.jmock.core.matcher.InvokeAtLeastMatcher;13import org.jmock.core.matcher.InvokeAtMostMatcher;14import org.jmock.core.matcher.InvokeCountMatcher;15import org.jmock.core.matcher.InvokeBetweenMatcher;16import org.jmock.core.matcher.InvokeId;17import org.jmock.core.matcher.InvokeIdMatcher;18import org.jmock.core.matcher.InvokeIdRangeMatcher;19import org.jmock.core.matcher.InvokeIdSequenceMatcher;20import org.jmock.core.matcher.InvokeIdSetMatcher;21import org.jmock.core.matcher.InvokeIdTimesMatcher;22import org.jmock.core.matcher.InvokeSequentiallyMatcher;23import org.jmock.core.matcher.InvokeNeverMatcher;24import org.jmock.core.matcher.InvokeOnceOrMoreMatcher;25import org.jmock.core.matcher.InvokeOnceOrLessMatcher;26import org.jmock.core.matcher.InvokeOnceOrMoreTimesMatcher;27import org.jmock.core.matcher.InvokeOnceOrLessTimesMatcher;28import org.jmock.core.matcher.InvokeTimesMatcher;29import org.jmock.core.matcher.InvokeAtLeastOnceOrMoreMatcher;30import org.jmock.core.matcher.InvokeAtLeastOnceOrLessMatcher;31import org.jmock.core.matcher.InvokeAtLeastOnceOrMoreTimesMatcher;32import org.jmock.core.matcher.InvokeAtLeastOnceOrLessTimesMatcher;33import org.jmock.core.matcher.InvokeAtLeastOrMoreMatcher;34import org.jmock.core.matcher.InvokeAtLeastOrLessMatcher;35import org.jmock.core.matcher.InvokeAtLeastOrMoreTimesMatcher;36import org.jmock.core.matcher.InvokeAtLeastOrLessTimesMatcher;37import org.jmock.core.matcher.InvokeAtMostOnceOrMoreMatcher;38import org.jmock.core.matcher.InvokeAtMostOnceOrLessMatcher;39import org.jmock.core.matcher.InvokeAtMostOnceOrMoreTimesMatcher;40import org.jmock.core.matcher.InvokeAtMostOnceOrLessTimesMatcher;41import org.jmock.core.matcher.InvokeAtMostOrMoreMatcher;42import org.jmock.core.matcher.InvokeAtMostOrLessMatcher;43import org.jmock.core.matcher.InvokeAtMostOrMoreTimesMatcher;44import org.jmock.core.matcher.InvokeAtMostOr

Full Screen

Full Screen

ReturnEnumerationAction

Using AI Code Generation

copy

Full Screen

1package com.jmockexample;2import org.jmock.Mock;3import org.jmock.MockObjectTestCase;4import org.jmock.lib.action.ReturnEnumerationAction;5import java.util.Enumeration;6import java.util.Vector;7public class ReturnEnumerationActionTest extends MockObjectTestCase {8 public void testReturnEnumerationAction() {9 Mock mock = mock(Enumeration.class);10 Vector v = new Vector();11 v.add("One");12 v.add("Two");13 v.add("Three");14 v.add("Four");15 mock.expects(once()).method("nextElement").will(16 new ReturnEnumerationAction(v.elements()));17 Enumeration e = (Enumeration) mock.proxy();18 assertEquals("One", e.nextElement());19 assertEquals("Two", e.nextElement());20 assertEquals("Three", e.nextElement());21 assertEquals("Four", e.nextElement());22 }23}

Full Screen

Full Screen

ReturnEnumerationAction

Using AI Code Generation

copy

Full Screen

1package com.jmock.example;2import org.jmock.Mockery;3import org.jmock.Expectations;4import org.jmock.lib.action.ReturnEnumerationAction;5import java.util.Enumeration;6import java.util.Vector;7public class ReturnEnumerationActionExample{8 public static void main(String[] args) {9 final Mockery context = new Mockery();10 final Enumeration enumeration = context.mock(Enumeration.class);11 Vector vector = new Vector();12 vector.add("one");13 vector.add("two");14 context.checking(new Expectations() {{15 oneOf (enumeration).hasMoreElements();16 will(new ReturnEnumerationAction(vector.elements()));17 oneOf (enumeration).nextElement();18 will(new ReturnEnumerationAction(vector.elements()));19 }});20 while (enumeration.hasMoreElements()) {21 System.out.println(enumeration.nextElement());22 }23 }24}

Full Screen

Full Screen

ReturnEnumerationAction

Using AI Code Generation

copy

Full Screen

1package org.jmock.test.acceptance;2import org.jmock.Mock;3import org.jmock.MockObjectTestCase;4import org.jmock.core.Constraint;5import org.jmock.core.constraint.IsEqual;6import org.jmock.lib.action.ReturnEnumerationAction;7import java.util.Enumeration;8import java.util.Vector;9public class ReturnEnumerationActionTest extends MockObjectTestCase {10 public void testReturnsEnumerationOfValues() {11 Mock mock = mock(Enumeration.class);12 mock.expects(once()).method("nextElement").will(returnEnumeration(new Object[] { "one", "two", "three" }));13 Enumeration enumeration = (Enumeration) mock.proxy();14 assertEquals("one", enumeration.nextElement());15 assertEquals("two", enumeration.nextElement());16 assertEquals("three", enumeration.nextElement());17 }18 public void testReturnsEnumerationOfValuesWithConstraints() {19 Mock mock = mock(Enumeration.class);20 mock.expects(once()).method("nextElement").with(isEqual("one")).will(returnEnumeration(new Object[] { "one", "two", "three" }));21 Enumeration enumeration = (Enumeration) mock.proxy();22 assertEquals("one", enumeration.nextElement());23 assertEquals("two", enumeration.nextElement());24 assertEquals("three", enumeration.nextElement());25 }26 public void testReturnsEnumerationOfValuesWithConstraintsAndNulls() {27 Mock mock = mock(Enumeration.class);28 mock.expects(once()).method("nextElement").with(isEqual("one")).will(returnEnumeration(new Object[] { "one", null, "three" }));29 Enumeration enumeration = (Enumeration) mock.proxy();30 assertEquals("one", enumeration.nextElement());31 assertNull(enumeration.nextElement());32 assertEquals("three", enumeration.nextElement());33 }34 public void testReturnsEnumerationOfValuesWithConstraintsAndNullsAndEmptyArray() {35 Mock mock = mock(Enumeration.class);36 mock.expects(once()).method("nextElement").with(isEqual("one")).will(returnEnumeration(new Object[] {}));37 Enumeration enumeration = (Enumeration) mock.proxy();38 assertEquals("one", enumeration.nextElement());39 }40 public void testReturnsEnumerationOfValuesWithConstraintsAndNullsAndNullArray() {41 Mock mock = mock(Enumeration.class);42 mock.expects(once()).method("nextElement").with(isEqual("one")).will(returnEnumeration(null));43 Enumeration enumeration = (Enumeration) mock.proxy();44 assertEquals("one", enumeration.nextElement());45 }

Full Screen

Full Screen

ReturnEnumerationAction

Using AI Code Generation

copy

Full Screen

1{2 public void testReturnsEnumerationOfValues()3 {4 ReturnEnumerationAction action = new ReturnEnumerationAction(5 new Object[] { "one", "two", "three" }6 );7 assertEquals("one", action.perform(null));8 assertEquals("two", action.perform(null));9 assertEquals("three", action.perform(null));10 assertEquals("one", action.perform(null));11 assertEquals("two", action.perform(null));12 }13}14{15 public void testReturnsEnumerationOfValues()16 {17 ReturnEnumerationAction action = new ReturnEnumerationAction(18 new Object[] { "one", "two", "three" }19 );20 assertEquals("one", action.perform(null));21 assertEquals("two", action.perform(null));22 assertEquals("three", action.perform(null));23 assertEquals("one", action.perform(null));24 assertEquals("two", action.perform(null));25 }26}27{28 public void testReturnsEnumerationOfValues()29 {30 ReturnEnumerationAction action = new ReturnEnumerationAction(31 new Object[] { "one", "two", "three" }32 );33 assertEquals("one", action.perform(null));34 assertEquals("two", action.perform(null));35 assertEquals("three", action.perform(null));36 assertEquals("one", action.perform(null));37 assertEquals("two", action.perform(null));38 }39}

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 ReturnEnumerationAction

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