How to use invocationReturning method of org.jmock.test.unit.internal.ReturnDefaultValueActionTests class

Best Jmock-library code snippet using org.jmock.test.unit.internal.ReturnDefaultValueActionTests.invocationReturning

Source:ReturnDefaultValueActionTests.java Github

copy

Full Screen

...43 assertHasRegisteredValue(action, Float.class, new Float(0.0F));44 assertHasRegisteredValue(action, Double.class, new Double(0.0));45 assertHasRegisteredValue(action, String.class, "");46 assertNotNull( "should return an object for Object return type",47 action.invoke(invocationReturning(Object.class)) );48 }49 public void testReturnsEmptyArrayForAllArrayTypes()50 throws Throwable51 {52 int[] defaultArrayForPrimitiveType =53 (int[])action.invoke(invocationReturning(int[].class));54 assertEquals("should be empty array", 0, defaultArrayForPrimitiveType.length);55 Object[] defaultArrayForReferenceType =56 (Object[])action.invoke(invocationReturning(Object[].class));57 assertEquals("should be empty array", 0, defaultArrayForReferenceType.length);58 }59 public interface InterfaceType {60 int returnInt();61 }62 // Inspired by http://www.c2.com/cgi/wiki?JavaNullProxy63 public void testIfImposteriserCanImposteriseReturnTypeReturnsNewMockObjectWithSameReturnDefaultValueAction() throws Throwable {64 Imposteriser imposteriser = new JavaReflectionImposteriser() {65 @Override66 public boolean canImposterise(Class<?> c) {67 return c == InterfaceType.class;68 }69 };70 71 action = new ReturnDefaultValueAction(imposteriser);72 73 int intResult = -1;74 75 action.addResult(int.class, new Integer(intResult));76 77 InterfaceType result = (InterfaceType)action.invoke(invocationReturning(InterfaceType.class));78 79 assertEquals("int result from 'null' interface implementation",80 intResult, result.returnInt());81 82 assertEquals("should not have returned a mock Runnable because the imposteriser cannot imposterise it",83 null, action.invoke(invocationReturning(Runnable.class)));84 }85 86 public void testDefaultResultsCanBeExplicitlyOverriddenByType() throws Throwable {87 int newDefaultIntResult = 20;88 String newDefaultStringResult = "hello";89 action.addResult(String.class, newDefaultStringResult);90 action.addResult(int.class, new Integer(newDefaultIntResult));91 assertEquals("expected registered value for string result type",92 newDefaultStringResult, action.invoke(invocationReturning(String.class)));93 assertEquals("expected registered value for int result type",94 new Integer(newDefaultIntResult), action.invoke(invocationReturning(int.class)));95 }96 public void testAnExplicitlyRegisteredResultOverridesThePreviousResultForTheSameType() throws Throwable {97 action.addResult(String.class, "result1");98 action.addResult(String.class, "result2");99 assertEquals("expected second result",100 "result2", action.invoke(invocationReturning(String.class)));101 }102 class UnsupportedReturnType103 {104 }105 public void testInvocationWithAnUnsupportedReturnTypeReturnsNull()106 throws Throwable107 {108 Class<?> unsupportedReturnType = UnsupportedReturnType.class;109 Object result = action.invoke(invocationReturning(unsupportedReturnType));110 111 assertNull("should have returned null", result);112 }113 114 public void assertHasRegisteredValue(ReturnDefaultValueAction action,115 Class<?> resultType,116 Object resultValue )117 throws Throwable118 {119 assertEquals("expected " + resultValue + " to be returned",120 resultValue, action.invoke(invocationReturning(resultType)));121 }122 public void assertHasNotRegisteredReturnType( ReturnDefaultValueAction action,123 Class<?> resultType )124 throws Throwable125 {126 try {127 action.invoke(invocationReturning(resultType));128 fail("action should not support return type " + resultType);129 }130 catch (AssertionFailedError expected) {131 return;132 }133 }134 private Invocation invocationReturning(Class<?> resultType) {135 return new Invocation("INVOKED-OBJECT",136 METHOD_FACTORY.newMethodReturning(resultType),137 NO_ARG_VALUES);138 }139}...

