How to use ParametersMatcher class of org.jmock.internal.matcher package

Best Jmock-library code snippet using org.jmock.internal.matcher.ParametersMatcher

Source:InvocationExpectation.java Github

copy

Full Screen

...17 * @author npryce18 * @author smgf19 */20public class InvocationExpectation implements Expectation {21 private static ParametersMatcher ANY_PARAMETERS = new AnyParametersMatcher();22 private Cardinality cardinality = Cardinality.ALLOWING;23 private Matcher<?> objectMatcher = IsAnything.anything();24 private Matcher<? super Method> methodMatcher = IsAnything.anything("<any method>");25 private boolean methodIsKnownToBeVoid = false;26 private ParametersMatcher parametersMatcher = ANY_PARAMETERS;27 private Action action = new VoidAction();28 private boolean actionIsDefault = true;29 private List<OrderingConstraint> orderingConstraints = new ArrayList<OrderingConstraint>();30 private List<SideEffect> sideEffects = new ArrayList<SideEffect>();31 32 private int invocationCount = 0;33 34 public void setCardinality(Cardinality cardinality) {35 this.cardinality = cardinality;36 }37 38 public void setObjectMatcher(Matcher<?> objectMatcher) {39 this.objectMatcher = objectMatcher;40 }41 42 public void setMethod(Method method) {43 this.methodMatcher = new MethodMatcher(method);44 this.methodIsKnownToBeVoid = method.getReturnType() == void.class;45 }46 47 public void setMethodMatcher(Matcher<? super Method> matcher) {48 this.methodMatcher = matcher;49 this.methodIsKnownToBeVoid = false;50 }51 52 public void setParametersMatcher(ParametersMatcher parametersMatcher) {53 this.parametersMatcher = parametersMatcher;54 }55 public void addOrderingConstraint(OrderingConstraint orderingConstraint) {56 orderingConstraints.add(orderingConstraint);57 }58 public void addSideEffect(SideEffect sideEffect) {59 sideEffects.add(sideEffect);60 }61 62 public void setAction(Action action) {63 this.action = action;64 this.actionIsDefault = false;65 }66 67 public void setDefaultAction(Action action) {68 this.action = action;69 this.actionIsDefault = true;70 }71 72 public void describeTo(Description description) {73 if (! isSatisfied()) {74 description.appendText("! ");75 }76 describeExpectation(description);77 }78 public void describeMismatch(Invocation invocation, Description description) {79 describeExpectation(description);80 final Object[] parameters = invocation.getParametersAsArray();81 if (methodMatcher.matches(invocation.getInvokedMethod()) &&82 parametersMatcher.isCompatibleWith(parameters))83 {84 parametersMatcher.describeMismatch(parameters, description);85 }86 }87 private void describeExpectation(Description description) {88 describeMethod(description);89 parametersMatcher.describeTo(description);90 describeSideEffects(description);91 }92 private void describeMethod(Description description) {93 cardinality.describeTo(description);94 description.appendText(", ");95 if (invocationCount == 0) {96 description.appendText("never invoked");97 }98 else {99 description.appendText("already invoked ");100 description.appendText(Formatting.times(invocationCount));101 }102 description.appendText(": ");103 objectMatcher.describeTo(description);104 description.appendText(".");105 methodMatcher.describeTo(description);106 }107 108 private void describeSideEffects(Description description) {109 for (OrderingConstraint orderingConstraint : orderingConstraints) {110 description.appendText("; ");111 orderingConstraint.describeTo(description);112 }113 114 if (!shouldSuppressActionDescription()) {115 description.appendText("; ");116 action.describeTo(description);117 }118 119 for (SideEffect sideEffect : sideEffects) {120 description.appendText("; ");121 sideEffect.describeTo(description);122 }123 }124 private boolean shouldSuppressActionDescription() {125 return methodIsKnownToBeVoid && actionIsDefault;126 }127 public boolean isSatisfied() {128 return cardinality.isSatisfied(invocationCount);129 }130 131 public boolean allowsMoreInvocations() {132 return cardinality.allowsMoreInvocations(invocationCount);133 }134 135 public boolean matches(Invocation invocation) {136 return allowsMoreInvocations()137 && objectMatcher.matches(invocation.getInvokedObject())138 && methodMatcher.matches(invocation.getInvokedMethod())139 && parametersMatcher.matches(invocation.getParametersAsArray())140 && isInCorrectOrder();141 142 }143 144 private boolean isInCorrectOrder() {145 for (OrderingConstraint constraint : orderingConstraints) {146 if (!constraint.allowsInvocationNow()) return false;147 }148 return true;149 }150 151 public Object invoke(Invocation invocation) throws Throwable {152 invocationCount++;153 performSideEffects();154 final Object result = action.invoke(new Invocation(ExpectationMode.ASSERTING, invocation));155 invocation.checkReturnTypeCompatibility(result);156 return result;157 }158 private void performSideEffects() {159 for (SideEffect sideEffect : sideEffects) {160 sideEffect.perform();161 }162 }163 164 private static class AnyParametersMatcher extends IsAnything<Object[]> implements ParametersMatcher {165 public AnyParametersMatcher() {166 super("(<any parameters>)");167 }168 public boolean isCompatibleWith(Object[] parameters) {169 return true;170 }171 };172}...

