How to use method of org.jmock.test.acceptance.InvocationDescriptionAcceptanceTests class

Best Jmock-library code snippet using org.jmock.test.acceptance.InvocationDescriptionAcceptanceTests.

Run Jmock-library automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

copy
1package org.jmock.test.acceptance;
2
3import static org.hamcrest.CoreMatchers.containsString;
4import static org.junit.Assert.assertThat;
5import static org.junit.Assert.fail;
6
7import org.jmock.Expectations;
8import org.jmock.api.Imposteriser;
9import org.jmock.integration.junit4.JUnit4Mockery;
10import org.jmock.test.unit.lib.legacy.ImposteriserParameterResolver;
11import org.junit.jupiter.params.ParameterizedTest;
12import org.junit.jupiter.params.provider.ArgumentsSource;
13
14/**
15 * @author Steve Freeman 2012 http://www.jmock.org
16 */
17public class InvocationDescriptionAcceptanceTests {
18  private static final String UNEXPECTED_ARGUMENT = "unexpected argument";
19  private final JUnit4Mockery aMockContext = new JUnit4Mockery();
20
21    private final SubBean aSubBean = aMockContext.mock(SubBean.class);
22    private final Collaborator aCollab = aMockContext.mock(Collaborator.class);
23
24    // https://github.com/jmock-developers/jmock-library/issues/20
25    @ParameterizedTest
26    @ArgumentsSource(ImposteriserParameterResolver.class)
27    public void doesNotModifyInvocationsWhileReportingFailure(Imposteriser imposteriserImpl) {
28      final Bean lBean = new Bean(aSubBean);
29
30      aMockContext.checking(new Expectations() {{
31        allowing(aSubBean).count(); will(returnValue(123));
32        oneOf(aCollab).message("xyzzy", lBean);
33      }});
34
35      try {
36        new Subject(aCollab).doIt(lBean);
37      } catch (AssertionError expected) {
38        assertThat(expected.getMessage(), containsString("collaborator.message(\"unexpected argument\", <Bean{123}>)"));
39        return;
40      }
41      fail("should have thrown exception");
42    }
43
44    static class Bean  {
45      private final SubBean aSubBean;
46
47      public Bean(SubBean pSubBean) {
48        aSubBean = pSubBean;
49      }
50
51      @Override
52      public String toString() { // called via describeTo() when reporting error
53        return String.format("Bean{%d}", aSubBean.count());
54      }
55    }
56
57    interface SubBean {
58      int count();
59    }
60
61    interface Collaborator {
62      void message(String pX, Bean pBean);
63    }
64
65    static class Subject {
66      private final Collaborator aCollab;
67
68      public Subject(Collaborator pCollab) {
69        aCollab = pCollab;
70      }
71
72      @SuppressWarnings("UnusedDeclaration")
73      void doIt(Bean pBean) {
74        aCollab.message(UNEXPECTED_ARGUMENT, pBean);
75      }
76    }
77
78
79}
80
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Most used method in InvocationDescriptionAcceptanceTests

Trigger code on LambdaTest Cloud Grid

Execute automation tests with on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)