Full Screen

Full Screen

Source:ReturnDefaultCollectionTests.java Github

copy

Full Screen

...7import java.beans.beancontext.BeanContextServices;8import java.util.*;9import static org.hamcrest.MatcherAssert.assertThat;10import static org.hamcrest.Matchers.*;11import static org.jmock.test.unit.internal.ReturnDefaultValueActionTests.invocationReturning;12/**13 * @author Steve Freeman 2013 http://www.jmock.org14 * https://github.com/jmock-developers/jmock-library/issues/915 */16public class ReturnDefaultCollectionTests {17 abstract static class AbstractCollection implements Collection {}18 private static final Matcher<Object> IS_PROXY_CLASS = hasProperty("canonicalName", containsString("Proxy"));19 private final ReturnDefaultValueAction action = new ReturnDefaultValueAction();20 @SuppressWarnings("unchecked")21 @Test public void22 returnsANewInstanceForEachCall() throws Throwable {23 final ArrayList<Object> firstInstance = returnedArrayList();24 firstInstance.add(new Object());25 assertThat(returnedArrayList(), is(empty()));26 }27 @Test public void28 returnsNewInstanceOfIterableClasses() throws Throwable {29 returnsInstanceForType(ArrayList.class, ArrayList.class);30 returnsInstanceForType(PriorityQueue.class, PriorityQueue.class);31 }32 @Test public void33 returnsNewInstanceOfMapClasses() throws Throwable {34 returnsInstanceForType(HashMap.class, HashMap.class);35 returnsInstanceForType(Properties.class, Properties.class);36 }37 @Test public void38 returnsNewInstanceConformingToCollectionInterface() throws Throwable {39 returnsInstanceForType(List.class, LinkedList.class);40 returnsInstanceForType(Set.class, TreeSet.class);41 returnsInstanceForType(NavigableSet.class, TreeSet.class);42 returnsInstanceForType(SortedSet.class, TreeSet.class);43 returnsInstanceForType(Queue.class, LinkedList.class);44 returnsInstanceForType(Deque.class, LinkedList.class);45 }46 // https://github.com/jmock-developers/jmock-library/issues/4647 @Test public void48 imposterisesBeanContextTypesToAvoidMissingTypesInAndroid() throws Throwable {49 assertThat(action.invoke(invocationReturning(BeanContext.class)).getClass(), IS_PROXY_CLASS);50 assertThat(action.invoke(invocationReturning(BeanContextServices.class)).getClass(), IS_PROXY_CLASS);51 }52 @Test public void53 returnsNewInstanceConformingToMapType() throws Throwable {54 returnsInstanceForType(Map.class, TreeMap.class);55 returnsInstanceForType(SortedMap.class, TreeMap.class);56 returnsInstanceForType(NavigableMap.class, TreeMap.class);57 }58 @Test public void59 imposterisesUnsupportedMapTypes() throws Throwable {60 assertThat(action.invoke(invocationReturning(LogicalMessageContext.class)).getClass(), IS_PROXY_CLASS);61 }62 63 @Test public void64 returnsNullForAbstractCollections() throws Throwable {65 assertThat(action.invoke(invocationReturning(AbstractCollection.class)), is(nullValue()));66 }67 private void returnsInstanceForType(Class<?> declaredType, Class<?> expectedType) throws Throwable {68 assertThat(69 action.invoke(invocationReturning(declaredType)),70 instanceOf(expectedType));71 }72 @SuppressWarnings("unchecked")73 private ArrayList<Object> returnedArrayList() throws Throwable {74 return (ArrayList<Object>) action.invoke(invocationReturning(ArrayList.class));75 }76}...

Full Screen

Full Screen

invocationReturning

Using AI Code Generation

copy

Full Screen

1package org.jmock.test.unit.internal;2import org.jmock.Expectations;3import org.jmock.Mockery;4import org.jmock.api.Invocation;5import org.jmock.internal.ReturnDefaultValueAction;6import org.jmock.test.unit.support.MethodFactory;7import org.junit.Test;8public class ReturnDefaultValueActionTests {9 ReturnDefaultValueAction action = new ReturnDefaultValueAction();10 Mockery context = new Mockery();11 Invocation invocation = context.mock(Invocation.class);12 public void returnsNullForVoidMethod() throws Throwable {13 context.checking(new Expectations() {{14 allowing (invocation).getMethod(); will (returnValue(MethodFactory.methodReturning(void.class)));15 }});16 assertThat(action.invocationReturning(invocation), is(nullValue()));17 }18 public void returnsNullForMethodReturningNull() throws Throwable {19 context.checking(new Expectations() {{20 allowing (invocation).getMethod(); will (returnValue(MethodFactory.methodReturning(Object.class)));21 }});22 assertThat(action.invocationReturning(invocation), is(nullValue()));23 }24 public void returnsFalseForMethodReturningBoolean() throws Throwable {25 context.checking(new Expectations() {{26 allowing (invocation).getMethod(); will (returnValue(MethodFactory.methodReturning(boolean.class)));27 }});28 assertThat(action.invocationReturning(invocation), is(false));29 }30 public void returnsZeroForMethodReturningByte() throws Throwable {31 context.checking(new Expectations() {{32 allowing (invocation).getMethod(); will (returnValue(MethodFactory.methodReturning(byte.class)));33 }});34 assertThat(action.invocationReturning(invocation), is((byte)0));35 }36 public void returnsZeroForMethodReturningChar() throws Throwable {37 context.checking(new Expectations() {{38 allowing (invocation).getMethod(); will (returnValue(MethodFactory.methodReturning(char.class)));39 }});40 assertThat(action.invocationReturning(invocation), is((char)0));41 }42 public void returnsZeroForMethodReturningShort() throws Throwable {43 context.checking(new Expectations() {{44 allowing (invocation).getMethod(); will (returnValue(MethodFactory.methodReturning(short.class)));45 }});46 assertThat(action.invocationReturning(invocation), is((short)0));47 }48 public void returnsZeroForMethodReturningInt() throws Throwable {49 context.checking(new Expectations() {{50 allowing (inv

Full Screen

Full Screen

invocationReturning

Using AI Code Generation

copy

Full Screen

1package org.jmock.test.unit.internal;2import org.jmock.Mockery;3import org.jmock.api.Invocation;4import org.jmock.internal.ReturnDefaultValueAction;5import org.jmock.test.unit.lib.ClassImposteriserTest;6import junit.framework.TestCase;7public class ReturnDefaultValueActionTests extends TestCase {8 private Mockery context = new Mockery();9 private Invocation invocation = context.mock(Invocation.class);10 private ReturnDefaultValueAction action = new ReturnDefaultValueAction();11 private ClassImposteriserTest classImposteriserTest = new ClassImposteriserTest();12 private ClassImposteriserTest classImposteriserTest1 = new ClassImposteriserTest();13 private ClassImposteriserTest classImposteriserTest2 = new ClassImposteriserTest();14 private ClassImposteriserTest classImposteriserTest3 = new ClassImposteriserTest();15 private ClassImposteriserTest classImposteriserTest4 = new ClassImposteriserTest();16 private ClassImposteriserTest classImposteriserTest5 = new ClassImposteriserTest();17 private ClassImposteriserTest classImposteriserTest6 = new ClassImposteriserTest();18 private ClassImposteriserTest classImposteriserTest7 = new ClassImposteriserTest();19 private ClassImposteriserTest classImposteriserTest8 = new ClassImposteriserTest();20 private ClassImposteriserTest classImposteriserTest9 = new ClassImposteriserTest();21 private ClassImposteriserTest classImposteriserTest10 = new ClassImposteriserTest();22 private ClassImposteriserTest classImposteriserTest11 = new ClassImposteriserTest();23 private ClassImposteriserTest classImposteriserTest12 = new ClassImposteriserTest();24 private ClassImposteriserTest classImposteriserTest13 = new ClassImposteriserTest();25 private ClassImposteriserTest classImposteriserTest14 = new ClassImposteriserTest();26 private ClassImposteriserTest classImposteriserTest15 = new ClassImposteriserTest();27 private ClassImposteriserTest classImposteriserTest16 = new ClassImposteriserTest();28 private ClassImposteriserTest classImposteriserTest17 = new ClassImposteriserTest();29 private ClassImposteriserTest classImposteriserTest18 = new ClassImposteriserTest();

Full Screen

Full Screen

invocationReturning

Using AI Code Generation

copy

Full Screen

1public class TestClass {2 public static void main(String[] args) {3 ReturnDefaultValueActionTests test = new ReturnDefaultValueActionTests();4 test.invocationReturning();5 }6}7public class TestClass {8 public static void main(String[] args) {9 ReturnDefaultValueActionTests test = new ReturnDefaultValueActionTests();10 test.invoke();11 }12}13public class TestClass {14 public static void main(String[] args) {15 ReturnDefaultValueActionTests test = new ReturnDefaultValueActionTests();16 test.invokeWithNullArgument();17 }18}19public class TestClass {20 public static void main(String[] args) {21 ReturnDefaultValueActionTests test = new ReturnDefaultValueActionTests();22 test.invocationReturning();23 }24}25public class TestClass {26 public static void main(String[] args) {27 ReturnDefaultValueActionTests test = new ReturnDefaultValueActionTests();28 test.invocationReturning();29 }30}31public class TestClass {32 public static void main(String[] args) {33 ReturnDefaultValueActionTests test = new ReturnDefaultValueActionTests();34 test.invoke();35 }36}37public class TestClass {38 public static void main(String[] args) {39 ReturnDefaultValueActionTests test = new ReturnDefaultValueActionTests();40 test.invoke();41 }42}43public class TestClass {44 public static void main(String[] args) {45 ReturnDefaultValueActionTests test = new ReturnDefaultValueActionTests();46 test.invoke();47 }48}

Full Screen

Full Screen

invocationReturning

Using AI Code Generation

copy

Full Screen

1package org.jmock.test.unit.internal;2import java.io.Serializable;3import org.jmock.api.Invocation;4import org.jmock.api.Invokable;5import org.jmock.internal.ReturnDefaultValueAction;6import org.jmock.test.unit.internal.ReturnDefaultValueActionTests.InvocationReturning;7import org.junit.Before;8import org.junit.Test;9public class ReturnDefaultValueActionTest {10 private ReturnDefaultValueAction action;11 private InvocationReturning invocationReturning;12 public void setUp() throws Exception {13 action = new ReturnDefaultValueAction();14 invocationReturning = new InvocationReturning();15 }16 public void testInvokable() {17 Invokable invokable = new Invokable() {18 public Object invoke(Invocation invocation) throws Throwable {19 return invocationReturning.invocationReturning(invocation);20 }21 };22 action.invokable(invokable);23 }24 public void testInvocationReturning() {25 Invocation invocation = new Invocation() {26 public Object invoke(Invokable invokable) throws Throwable {27 return invokable.invoke(this);28 }29 public Object invoke() throws Throwable {30 return invocationReturning.invocationReturning(this);31 }32 public Object invoke(Object... arguments) throws Throwable {33 return invocationReturning.invocationReturning(this);34 }35 public Object invokeIn(Object target) throws Throwable {36 return invocationReturning.invocationReturning(this);37 }38 public Object invokeIn(Object target, Object... arguments) throws Throwable {39 return invocationReturning.invocationReturning(this);40 }41 public Object invokeOn(Object target) throws Throwable {42 return invocationReturning.invocationReturning(this);43 }44 public Object invokeOn(Object target, Object... arguments) throws Throwable {45 return invocationReturning.invocationReturning(this);46 }47 public Object invokeWith(Object... arguments) throws Throwable {48 return invocationReturning.invocationReturning(this);49 }50 public Object returnValue() throws Throwable {51 return invocationReturning.invocationReturning(this);52 }53 public Object returnValueIn(Object target) throws Throwable {54 return invocationReturning.invocationReturning(this);55 }56 public Object returnValueIn(Object target, Object... arguments) throws Throwable {57 return invocationReturning.invocationReturning(this);58 }59 public Object returnValueOn(Object target) throws Throwable {60 return invocationReturning.invocationReturning(this);61 }62 public Object returnValueOn(Object target, Object... arguments)

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 method in ReturnDefaultValueActionTests

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful