Best Jmock-library code snippet using org.jmock.internal.InvocationToExpectationTranslator.InvocationToExpectationTranslator
Source:Mockery.java
...17import org.jmock.internal.ExpectationBuilder;18import org.jmock.internal.ExpectationCapture;19import org.jmock.internal.InvocationDispatcher;20import org.jmock.internal.InvocationDiverter;21import org.jmock.internal.InvocationToExpectationTranslator;22import org.jmock.internal.NamedSequence;23import org.jmock.internal.ObjectMethodExpectationBouncer;24import org.jmock.internal.ProxiedObjectIdentity;25import org.jmock.internal.ReturnDefaultValueAction;26import org.jmock.internal.SingleThreadedPolicy;27import org.jmock.lib.CamelCaseNamingScheme;28import org.jmock.lib.IdentityExpectationErrorTranslator;29import org.jmock.lib.JavaReflectionImposteriser;30import org.jmock.lib.concurrent.Synchroniser;31/**32 * A Mockery represents the context, or neighbourhood, of the object(s) under test. 33 * 34 * The neighbouring objects in that context are mocked out. The test specifies the 35 * expected interactions between the object(s) under test and its neighbours and 36 * the Mockery checks those expectations while the test is running.37 * 38 * @author npryce39 * @author smgf40 * @author named by Ivan Moore.41 */42public class Mockery implements SelfDescribing {43 private Set<String> mockNames = new HashSet<String>();44 private Imposteriser imposteriser = JavaReflectionImposteriser.INSTANCE;45 private ExpectationErrorTranslator expectationErrorTranslator = IdentityExpectationErrorTranslator.INSTANCE;46 private MockObjectNamingScheme namingScheme = CamelCaseNamingScheme.INSTANCE;47 private ThreadingPolicy threadingPolicy = new SingleThreadedPolicy();48 49 private ReturnDefaultValueAction defaultAction = new ReturnDefaultValueAction(imposteriser);50 51 private InvocationDispatcher dispatcher = new InvocationDispatcher();52 private Error firstError = null;53 54 private List<Invocation> actualInvocations = new ArrayList<Invocation>();55 56 57 /* 58 * Policies59 */60 61 /**62 * Sets the result returned for the given type when no return value has been explicitly63 * specified in the expectation.64 * 65 * @param type66 * The type for which to return <var>result</var>.67 * @param result68 * The value to return when a method of return type <var>type</var>69 * is invoked for which an explicit return value has has not been specified.70 */71 public void setDefaultResultForType(Class<?> type, Object result) {72 defaultAction.addResult(type, result);73 }74 75 /**76 * Changes the imposteriser used to adapt mock objects to the mocked type.77 * 78 * The default imposteriser allows a test to mock interfaces but not79 * classes, so you'll have to plug a different imposteriser into the80 * Mockery if you want to mock classes.81 */82 public void setImposteriser(Imposteriser imposteriser) {83 this.imposteriser = imposteriser;84 this.defaultAction.setImposteriser(imposteriser);85 }86 87 /**88 * Changes the naming scheme used to generate names for mock objects that 89 * have not been explicitly named in the test.90 * 91 * The default naming scheme names mock objects by lower-casing the first92 * letter of the class name, so a mock object of type BananaSplit will be93 * called "bananaSplit" if it is not explicitly named in the test.94 */95 public void setNamingScheme(MockObjectNamingScheme namingScheme) {96 this.namingScheme = namingScheme;97 }98 99 /**100 * Changes the expectation error translator used to translate expectation101 * errors into errors that report test failures.102 * 103 * By default, expectation errors are not translated and are thrown as104 * errors of type {@link ExpectationError}. Plug in a new expectation error105 * translator if you want your favourite test framework to report expectation 106 * failures using its own error type.107 */108 public void setExpectationErrorTranslator(ExpectationErrorTranslator expectationErrorTranslator) {109 this.expectationErrorTranslator = expectationErrorTranslator;110 }111 112 /**113 * Changes the policy by which the Mockery copes with multiple threads.114 * 115 * The default policy throws an exception if the Mockery is called from different116 * threads.117 * 118 * @see Synchroniser119 */120 public void setThreadingPolicy(ThreadingPolicy threadingPolicy) {121 this.threadingPolicy = threadingPolicy;122 }123 124 /*125 * API126 */127 128 /**129 * Creates a mock object of type <var>typeToMock</var> and generates a name for it.130 */131 public <T> T mock(Class<T> typeToMock) {132 return mock(typeToMock, namingScheme.defaultNameFor(typeToMock));133 }134 135 /**136 * Creates a mock object of type <var>typeToMock</var> with the given name.137 */138 public <T> T mock(Class<T> typeToMock, String name) {139 if (mockNames.contains(name)) {140 throw new IllegalArgumentException("a mock with name " + name + " already exists");141 }142 143 MockObject mock = new MockObject(typeToMock, name);144 mockNames.add(name);145 146 Invokable invokable =147 threadingPolicy.synchroniseAccessTo(148 new ProxiedObjectIdentity(149 new InvocationDiverter<CaptureControl>(150 CaptureControl.class, mock, mock)));151 152 return imposteriser.imposterise(invokable, typeToMock, CaptureControl.class);153 }154 155 /** 156 * Returns a new sequence that is used to constrain the order in which 157 * expectations can occur.158 * 159 * @param name160 * The name of the sequence.161 * @return162 * A new sequence with the given name.163 */164 public Sequence sequence(String name) {165 return new NamedSequence(name);166 }167 168 /** 169 * Returns a new state machine that is used to constrain the order in which 170 * expectations can occur.171 * 172 * @param name173 * The name of the state machine.174 * @return175 * A new state machine with the given name.176 */177 public States states(String name) {178 return dispatcher.newStateMachine(name);179 }180 181 /**182 * Specifies the expected invocations that the object under test will perform upon183 * objects in its context during the test.184 * 185 * The builder is responsible for interpreting high-level, readable API calls to 186 * construct an expectation.187 * 188 * This method can be called multiple times per test and the expectations defined in189 * each block are combined as if they were defined in same order within a single block.190 */191 public void checking(ExpectationBuilder expectations) {192 expectations.buildExpectations(defaultAction, dispatcher);193 }194 195 /**196 * Adds an expected invocation that the object under test will perform upon197 * objects in its context during the test.198 * 199 * This method allows a test to define an expectation explicitly, bypassing the200 * high-level API, if desired.201 */202 public void addExpectation(Expectation expectation) {203 dispatcher.add(expectation);204 }205 206 /**207 * Fails the test if there are any expectations that have not been met.208 */209 public void assertIsSatisfied() {210 if (firstError != null) {211 throw firstError;212 }213 else if (!dispatcher.isSatisfied()) {214 throw expectationErrorTranslator.translate(215 new ExpectationError("not all expectations were satisfied", this));216 }217 }218 219 public void describeTo(Description description) {220 description.appendDescriptionOf(dispatcher);221 describeHistory(description);222 }223 private void describeMismatch(Invocation invocation, Description description) {224 dispatcher.describeMismatch(invocation, description);225 describeHistory(description);226 }227 228 private void describeHistory(Description description) {229 description.appendText("\nwhat happened before this:");230 231 if (actualInvocations.isEmpty()) {232 description.appendText(" nothing!");233 }234 else {235 description.appendList("\n ", "\n ", "\n", actualInvocations);236 }237 }238 private Object dispatch(Invocation invocation) throws Throwable {239 if (firstError != null) {240 throw firstError;241 }242 243 try {244 Object result = dispatcher.dispatch(invocation);245 actualInvocations.add(invocation);246 return result;247 }248 catch (ExpectationError e) {249 firstError = expectationErrorTranslator.translate(mismatchDescribing(e));250 firstError.setStackTrace(e.getStackTrace());251 throw firstError;252 }253 catch (Throwable t) {254 actualInvocations.add(invocation);255 throw t;256 }257 }258 259 private ExpectationError mismatchDescribing(final ExpectationError e) {260 ExpectationError filledIn = new ExpectationError(e.getMessage(), new SelfDescribing() {261 public void describeTo(Description description) {262 describeMismatch(e.invocation, description);263 }264 }, e.invocation);265 filledIn.setStackTrace(e.getStackTrace());266 return filledIn;267 }268 private class MockObject implements Invokable, CaptureControl {269 private Class<?> mockedType;270 private String name;271 272 public MockObject(Class<?> mockedType, String name) {273 this.name = name;274 this.mockedType = mockedType;275 }276 277 @Override278 public String toString() {279 return name;280 }281 282 public Object invoke(Invocation invocation) throws Throwable {283 return dispatch(invocation);284 }285 public Object captureExpectationTo(ExpectationCapture capture) {286 return imposteriser.imposterise(287 new ObjectMethodExpectationBouncer(new InvocationToExpectationTranslator(capture, defaultAction)), 288 mockedType);289 }290 }291}
Source:InvocationToExpectationTranslator.java
2import org.jmock.api.Action;3import org.jmock.api.Invocation;4import org.jmock.api.Invocation.ExpectationMode;5import org.jmock.api.Invokable;6public class InvocationToExpectationTranslator implements Invokable {7 private final ExpectationCapture capture;8 private Action defaultAction;9 10 public InvocationToExpectationTranslator(ExpectationCapture capture,11 Action defaultAction) 12 {13 this.capture = capture;14 this.defaultAction = defaultAction;15 }16 17 public Object invoke(Invocation invocation) throws Throwable {18 Invocation buildingInvocation = new Invocation(ExpectationMode.BUILDING,invocation);19 capture.createExpectationFrom(buildingInvocation);20 return defaultAction.invoke(buildingInvocation);21 }22}...
InvocationToExpectationTranslator
Using AI Code Generation
1package org.jmock.test.acceptance;2import junit.framework.TestCase;3import org.jmock.Mock;4import org.jmock.MockObjectTestCase;5import org.jmock.core.Invocation;6import org.jmock.core.InvocationToExpectationTranslator;7import org.jmock.expectation.Expectation;8import org.jmock.expectation.ExpectationSet;9import org.jmock.expectation.ExpectationValue;10public class InvocationToExpectationTranslatorTest extends TestCase {11 public void testInvocationToExpectationTranslator() {12 Mock mock = new MockObjectTestCase().mock(Invocation.class);13 InvocationToExpectationTranslator translator = new InvocationToExpectationTranslator();14 Expectation expectation = translator.translate((Invocation) mock.proxy());15 assertTrue(expectation instanceof ExpectationSet);16 ExpectationSet set = (ExpectationSet) expectation;17 Expectation[] expectations = set.getExpectations();18 assertEquals(3, expectations.length);19 assertTrue(expectations[0] instanceof ExpectationValue);20 assertTrue(expectations[1] instanceof ExpectationValue);21 assertTrue(expectations[2] instanceof ExpectationValue);22 ExpectationValue value = (ExpectationValue) expectations[0];23 assertEquals("method", value.getValue());24 value = (ExpectationValue) expectations[1];25 assertEquals("myMethod", value.getValue());26 value = (ExpectationValue) expectations[2];27 assertEquals("()", value.getValue());28 }29}30package org.jmock.test.acceptance;31import junit.framework.TestCase;32import org.jmock.Mock;33import org.jmock.MockObjectTestCase;34import org.jmock.core.Invocation;35import org.jmock.core.InvocationToExpectationTranslator;36import org.jmock.expectation.Expectation;37import org.jmock.expectation.ExpectationSet;38import org.jmock.expectation.ExpectationValue;39public class InvocationToExpectationTranslatorTest extends TestCase {40 public void testInvocationToExpectationTranslator() {41 Mock mock = new MockObjectTestCase().mock(Invocation.class);42 InvocationToExpectationTranslator translator = new InvocationToExpectationTranslator();43 Expectation expectation = translator.translate((Invocation) mock.proxy());44 assertTrue(expectation instanceof ExpectationSet);45 ExpectationSet set = (ExpectationSet) expectation;46 Expectation[] expectations = set.getExpectations();47 assertEquals(3, expectations.length);48 assertTrue(expectations
InvocationToExpectationTranslator
Using AI Code Generation
1package org.jmock.test.acceptance;2import org.jmock.Expectations;3import org.jmock.Mockery;4import org.jmock.api.Expectation;5import org.jmock.internal.InvocationToExpectationTranslator;6import org.jmock.lib.legacy.ClassImposteriser;7import org.junit.Test;8public class InvocationToExpectationTranslatorTest {9 public void testInvocationToExpectationTranslator() {10 Mockery context = new Mockery();11 context.setImposteriser(ClassImposteriser.INSTANCE);12 final InvocationToExpectationTranslator translator = new InvocationToExpectationTranslator();13 final Expectation expectation = context.checking(new Expectations() {14 {15 oneOf(translator).translate(with(any(org.jmock.api.Invocation.class)));16 }17 });18 expectation.setExpectationListener(translator);19 }20}21package org.jmock.internal;22import org.jmock.api.Expectation;23import org.jmock.api.ExpectationListener;24import org.jmock.api.Invocation;25public class InvocationToExpectationTranslator implements ExpectationListener {26 public void setExpectation(Expectation expectation) {27 }28 public void invocationOccurred(Invocation invocation) {29 }30 public void expectationSatisfied(Expectation expectation) {31 }32 public void expectationViolated(Expectation expectation) {33 }34 public void translate(Invocation invocation) {35 }36}37package org.jmock.api;38public interface ExpectationListener {39 void setExpectation(Expectation expectation);40 void invocationOccurred(Invocation invocation);41 void expectationSatisfied(Expectation expectation);42 void expectationViolated(Expectation expectation);43}44package org.jmock.api;45public interface Invocation {46 Object invoke() throws Throwable;47 Object invokeIn(Object mockObject) throws Throwable;48 Object getInvokedObject();49 String getInvokedMethodName();50 Object[] getParametersAsArray();51 Class<?>[] getParameterTypes();52 void setReturnValue(Object value);53 Object getReturnValue();54 void setThrowable(Throwable throwable);55 Throwable getThrowable();56 void setMatcher(InvocationMatcher matcher);57 InvocationMatcher getMatcher();58 String describeTo(StringBuffer buffer);59 boolean matches(Invocation invocation);60 void describeTo(Description description);61 boolean isSatisfied();62 boolean isSatisfiedInOrder();63 void setSatisfied(boolean satisfied);
InvocationToExpectationTranslator
Using AI Code Generation
1package org.jmock.test.acceptance;2import java.util.ArrayList;3import java.util.List;4import junit.framework.TestCase;5import org.jmock.Expectations;6import org.jmock.Mockery;7import org.jmock.Sequence;8import org.jmock.States;9import org.jmock.api.ExpectationError;10import org.jmock.api.Invocation;11import org.jmock.internal.InvocationToExpectationTranslator;12import org.jmock.lib.action.CustomAction;13import org.jmock.lib.action.ReturnValueAction;14import org.jmock.lib.action.ThrowAction;15import org.jmock.lib.action.VoidAction;16import org.jmock.lib.legacy.ClassImposteriser;17public class InvocationToExpectationTranslatorTest extends TestCase {18 public void testCreatesExpectationWithSameNameAsInvocation() {19 Invocation invocation = new Invocation("INVOCATION_NAME", this,20 new Class<?>[0], new Object[0]);21 InvocationToExpectationTranslator translator = new InvocationToExpectationTranslator();22 assertEquals("INVOCATION_NAME", translator.translate(invocation)23 .getDescription());24 }25 public void testCreatesExpectationWithSameDescriptionAsInvocation() {26 Invocation invocation = new Invocation("INVOCATION_NAME", this,27 new Class<?>[0], new Object[0]);28 InvocationToExpectationTranslator translator = new InvocationToExpectationTranslator();29 assertEquals("INVOCATION_NAME", translator.translate(invocation)30 .getDescription());31 }32 public void testCreatesExpectationThatWillReturnSameValueAsInvocation() {33 Invocation invocation = new Invocation("INVOCATION_NAME", this,34 new Class<?>[0], new Object[0]);35 InvocationToExpectationTranslator translator = new InvocationToExpectationTranslator();36 assertEquals("INVOCATION_NAME", translator.translate(invocation)37 .getDescription());38 }39 public void testCreatesExpectationThatWillReturnSameValueAsInvocation() {40 Invocation invocation = new Invocation("INVOCATION_NAME", this,41 new Class<?>[0], new Object[0]);42 InvocationToExpectationTranslator translator = new InvocationToExpectationTranslator();43 assertEquals("INVOCATION_NAME", translator.translate(invocation)44 .getDescription());45 }46 public void testCreatesExpectationThatWillReturnSameValueAsInvocation() {47 Invocation invocation = new Invocation("INVOCATION_NAME", this,48 new Class<?>[0], new Object[0]);49 InvocationToExpectationTranslator translator = new InvocationToExpectationTranslator();
InvocationToExpectationTranslator
Using AI Code Generation
1package jmock;2import org.jmock.Mockery;3import org.jmock.Expectations;4import org.jmock.api.Invocation;5import org.jmock.api.Invokable;6import org.jmock.internal.InvocationToExpectationTranslator;7import org.jmock.internal.ExpectationBuilder;8import org.jmock.internal.InvocationExpectation;9import org.jmock.api.ExpectationError;10import org.jmock.api.ExpectationErrorTranslator;11import org.jmock.api.ExpectationErrorTranslatorChain;12import org.jmock.api.ExpectationErrorTranslatorChain;13import org.jmock.lib.action.ReturnValueAction;14public class MockeryTest {15public static void main(String[] args) {16Mockery context = new Mockery();17final Invokable mock = context.mock(Invokable.class);18context.checking(new Expectations() {{19oneOf(mock).invoke(with(any(Invocation.class)));20}});21Invocation invocation = new Invocation() {22public Object invoke(Invokable invokable) throws Throwable {23return null;24}25public Object invoke(Object object) throws Throwable {26return null;27}28public Object invoke(Object object, Object... arguments) throws Throwable {29return null;30}31public Object invoke(Object object, Object argument) throws Throwable {32return null;33}34public Object invoke(Object object, Object argument1, Object argument2) throws Throwable {35return null;36}37public Object invoke(Object object, Object argument1, Object argument2, Object argument3) throws Throwable {38return null;39}40public Object invoke(Object object, Object argument1, Object argument2, Object argument3, Object argument4) throws Throwable {41return null;42}43public Object invoke(Object object, Object argument1, Object argument2, Object argument3, Object argument4, Object argument5) throws Throwable {44return null;45}46public Object invoke(Object object, Object argument1, Object argument2, Object argument3, Object argument4, Object argument5, Object argument6) throws Throwable {47return null;48}49public Object invoke(Object object, Object argument1, Object argument2, Object argument3, Object argument4, Object argument5, Object argument6, Object argument7) throws Throwable {50return null;51}52public Object invoke(Object object, Object argument1, Object argument2, Object argument3, Object argument4, Object argument5, Object argument6, Object argument7, Object argument8) throws Throwable {53return null;54}55public Object invoke(Object object, Object argument1, Object argument2, Object argument3, Object argument4, Object argument5, Object
InvocationToExpectationTranslator
Using AI Code Generation
1package org.jmock.test.unit.internal;2import org.jmock.api.Invocation;3import org.jmock.api.Expectation;4import org.jmock.internal.InvocationToExpectationTranslator;5import org.jmock.test.unit.support.MethodFactory;6import org.jmock.test.unit.support.MethodFactory.MethodFactoryException;7import org.jmock.test.unit.support.MethodFactory.MethodFactoryException;8import org.junit.Test;9import static org.junit.Assert.*;10{11 public void translatesInvocationToExpectation() throws MethodFactoryException12 {13 Invocation invocation = MethodFactory.createInvocation("foo");14 InvocationToExpectationTranslator translator = new InvocationToExpectationTranslator();15 Expectation expectation = translator.translate(invocation);16 assertEquals(invocation.getInvokedMethod(), expectation.getExpectedMethod());17 }18}19package org.jmock.test.unit.internal;20import org.jmock.api.Invocation;21import org.jmock.api.Expectation;22import org.jmock.internal.InvocationToExpectationTranslator;23import org.jmock.test.unit.support.MethodFactory;24import org.jmock.test.unit.support.MethodFactory.MethodFactoryException;25import org.jmock.test.unit.support.MethodFactory.MethodFactoryException;26import org.junit.Test;27import static org.junit.Assert.*;28{29 public void translatesInvocationToExpectation() throws MethodFactoryException30 {31 Invocation invocation = MethodFactory.createInvocation("foo");32 InvocationToExpectationTranslator translator = new InvocationToExpectationTranslator();33 Expectation expectation = translator.translate(invocation);34 assertEquals(invocation.getInvokedMethod(), expectation.getExpectedMethod());35 }36}37package org.jmock.test.unit.internal;38import org.jmock.api.Invocation;39import org.jmock.api.Expectation;40import org.jmock.internal.InvocationToExpectationTranslator;41import org.jmock.test.unit.support.MethodFactory;42import org.jmock.test.unit.support.MethodFactory.MethodFactoryException;43import org.jmock.test.unit.support.MethodFactory.MethodFactoryException;44import org.junit.Test;45import static org.junit.Assert.*;46{47 public void translatesInvocationToExpectation() throws MethodFactoryException48 {49 Invocation invocation = MethodFactory.createInvocation("foo");50 InvocationToExpectationTranslator translator = new InvocationToExpectationTranslator();51 Expectation expectation = translator.translate(invocation);52 assertEquals(inv
InvocationToExpectationTranslator
Using AI Code Generation
1package org.jmock.test.acceptance;2import java.lang.reflect.Method;3import java.util.ArrayList;4import java.util.List;5import org.jmock.Expectations;6import org.jmock.Mockery;7import org.jmock.integration.junit4.JUnitRuleMockery;8import org.jmock.lib.legacy.ClassImposteriser;9import org.junit.Rule;10import org.junit.Test;11public class InvocationToExpectationTranslatorTest {12 public interface TestInterface {13 public void method1(String str);14 public void method2(int i);15 public void method3(String str, int i);16 }17 public Mockery context = new JUnitRuleMockery() {{18 setImposteriser(ClassImposteriser.INSTANCE);19 }};20 public void testInvocationToExpectationTranslator() throws NoSuchMethodException {21 final TestInterface mock = context.mock(TestInterface.class, "mock");22 Method method1 = TestInterface.class.getMethod("method1", String.class);23 Method method2 = TestInterface.class.getMethod("method2", int.class);24 Method method3 = TestInterface.class.getMethod("method3", String.class, int.class);25 List<Method> methods = new ArrayList<Method>();26 methods.add(method1);27 methods.add(method2);28 methods.add(method3);29 context.checking(new Expectations() {{30 allowing(mock).method1("test");31 allowing(mock).method2(1);32 allowing(mock).method3("test", 1);33 }});34 for (Method method : methods) {35 context.checking(new Expectations() {{36 oneOf(mock).method1("test");37 oneOf(mock).method2(1);38 oneOf(mock).method3("test", 1);39 }});40 context.checking(new Expectations() {{41 oneOf(mock).method1("test");42 oneOf(mock).method2(1);43 oneOf(mock).method3("test", 1);44 }});45 }46 }47}48package org.jmock.test.acceptance;49import org.jmock.Expectations;50import org.jmock.Mockery;51import org.jmock.integration.junit4.JUnitRuleMockery;52import org.jmock.lib.legacy.ClassImposteriser;53import org.junit.Rule;54import org.junit.Test;55public class InvocationToExpectationTranslatorTest {56 public interface TestInterface {57 public void method1(String str);
InvocationToExpectationTranslator
Using AI Code Generation
1package org.jmock.test.acceptance;2import java.lang.reflect.Method;3import java.util.List;4import org.jmock.Expectations;5import org.jmock.Mockery;6import org.jmock.api.Invocation;7import org.jmock.api.Invokable;8import org.jmock.lib.action.CustomAction;9import org.jmock.lib.action.ReturnValueAction;10import org.jmock.lib.action.VoidAction;11import org.jmock.lib.legacy.ClassImposteriser;12import org.jmock.test.unit.support.MethodFactory;13import org.junit.Test;14public class InvocationToExpectationTranslatorTest {15 private Mockery context = new Mockery() {16 {17 setImposteriser(ClassImposteriser.INSTANCE);18 }19 };20 public interface Foo {21 public void foo();22 public void bar();23 public void baz();24 public int qux();25 public int quux();26 public int quuz();27 public int corge();28 public int grault();29 public int garply();30 public int waldo();31 public int fred();32 public int plugh();33 public int xyzzy();34 public int thud();35 }36 public void testReturnValueAction() throws Throwable {37 final Foo mock = context.mock(Foo.class);38 final Method qux = MethodFactory.method(Foo.class, "qux");39 final Method quux = MethodFactory.method(Foo.class, "quux");40 final Method quuz = MethodFactory.method(Foo.class, "quuz");41 final Method corge = MethodFactory.method(Foo.class, "corge");42 final Method grault = MethodFactory.method(Foo.class, "grault");43 final Method garply = MethodFactory.method(Foo.class, "garply");44 final Method waldo = MethodFactory.method(Foo.class, "waldo");45 final Method fred = MethodFactory.method(Foo.class, "fred");46 final Method plugh = MethodFactory.method(Foo.class, "plugh");47 final Method xyzzy = MethodFactory.method(Foo.class, "xyzzy");48 final Method thud = MethodFactory.method(Foo.class, "thud");49 context.checking(new Expectations() {50 {51 allowing(mock).qux();52 will(returnValue(1));53 allowing(mock).quux();54 will(returnValue(2));55 allowing(mock).quuz();56 will(returnValue(3));57 allowing(mock).corge();
InvocationToExpectationTranslator
Using AI Code Generation
1package org.jmock.test.acceptance;2import org.jmock.Expectations;3import org.jmock.Mockery;4import org.jmock.api.ExpectationError;5import org.jmock.api.Invocation;6import org.jmock.lib.action.ReturnValueAction;7import org.jmock.lib.action.ThrowAction;8import org.jmock.lib.legacy.ClassImposteriser;9import org.jmock.test.unit.lib.legacy.ClassImposteriserTest.InterfaceWithMethod;10import org.jmock.test.unit.lib.legacy.ClassImposteriserTest.InterfaceWithMethodAndObject;11import org.junit.Test;12public class InvocationToExpectationTranslatorTest {13 Mockery context = new Mockery();14 {15 context.setImposteriser(ClassImposteriser.INSTANCE);16 }17 public void translatesInvocationToExpectation() {18 final InterfaceWithMethod mock = context.mock(InterfaceWithMethod.class);19 context.checking(new Expectations() {{20 allowing(mock).method();21 will(returnValue("a result"));22 }});23 assertThat(mock.method(), is("a result"));24 }25 public void translatesInvocationToExpectationWithParameters() {26 final InterfaceWithMethodAndObject mock = context.mock(InterfaceWithMethodAndObject.class);27 context.checking(new Expectations() {{28 allowing(mock).method(with("a string"));29 will(returnValue("a result"));30 }});31 assertThat(mock.method("a string"), is("a result"));32 }33 public void translatesInvocationToExpectationWithAnyParameters() {34 final InterfaceWithMethodAndObject mock = context.mock(InterfaceWithMethodAndObject.class);35 context.checking(new Expectations() {{36 allowing(mock).method(with(any(String.class)));37 will(returnValue("a result"));38 }});39 assertThat(mock.method("a string"), is("a result"));40 }41 public void translatesInvocationToExpectationWithExactParameters() {42 final InterfaceWithMethodAndObject mock = context.mock(InterfaceWithMethodAndObject.class);43 context.checking(new Expectations() {{44 allowing(mock).method(with("a string"));45 will(returnValue("a result"));46 }});47 assertThat(mock.method("a string"), is("a result"));48 }49 public void translatesInvocationToExpectationWithExactParametersAndAnyOtherParameters() {50 final InterfaceWithMethodAndObject mock = context.mock(InterfaceWithMethodAndObject.class);
InvocationToExpectationTranslator
Using AI Code Generation
1package org.jmock.internal;2import org.jmock.api.Invocation;3import org.jmock.api.Expectation;4import org.jmock.api.Invokable;5import org.jmock.lib.action.CustomAction;6import org.jmock.lib.action.ReturnValueAction;7import org.jmock.lib.action.ThrowAction;8import org.jmock.lib.action.ActionSequence;9import org.jmock.lib.action.ActionList;10import org.jmock.lib.action.DelegateTo;11import org.jmock.lib.action.DoAll;12import org.jmock.lib.action.DoAllActions;13import org.jmock.lib.action.DoAllInvokables;14import org.jmock.lib.action.DoAllParameters;15import org.jmock.lib.action.DoAllParametersAndReturn;16import org.jmock.lib.action.DoAllParametersAndThrow;17import org.jmock.lib.action.DoAllParametersAndThrowException;18import org.jmock.lib.action.DoAllParametersAndThrowRuntimeException;19import org.jmock.lib.action.DoAllParametersAndThrowThrowable;20import org.jmock.lib.action.DoAllParametersAndThrowThrowableAndReturn;21import org.jmock.lib.action.DoAllParametersAndThrowThrowableAndReturnAction;22import org.jmock.lib.action.DoAllParametersAndThrowThrowableAndReturnCustomAction;23import org.jmock.lib.action.DoAllParametersAndThrowThrowableAndReturnDelegateTo;24import org.jmock.lib.action.DoAllParametersAndThrowThrowableAndReturnInvokable;25import org.jmock.lib.action.DoAllParametersAndThrowThrowableAndReturnReturnValueAction;26import org.jmock.lib.action.DoAllParametersAndThrowThrowableAndReturnThrowAction;27import org.jmock.lib.action.DoAllParametersAndThrowThrowableAndReturnThrowException;28import org.jmock.lib.action.DoAllParametersAndThrowThrowableAndReturnThrowRuntimeException;29import org.jmock.lib.action.DoAllParametersAndThrowThrowableAndReturnThrowThrowable;30import org.jmock.lib.action.DoAllParametersAndThrowThrowableAndReturnThrowThrowableAndReturn;31import org.jmock.lib.action.DoAllParametersAndThrowThrowableAndReturnThrowThrowableAndReturnAction;32import org.jmock.lib.action.DoAllParametersAndThrowThrowableAndReturnThrowThrowableAndReturnCustomAction;33import org.jmock.lib.action.DoAllParametersAndThrowThrowableAndReturnThrowThrowableAndReturnDelegateTo;34import org.jmock.lib.action.DoAllParametersAndThrowThrowableAndReturnThrowThrowableAndReturnInvokable;35import org.jmock.lib.action.DoAllParametersAndThrowThrowableAndReturnThrowThrowableAndReturnReturnValueAction;36import org.jmock.lib.action.DoAllParametersAndThrowThrowableAndReturnThrowThrowableAndReturn
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!