Full Screen

Full Screen

Source:ParametersMatcher.java Github

copy

Full Screen

2import java.util.List;3import org.hamcrest.Matcher;4import org.hamcrest.collection.IsArray;5import org.hamcrest.core.IsEqual;6public class ParametersMatcher extends IsArray<Object> {7 public ParametersMatcher(Object[] expectedValues) {8 super(equalMatchersFor(expectedValues));9 }10 11 @SuppressWarnings("unchecked")12 private static Matcher<Object>[] equalMatchersFor(Object[] expectedValues) {13 Matcher<Object>[] matchers = new Matcher[expectedValues.length];14 for (int i = 0; i < expectedValues.length; i++) {15 matchers[i] = new IsEqual<Object>(expectedValues[i]);16 }17 return matchers;18 }19 20 @SuppressWarnings("unchecked")21 public ParametersMatcher(List<Matcher<?>> parameterMatchers) {22 super(parameterMatchers.toArray(new Matcher[0]));23 }24 @Override25 protected String descriptionStart() {26 return "(";27 }28 29 @Override30 protected String descriptionEnd() {31 return ")";32 }33}...

Full Screen

Full Screen

ParametersMatcher

Using AI Code Generation

copy

Full Screen

1import org.jmock.Mockery;2import org.jmock.MockObjectTestCase;3import org.jmock.Expectations;4import org.jmock.api.Invocation;5import org.jmock.internal.matcher.ParametersMatcher;6import org.jmock.lib.legacy.ClassImposteriser;7import java.lang.reflect.Method;8import java.lang.reflect.InvocationTargetException;9import java.lang.reflect.Field;10import java.lang.reflect.Modifier;11public class 1 extends MockObjectTestCase {12 public void testParametersMatcher() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, NoSuchFieldException {13 Mockery context = new Mockery();14 context.setImposteriser(ClassImposteriser.INSTANCE);15 final A mockA = context.mock(A.class);16 final B mockB = context.mock(B.class);17 final C mockC = context.mock(C.class);18 context.checking(new Expectations() {{19 oneOf(mockA).doSomething(with(any(String.class)), with(any(String.class)), with(any(String.class)));20 will(new ParametersMatcher() {21 protected boolean isMatched(Object[] parameters) {22 return parameters[0].equals("test1") && parameters[1].equals("test2") && parameters[2].equals("test3");23 }24 });25 }});26 mockA.doSomething("test1", "test2", "test3");27 mockA.doSomething("test1", "test2", "test4");28 }29 public class A {30 public void doSomething(String s1, String s2, String s3) {31 }32 }33 public class B {34 public void doSomething(String s1, String s2, String s3) {35 }36 }37 public class C {38 public void doSomething(String s1, String s2, String s3) {39 }40 }41}42import org.jmock.Mockery;43import org.jmock.MockObjectTestCase;44import org.jmock.Expectations;45import org.jmock.api.Invocation;46import org.jmock.internal.matcher.ParametersMatcher;47import org.jmock.lib.legacy.ClassImposteriser;48import java.lang.reflect.Method;49import java.lang.reflect.InvocationTargetException;50import java.lang.reflect.Field;51import java.lang.reflect.Modifier;52public class 2 extends MockObjectTestCase {53 public void testParametersMatcher() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException,

Full Screen

Full Screen

ParametersMatcher

Using AI Code Generation

copy

Full Screen

1import org.jmock.api.Invocation;2import org.jmock.internal.matcher.ParametersMatcher;3import org.jmock.internal.matcher.InvokeOnceMatcher;4import org.jmock.internal.matcher.InvokeAtLeastOnceMatcher;5import org.jmock.internal.matcher.InvokeAtMostOnceMatcher;6import org.jmock.internal.matcher.InvokeAtLeastMatcher;7import org.jmock.internal.matcher.InvokeAtMostMatcher;8import org.jmock.internal.matcher.InvokeBetweenMatcher;9import org.jmock.internal.matcher.InvokeExactlyMatcher;10import org.jmock.internal.matcher.InvokeTimesMatcher;11import org.jmock.internal.matcher.InvokeNeverMatcher;12import org.jmock.internal.matcher.InvokeAtLeastNTimesMatcher;13import org.jmock.internal.matcher.InvokeAtMostNTimesMatcher;14import org.jmock.internal.matcher.InvokeBetweenNTimesMatcher;15import org.jmock.internal.matcher.InvokeExactlyNTimesMatcher;16import org.jmock.internal.matcher.InvokeNTimesMatcher;17import org.jmock.internal.matcher.InvokeNeverNTimesMatcher;18public class Test {19 public static void main(String[] args) {20 ParametersMatcher matcher = new ParametersMatcher();21 matcher.add(new InvokeOnceMatcher());22 matcher.add(new InvokeAtLeastOnceMatcher());23 matcher.add(new InvokeAtMostOnceMatcher());24 matcher.add(new InvokeAtLeastMatcher(1));25 matcher.add(new InvokeAtMostMatcher(1));26 matcher.add(new InvokeBetweenMatcher(1, 2));27 matcher.add(new InvokeExactlyMatcher(1));28 matcher.add(new InvokeTimesMatcher(1));29 matcher.add(new InvokeNeverMatcher());30 matcher.add(new InvokeAtLeastNTimesMatcher(1));31 matcher.add(new InvokeAtMostNTimesMatcher(1));32 matcher.add(new InvokeBetweenNTimesMatcher(1, 2));33 matcher.add(new InvokeExactlyNTimesMatcher(1));34 matcher.add(new InvokeNTimesMatcher(1));35 matcher.add(new InvokeNeverNTimesMatcher());36 matcher.add(new InvokeAtLeastNTimesMatcher(1, 1));37 matcher.add(new InvokeAtMostNTimesMatcher(1, 1));38 matcher.add(new InvokeBetweenNTimesMatcher(1, 2, 1));39 matcher.add(new InvokeExactlyNTimesMatcher(1, 1));40 matcher.add(new InvokeNTimesMatcher(1, 1));41 matcher.add(new InvokeNeverNTimesMatcher(1));42 matcher.add(new InvokeAtLeastNTimesMatcher(1, 1, 1));43 matcher.add(new InvokeAtMostNTimesMatcher(1,

Full Screen

Full Screen

ParametersMatcher

Using AI Code Generation

copy

Full Screen

1import org.jmock.MockObjectTestCase;2import org.jmock.Mock;3import org.jmock.core.*;4import org.jmock.core.constraint.*;5import org.jmock.core.matcher.*;6import org.jmock.core.stub.*;7import org.jmock.internal.*;8import org.jmock.internal.matcher.*;9import org.jmock.util.*;10public class Test extends MockObjectTestCase {11 public void test() {12 Mock mock = mock(SomeInterface.class,"mock");13 ParametersMatcher parametersMatcher = new ParametersMatcher(new Object[]{"one","two"});14 mock.expects(once()).method("someMethod").with(parametersMatcher);15 SomeInterface someInterface = (SomeInterface)mock.proxy();16 someInterface.someMethod("one","two");17 }18}19import org.jmock.MockObjectTestCase;20import org.jmock.Mock;21import org.jmock.core.*;22import org.jmock.core.constraint.*;23import org.jmock.core.matcher.*;24import org.jmock.core.stub.*;25import org.jmock.internal.*;26import org.jmock.internal.matcher.*;27import org.jmock.util.*;28public class Test extends MockObjectTestCase {29 public void test() {30 Mock mock = mock(SomeInterface.class,"mock");31 ParametersMatcher parametersMatcher = new ParametersMatcher(new Object[]{"one","two"});32 mock.expects(once()).method("someMethod").with(parametersMatcher);33 SomeInterface someInterface = (SomeInterface)mock.proxy();34 someInterface.someMethod("one","two");35 }36}37import org.jmock.MockObjectTestCase;38import org.jmock.Mock;39import org.jmock.core.*;40import org.jmock.core.constraint.*;41import org.jmock.core.matcher.*;42import org.jmock.core.stub.*;43import org.jmock.internal.*;44import org.jmock.internal.matcher.*;45import org.jmock.util.*;46public class Test extends MockObjectTestCase {47 public void test() {48 Mock mock = mock(SomeInterface.class,"mock");49 ParametersMatcher parametersMatcher = new ParametersMatcher(new Object

Full Screen

Full Screen

ParametersMatcher

Using AI Code Generation

copy

Full Screen

1import org.jmock.internal.matcher.ParametersMatcher;2import org.jmock.core.Invocation;3import org.jmock.core.InvocationMatcher;4{5 public static void main(String[] args)6 {7 ParametersMatcherTest pm = new ParametersMatcherTest();8 pm.testMatches();9 }10 public void testMatches()11 {12 int[] a = {1, 2, 3};13 int[] b = {1, 2, 3};14 int[] c = {1, 2, 3};15 int[] d = {1, 2, 3};16 int[] e = {1, 2, 3};17 int[] f = {1, 2, 3};18 int[] g = {1, 2, 3};19 int[] h = {1, 2, 3};20 int[] i = {1, 2, 3};21 int[] j = {1, 2, 3};22 int[] k = {1, 2, 3};23 int[] l = {1, 2, 3};24 int[] m = {1, 2, 3};25 int[] n = {1, 2, 3};26 int[] o = {1, 2, 3};27 int[] p = {1, 2, 3};28 int[] q = {1, 2, 3};29 int[] r = {1, 2, 3};30 int[] s = {1, 2, 3};31 int[] t = {1, 2, 3};32 int[] u = {1, 2, 3};33 int[] v = {1, 2, 3};34 int[] w = {1, 2, 3};35 int[] x = {1, 2, 3};36 int[] y = {1, 2, 3};37 int[] z = {1, 2, 3};38 int[] aa = {1, 2, 3};39 int[] ab = {1, 2, 3};40 int[] ac = {1, 2, 3};41 int[] ad = {1, 2, 3};42 int[] ae = {1,

Full Screen

Full Screen

ParametersMatcher

Using AI Code Generation

copy

Full Screen

1public class 1 {2 public static void main(String[] args) {3 ParametersMatcher matcher = new ParametersMatcher(new Object[]{new Integer(1), new Integer(2)});4 Object[] params = new Object[]{new Integer(1), new Integer(2)};5 System.out.println(matcher.matches(params));6 }7}8public class 2 {9 public static void main(String[] args) {10 ParametersMatcher matcher = new ParametersMatcher(new Object[]{new Integer(1), new Integer(2)});11 Object[] params = new Object[]{new Integer(1), new Integer(3)};12 System.out.println(matcher.matches(params));13 }14}15public class 3 {16 public static void main(String[] args) {17 ParametersMatcher matcher = new ParametersMatcher(new Object[]{new Integer(1), new Integer(2)});18 Object[] params = new Object[]{new Integer(1), new Integer(2), new Integer(3)};19 System.out.println(matcher.matches(params));20 }21}22public class 4 {23 public static void main(String[] args) {24 ParametersMatcher matcher = new ParametersMatcher(new Object[]{new Integer(1), new Integer(2)});25 Object[] params = new Object[]{new Integer(1)};26 System.out.println(matcher.matches(params));27 }28}29public class 5 {30 public static void main(String[] args) {31 ParametersMatcher matcher = new ParametersMatcher(new Object[]{new Integer(1), new Integer(2)});32 Object[] params = new Object[]{new Integer(1), new Integer(2), null};33 System.out.println(matcher.matches(params));34 }35}36public class 6 {37 public static void main(String[] args) {

Full Screen

Full Screen

ParametersMatcher

Using AI Code Generation

copy

Full Screen

1import java.util.List;2import java.util.ArrayList;3import org.jmock.Mockery;4import org.jmock.Expectations;5import org.jmock.internal.matcher.ParametersMatcher;6import org.jmock.api.Action;7import org.jmock.api.Invocation;8public class Test1 {9 public static void main(String[] args) {10 Mockery context = new Mockery();11 final List<String> mockList = context.mock(List.class);12 context.checking(new Expectations() {{13 oneOf (mockList).add(with(ParametersMatcher.parameters("one", "two")));14 will(new Action() {15 public void describeTo(Description description) {16 description.appendText("add one and two");17 }18 public Object invoke(Invocation invocation) throws Throwable {19 System.out.println("add one and two");20 return null;21 }22 });23 }});24 mockList.add("one", "two");25 context.assertIsSatisfied();26 }27}28import java.util.List;29import java.util.ArrayList;30import org.jmock.Mockery;31import org.jmock.Expectations;32import org.jmock.internal.matcher.ParametersMatcher;33import org.jmock.api.Action;34import org.jmock.api.Invocation;35public class Test2 {36 public static void main(String[] args) {37 Mockery context = new Mockery();38 final List<String> mockList = context.mock(List.class);39 context.checking(new Expectations() {{40 oneOf (mockList).add(with(ParametersMatcher.parameters(1, 2)));41 will(new Action() {42 public void describeTo(Description description) {43 description.appendText("add 1 and 2");44 }45 public Object invoke(Invocation invocation) throws Throwable {46 System.out.println("add 1 and 2");47 return null;48 }49 });50 }});51 mockList.add(1, 2);52 context.assertIsSatisfied();53 }54}55import java.util.List;56import java.util.ArrayList;57import org

Full Screen

Full Screen

ParametersMatcher

Using AI Code Generation

copy

Full Screen

1import org.jmock.core.Invocation;2import org.jmock.core.matcher.ParametersMatcher;3public class TestParametersMatcher extends ParametersMatcher {4 public TestParametersMatcher(Object[] parameters) {5 super(parameters);6 }7 public boolean matches(Invocation invocation) {8 return super.matches(invocation);9 }10}11import org.jmock.core.Invocation;12import org.jmock.core.matcher.ParametersMatcher;13public class TestParametersMatcher extends ParametersMatcher {14 public TestParametersMatcher(Object[] parameters) {15 super(parameters);16 }17 public boolean matches(Invocation invocation) {18 return super.matches(invocation);19 }20}21import org.jmock.core.Invocation;22import org.jmock.core.matcher.ParametersMatcher;23public class TestParametersMatcher extends ParametersMatcher {24 public TestParametersMatcher(Object[] parameters) {25 super(parameters);26 }27 public boolean matches(Invocation invocation) {28 return super.matches(invocation);29 }30}31import org.jmock.core.Invocation;32import org.jmock.core.matcher.ParametersMatcher;33public class TestParametersMatcher extends ParametersMatcher {34 public TestParametersMatcher(Object[] parameters) {35 super(parameters);36 }37 public boolean matches(Invocation invocation) {38 return super.matches(invocation);39 }40}41import org.jmock.core.Invocation;42import org.jmock.core.matcher.ParametersMatcher;43public class TestParametersMatcher extends ParametersMatcher {44 public TestParametersMatcher(Object[] parameters) {45 super(parameters);46 }47 public boolean matches(Invocation invocation) {48 return super.matches(invocation);49 }50}

Full Screen

Full Screen

ParametersMatcher

Using AI Code Generation

copy

Full Screen

1import org.jmock.core.*;2import org.jmock.core.constraint.*;3import org.jmock.internal.matcher.*;4import org.jmock.util.*;5public class 1 {6 public static void main(String[] args) {7 ParametersMatcher pm = new ParametersMatcher(8 new Constraint[] {9 new Any(),10 new IsEqual(new Integer(2)),11 new IsEqual(new Integer(3))12 }13 );14 System.out.println("ParametersMatcher: " + pm);15 System.out.println("ParametersMatcher: " + pm.matches(16 new Method("method1", new Class[] {String.class, Integer.class, Integer.class}, null),17 new Object[] {"hello", new Integer(2), new Integer(3)}18 ));19 }20}21ParametersMatcher: method1(java.lang.String, java.lang.Integer, java.lang.Integer)

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 ParametersMatcher

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