How to use matches method of org.jmock.internal.InvocationExpectation class

Best Jmock-library code snippet using org.jmock.internal.InvocationExpectation.matches

Source:InvocationExpectationTests.java Github

copy

Full Screen

...24 Method method = methodFactory.newMethod("method");25 26 public <T> Matcher<T> mockMatcher(final T expected, final boolean result) {27 return new BaseMatcher<T>() {28 public boolean matches(Object actual) {29 assertTrue("expected " + expected + ", was " + actual,30 equalTo(expected).matches(actual));31 return result;32 }33 public void describeTo(Description description) {34 }35 };36 }37 38 public void testMatchesAnythingByDefault() {39 assertTrue("should match", expectation.matches(40 new Invocation(new Object(), methodFactory.newMethod("method"), Invocation.NO_PARAMETERS)));41 assertTrue("should match", expectation.matches(42 new Invocation(new Object(), methodFactory.newMethod("anotherMethod"), 43 new Object[]{1,2,3,4})));44 }45 46 public void testCanConstrainTargetObject() {47 Object anotherObject = "anotherObject";48 49 expectation.setObjectMatcher(sameInstance(targetObject));50 51 assertTrue("should match", expectation.matches(new Invocation(targetObject, method, Invocation.NO_PARAMETERS)));52 assertTrue("should not match", !expectation.matches(new Invocation(anotherObject, method, Invocation.NO_PARAMETERS)));53 }54 55 public void testCanConstrainMethod() {56 Method anotherMethod = methodFactory.newMethod("anotherMethod");57 58 expectation.setMethodMatcher(equalTo(method));59 60 assertTrue("should match", expectation.matches(new Invocation(targetObject, method, Invocation.NO_PARAMETERS)));61 assertTrue("should not match", !expectation.matches(new Invocation(targetObject, anotherMethod, Invocation.NO_PARAMETERS)));62 }63 64 public void testCanConstrainArguments() {65 Object[] args = {1,2,3,4};66 Object[] differentArgs = {5,6,7,8};67 Object[] differentArgCount = {1,2,3};68 Object[] noArgs = null;69 70 expectation.setParametersMatcher(new AllParametersMatcher(args));71 72 assertTrue("should match", expectation.matches(new Invocation(targetObject, method, args)));73 assertTrue("should not match", !expectation.matches(new Invocation(targetObject, method, differentArgs)));74 assertTrue("should not match", !expectation.matches(new Invocation(targetObject, method, differentArgCount)));75 assertTrue("should not match", !expectation.matches(new Invocation(targetObject, method, noArgs)));76 }77 78 public void testDoesNotMatchIfMatchingCountMatcherDoesNotMatch() throws Throwable {79 Invocation invocation = new Invocation("targetObject", methodFactory.newMethod("method"), Invocation.NO_PARAMETERS);80 81 int maxInvocationCount = 3;82 83 expectation.setCardinality(new Cardinality(0, maxInvocationCount));84 85 int i;86 for (i = 0; i < maxInvocationCount; i++) {87 assertTrue("should match after " + i +" invocations", expectation.matches(invocation));88 expectation.invoke(invocation);89 }90 assertFalse("should not match after " + i + " invocations", expectation.matches(invocation));91 }92 93 public void testMustMeetTheRequiredInvocationCountButContinuesToMatch() throws Throwable {94 Invocation invocation = new Invocation("targetObject", methodFactory.newMethod("method"));95 96 int requiredInvocationCount = 3;97 expectation.setCardinality(new Cardinality(requiredInvocationCount, Integer.MAX_VALUE));98 99 int i;100 for (i = 0; i < requiredInvocationCount; i++) {101 assertTrue("should match after " + i +" invocations", 102 expectation.matches(invocation));103 assertFalse("should not be satisfied after " + i +" invocations",104 expectation.isSatisfied());105 106 expectation.invoke(invocation);107 }108 assertTrue("should match after " + i +" invocations", 109 expectation.matches(invocation));110 assertTrue("should be satisfied after " + i +" invocations",111 expectation.isSatisfied());112 }113 public void testPerformsActionWhenInvoked() throws Throwable {114 final Method stringReturningMethod = methodFactory.newMethod("tester", new Class[0], String.class, new Class[0]);115 Invocation invocation = new Invocation(targetObject, stringReturningMethod, Invocation.NO_PARAMETERS);116 MockAction action = new MockAction();117 118 action.expectInvoke = true;119 action.expectedInvocation = invocation;120 action.result = "result";121 122 expectation.setAction(action);123 124 Object actualResult = expectation.invoke(invocation);125 126 assertSame("actual result", action.result, actualResult);127 assertTrue("action1 was invoked", action.wasInvoked);128 }129 130 public void testPerformsSideEffectsWhenInvoked() throws Throwable {131 FakeSideEffect sideEffect1 = new FakeSideEffect();132 FakeSideEffect sideEffect2 = new FakeSideEffect();133 134 expectation.addSideEffect(sideEffect1);135 expectation.addSideEffect(sideEffect2);136 137 Invocation invocation = new Invocation("targetObject", methodFactory.newMethod("method"));138 expectation.invoke(invocation);139 140 assertTrue("side effect 1 should have been performed", sideEffect1.wasPerformed);141 assertTrue("side effect 2 should have been performed", sideEffect2.wasPerformed);142 }143 144 public void testDescriptionIncludesSideEffects() {145 FakeSideEffect sideEffect1 = new FakeSideEffect();146 FakeSideEffect sideEffect2 = new FakeSideEffect();147 148 sideEffect1.descriptionText = "side-effect-1";149 sideEffect2.descriptionText = "side-effect-2";150 151 expectation.addSideEffect(sideEffect1);152 expectation.addSideEffect(sideEffect2);153 154 String description = StringDescription.toString(expectation);155 156 AssertThat.stringIncludes("should include description of sideEffect1",157 sideEffect1.descriptionText, description);158 AssertThat.stringIncludes("should include description of sideEffect2",159 sideEffect2.descriptionText, description);160 161 }162 163 public void testReturnsNullIfHasNoActionsWhenInvoked() throws Throwable {164 Invocation invocation = new Invocation(targetObject, method, Invocation.NO_PARAMETERS);165 166 Object actualResult = expectation.invoke(invocation);167 168 assertNull("should have returned null", actualResult);169 }170 171 public void testFailsIfActionReturnsAnIncompatibleValue() throws Throwable {172 final Method stringReturningMethod = methodFactory.newMethod("tester", new Class[0], String.class, new Class[0]);173 Invocation invocation = new Invocation(targetObject, stringReturningMethod, Invocation.NO_PARAMETERS);174 ReturnValueAction action = new ReturnValueAction(new Integer(666));175 expectation.setAction(action);176 177 try {178 expectation.invoke(invocation);179 fail("Should have thrown an IllegalStateException");180 } catch (IllegalStateException expected) {181 AssertThat.stringIncludes("Shows returned type", "java.lang.Integer", expected.getMessage());182 AssertThat.stringIncludes("Shows expected return type", "java.lang.String", expected.getMessage());183 }184 }185 186 /**187 * @see CardinalityTests.testHasARequiredAndMaximumNumberOfExpectedInvocations188 */189 public void testHasARequiredAndMaximumNumberOfExpectedInvocations() throws Throwable {190 Invocation invocation = new Invocation(targetObject, method, Invocation.NO_PARAMETERS);191 192 expectation.setCardinality(new Cardinality(1, 1));193 194 assertTrue(expectation.allowsMoreInvocations());195 assertFalse(expectation.isSatisfied());196 197 expectation.invoke(invocation);198 expectation.invoke(invocation);199 200 assertFalse(expectation.allowsMoreInvocations());201 assertTrue(expectation.isSatisfied());202 }203 204 public void testMatchesIfAllOrderingConstraintsMatch() {205 FakeOrderingConstraint orderingConstraint1 = new FakeOrderingConstraint();206 FakeOrderingConstraint orderingConstraint2 = new FakeOrderingConstraint();207 208 expectation.addOrderingConstraint(orderingConstraint1);209 expectation.addOrderingConstraint(orderingConstraint2);210 211 Invocation invocation = new Invocation(targetObject, method, Invocation.NO_PARAMETERS);212 213 orderingConstraint1.allowsInvocationNow = true;214 orderingConstraint2.allowsInvocationNow = true;215 assertTrue(expectation.matches(invocation));216 217 orderingConstraint1.allowsInvocationNow = true;218 orderingConstraint2.allowsInvocationNow = false;219 assertFalse(expectation.matches(invocation));220 221 orderingConstraint1.allowsInvocationNow = false;222 orderingConstraint2.allowsInvocationNow = true;223 assertFalse(expectation.matches(invocation));224 225 orderingConstraint1.allowsInvocationNow = false;226 orderingConstraint2.allowsInvocationNow = false;227 assertFalse(expectation.matches(invocation));228 }229 230 public void testDescriptionIncludesCardinality() {231 final Cardinality cardinality = new Cardinality(2, 2);232 expectation.setCardinality(cardinality);233 234 AssertThat.stringIncludes("should include cardinality description",235 StringDescription.toString(cardinality), 236 StringDescription.toString(expectation));237 }238 239 public void testDescribesNumberOfInvocationsReceived() throws Throwable {240 Invocation invocation = new Invocation(targetObject, method, Invocation.NO_PARAMETERS);241 ...

Full Screen

Full Screen

Source:Dupple.java Github

copy

Full Screen

...33 return ClassImposteriser.INSTANCE.imposterise(new Invokable() {34 public Object invoke(Invocation invocation) throws Throwable {35 InvocationExpectation expectation = expectationFromInvocation(invocation);36 // TODO (Jun 16, 2008 8:01:49 PM): don't just match first37 if (!expectation.matches(invocations.get(0)))38 Assert.fail();39 return null;40 }41 }, ServerSocketFactory.class);42 // TODO Auto-generated method stub43 }44 }45 // TODO (Jun 16, 2008 7:55:15 PM): Use Google collections46 // TODO (Jun 16, 2008 7:56:36 PM): non-static47 // TODO (Jun 16, 2008 7:14:00 PM): generalize48 public static ServerSocketFactory recorder(Class<ServerSocketFactory> class1) {49 lastDupplery = new Dupplery();50 return lastDupplery.recorder(class1);51 // TODO (Jun 16, 2008 7:13:33 PM): release Dupple as OS...

Full Screen

Full Screen

matches

Using AI Code Generation

copy

Full Screen

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.InvocationExpectation;7import org.jmock.core.InvocationMatcher;8import org.jmock.core.Stub;9import org.jmock.core.constraint.IsEqual;10import org.jmock.core.constraint.IsAnything;11import org.jmock.core.constraint.IsIdentical;12import org.jmock.core.constraint.IsSame;13import org.jmock.core.constraint.IsInstanceOf;14import org.jmock.core.constraint.IsInstanceOfAny;15import org.jmock.core.constraint.IsNot;16import org.jmock.core.constraint.IsAnything;17import org.jmock.core.constraint.IsTypeCompatible;18import org.jmock.core.constraint.IsCompatibleType;19import org.jmock.core.constraint.IsCompatibleTypeAny;20import org.jmock.core.constraint.IsCompatibleTypeWith;

Full Screen

Full Screen

matches

Using AI Code Generation

copy

Full Screen

1package org.jmock.test.unit.core;2import org.jmock.core.Invocation;3import org.jmock.core.InvocationExpectation;4import org.jmock.core.InvocationMatcher;5import org.jmock.core.constraint.IsAnything;6import org.jmock.core.constraint.IsEqual;7import org.jmock.core.constraint.IsSame;8import org.jmock.core.matcher.InvokeAtLeastOnceMatcher;9import org.jmock.core.matcher.InvokeAtMostOnceMatcher;10import org.jmock.core.matcher.InvokeCountMatcher;11import org.jmock.core.matcher.InvokeOnceMatcher;12import org.jmock.core.matcher.InvokeRecorder;13import org.jmock.core.matcher.InvokeTimesMatcher;14import org.jmock.util.AsStringWriter;15import junit.framework.TestCase;16public class InvocationExpectationTest extends TestCase {17 private AsStringWriter writer = new AsStringWriter();18 private Invocation invocation = new Invocation("INVOKED-OBJECT", "INVOKED-METHOD", new Object[0], 0);19 private InvocationMatcher[] matchers = new InvocationMatcher[] {20 new InvokeOnceMatcher(),21 new InvokeAtLeastOnceMatcher(),22 new InvokeAtMostOnceMatcher(),23 new InvokeCountMatcher(2),24 new InvokeTimesMatcher(3, 5)25 };26 public void testMatches() {27 for (int i = 0; i < matchers.length; i++) {28 InvocationExpectation expectation = new InvocationExpectation("INVOKED-OBJECT", "INVOKED-METHOD", new IsAnything(), matchers[i]);29 assertTrue("should match: " + matchers[i], expectation.matches(invocation));30 }31 }32 public void testDoesNotMatch() {33 for (int i = 0; i < matchers.length; i++) {34 InvocationExpectation expectation = new InvocationExpectation("INVOKED-OBJECT", "INVOKED-METHOD", new IsAnything(), matchers[i]);35 assertFalse("should not match: " + matchers[i], expectation.matches(new Invocation("OTHER-OBJECT", "INVOKED-METHOD", new Object[0], 0)));36 assertFalse("should not match: " + matchers[i], expectation.matches(new Invocation("INVOKED-OBJECT", "OTHER-METHOD", new Object[0], 0)));37 assertFalse("should not match: " + matchers[i], expectation.matches(new Invocation("INVOKED-OBJECT", "INVOKED-METHOD", new Object[] { "ARG" },

Full Screen

Full Screen

matches

Using AI Code Generation

copy

Full Screen

1import org.jmock.core.Invocation;2import org.jmock.core.InvocationExpectation;3import org.jmock.core.InvocationMatcher;4import org.jmock.core.InvocationMocker;5import org.jmock.core.Invokable;6import org.jmock.core.Stub;7import org.jmock.core.constraint.IsAnything;8import org.jmock.core.constraint.IsEqual;9import org.jmock.core.constraint.IsInstanceOf;10import org.jmock.core.constraint.IsSame;11import org.jmock.core.constraint.IsTypeCompatible;12import org.jmock.core.constraint.StringContains;13import org.jmock.core.matcher.InvokeAtLeastOnceMatcher;14import org.jmock.core.matcher.InvokeCountMatcher;15import org.jmock.core.matcher.InvokeOnceMatcher;16import org.jmock.core.matcher.InvokeRangeMatcher;17import org.jmock.core.matcher.InvokeTimesMatcher;18import org.jmock.core.matcher.InvokeAtMostOnceMatcher;19import org.jmock.core.matcher.InvokeAtLeastOnceMatcher;20import org.jmock.core.matcher.InvokeAtMostOnceMatcher;21import org.jmock.core.matcher.InvokeExactlyOnceMatcher;22import org.jmock.core.matcher.InvokeNoMoreThanOnceMatcher;23import org.jmock.core.matcher.InvokeNoMoreThanMatcher;24import org.jmock.core.matcher.InvokeNoMoreThanRangeMatcher;25import org.jmock.core.matcher.InvokeNoMoreThanTimesMatcher;26import

Full Screen

Full Screen

matches

Using AI Code Generation

copy

Full Screen

1package org.jmock.test.unit.support;2import junit.framework.TestCase;3import org.jmock.core.Invocation;4import org.jmock.core.InvocationExpectation;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.IsAnythingArray;10import org.jmock.core.constraint.IsEqualArray;11import org.jmock.core.constraint.IsSame;12import org.jmock.core.constraint.IsSameArray;13import org.jmock.core.constraint.IsTypeCompatible;14import org.jmock.core.constraint.IsTypeCompatibleArray;15import org.jmock.core.constraint.IsInstanceOf;16import org.jmock.core.constraint.IsInstanceOfArray;17import org.jmock.core.constraint.IsIdentical;18import org.jmock.core.constraint.IsIdenticalArray;19import org.jmock.core.constraint.IsSubtype;20import org.jmock.core.constraint.IsSubtypeArray;21import org.jmock.core.constraint.IsCompatibleType;22import org.jmock.core.constraint.IsCompatibleTypeArray;23import org.jmock.core.constraint.IsCompatibleClass;24import org.jmock.core.constraint.IsCompatibleClassArray;25import org.jmock.core.constraint.IsCompatibleInterface;26import org.jmock.core.constraint.IsCompatibleInterfaceArray;27import org.jmock.core.constraint.IsCompatibleClassOrInterface;28import org.jmock.core.constraint.IsCompatibleClassOrInterfaceArray;29import org.jmock.core.constraint.IsCompatibleClassOrInterfaceWithArray;30import org.jmock.core.constraint.IsCompatibleClassOrInterfaceWithArrayArray;31import org.jmock.core.constraint.IsCompatibleClassOrInterfaceWithArrayArrayArray;32import org.jmock.core.constraint.IsCompatibleClassOrInterfaceWithArrayArrayArrayArray;33import org.jmock.core.constraint.IsCompatibleClassOrInterfaceWithArrayArrayArrayArrayArray;34import org.jmock.core.constraint.IsCompatibleClassOrInterfaceWithArrayArrayArrayArrayArrayArray;35import org.jmock.core.constraint.IsCompatibleClassOrInterfaceWithArrayArrayArrayArrayArrayArrayArray;36import org.jmock.core.constraint.IsCompatibleClassOrInterfaceWithArrayArrayArrayArrayArrayArrayArrayArray;37import org.jmock.core.constraint.IsCompatibleClassOrInterfaceWithArrayArrayArrayArrayArrayArrayArrayArrayArray;38import org.jmock.core.constraint.IsCompatibleClassOrInterfaceWit

Full Screen

Full Screen

matches

Using AI Code Generation

copy

Full Screen

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.InvocationExpectation;7import org.jmock.core.Stub;8public class InvocationExpectationTest extends MockObjectTestCase {9 public void testMatches() {10 InvocationExpectation expectation = new InvocationExpectation(11 "test method", new String[] { "java.lang.String" });12 Invocation invocation = new Invocation("test method",13 new String[] { "java.lang.String" }, new Object[] { "test" },14 null);15 assertTrue("Invocation does not match expectation", expectation16 .matches(invocation));17 }18}19package org.jmock.core;20import org.jmock.core.Invocation;21public class InvocationExpectation {22 private String methodName;23 private String[] parameterTypes;24 public InvocationExpectation(String methodName, String[] parameterTypes) {25 this.methodName = methodName;26 this.parameterTypes = parameterTypes;27 }28 public boolean matches(Invocation invocation) {29 return methodName.equals(invocation.getInvokedMethodName())30 && parameterTypes.equals(invocation.getParameterTypes());31 }32}33package org.jmock.core;34public class Invocation {35 private String methodName;36 private String[] parameterTypes;37 private Object[] arguments;38 private Object returnValue;39 public Invocation(String methodName, String[] parameterTypes,40 Object[] arguments, Object returnValue) {41 this.methodName = methodName;42 this.parameterTypes = parameterTypes;43 this.arguments = arguments;44 this.returnValue = returnValue;45 }46 public String getInvokedMethodName() {47 return methodName;48 }49 public String[] getParameterTypes() {50 return parameterTypes;51 }52 public Object[] getArguments() {53 return arguments;54 }55 public Object getReturnValue() {56 return returnValue;57 }58}59package org.jmock.test.acceptance;60import junit.framework.TestCase;61import org.jmock.Mock;62import org.jmock.MockObjectTestCase;63import org.jmock.core.Invocation;64import org.jmock.core.InvocationExpectation;65import org.jmock.core.Stub;66public class InvocationExpectationTest extends MockObjectTestCase {67 public void testMatches() {68 InvocationExpectation expectation = new InvocationExpectation(

Full Screen

Full Screen

matches

Using AI Code Generation

copy

Full Screen

1package com.jmockit;2import mockit.*;3import org.junit.*;4import org.junit.runner.*;5import org.junit.runners.*;6import static org.junit.Assert.*;7@RunWith(JUnit4.class)8public class JMockitTest {9 private InvocationExpectation invocationExpectation;10 public void test() {11 new Expectations() {12 {13 invocationExpectation.matches((Invocation) any);14 result = true;15 }16 };17 assertTrue(invocationExpectation.matches(new Invocation()));18 }19}20package org.jmock.internal;21public class InvocationExpectation {22 public boolean matches(Invocation invocation) {23 return true;24 }25}26package org.jmock.internal;27public class Invocation {28}

Full Screen

Full Screen

matches

Using AI Code Generation

copy

Full Screen

1import org.jmock.Mockery;2import org.jmock.Expectations;3import org.jmock.Mockery;4import org.jmock.Expectations;5import org.jmock.integration.junit4.JUnit4Mockery;6import org.jmock.lib.legacy.ClassImposteriser;7import org.jmock.internal.InvocationExpectation;8import org.jmock.api.Invocation;9import org.jmock.api.Expectation;10import org.jmock.api.Action;11import org.jmock.inter

Full Screen

Full Screen

matches

Using AI Code Generation

copy

Full Screen

1import org.jmock.core.InvocationExpectation;2import org.jmock.core.Invocation;3import org.jmock.core.Constraint;4import org.jmock.core.constraint.IsEqual;5import org.jmock.core.constraint.IsStringMatching;6import org.jmock.core.constraint.StringConstraints;7import org.jmock.core.constraint.StringEndsWith;8import org.jmock.core.constraint.StringStartsWith;9import org.jmock.core.constraint.StringContains;10import java.util.regex.Pattern;11{12public static void main(String[] args)13{14String str = "jmock is a mocking framework";15InvocationExpectation ie = new InvocationExpectation("test");16IsEqual isEqual = new IsEqual(str);17ie.setConstraint(isEqual);18Invocation inv = new Invocation("test", new Object[]{str});19if (ie.matches(inv))20System.out.println("The string matches the given constraint");21System.out.println("The string does not match the given constraint");22IsStringMatching isStringMatching = new IsStringMatching("jmock.*framework");23ie.setConstraint(isStringMatching);24if (ie.matches(inv))25System.out.println("The string matches the given constraint");26System.out.println("The string does not match the given constraint");27StringEndsWith stringEndsWith = new StringEndsWith("framework");28ie.setConstraint(stringEndsWith);29if (ie.matches(inv))30System.out.println("The string matches the given constraint");31System.out.println("The string does not match the given constraint");32StringStartsWith stringStartsWith = new StringStartsWith("jmock");33ie.setConstraint(stringStartsWith);

Full Screen

Full Screen

matches

Using AI Code Generation

copy

Full Screen

1public boolean match(Invocation invocation, InvocationExpectation expectation) {2 return expectation.matches(invocation);3}4public boolean match(Invocation invocation, InvocationExpectation expectation) {5 return expectation.matches(invocation);6}7public boolean match(Invocation invocation, InvocationExpectation expectation) {8 return expectation.matches(invocation);9}10public boolean match(Invocation invocation, InvocationExpectation expectation) {11 return expectation.matches(invocation);12}13public boolean match(Invocation invocation, InvocationExpectation expectation) {14 return expectation.matches(invocation);15}16public boolean match(Invocation invocation, InvocationExpect

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful