Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6808611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:58:39+00:00 2026-05-26T19:58:39+00:00

Below I am just trying to mock a class named TestWrapper and set ‘allowing’

  • 0

Below I am just trying to mock a class named TestWrapper and set ‘allowing’ expecations on it. However, when setting expectations I get error. When using easymock and just setting expectations, this doesn’t seem to happen

import org.jmock.Expectations;
import org.jmock.Mockery;
import org.jmock.integration.junit4.JUnit4Mockery;
import org.jmock.lib.legacy.ClassImposteriser;
import org.junit.Before;
import org.junit.Test;

import java.math.BigDecimal;

public class CustomerPaymentProgramConverterTest {

    TestWrapper paymentType;

    Mockery mockery = new JUnit4Mockery() {{
            setImposteriser(ClassImposteriser.INSTANCE);
    }};

    @Before
    public void setupMethod() {

      paymentType = mockery.mock(TestWrapper.class);

    }

    @Test
    public void testFromWebService() {

        mockery.checking(new Expectations() {{

                    //debugger throws error on the line below.
                    allowing(paymentType.getScheduledPaymentAmount());
                    will(returnValue(new BigDecimal(123)));
                    allowing(paymentType.getScheduledPaymentConfirmationNumber());
                    will(returnValue(121212L));
        }});

    }
}

TestWrapper.class

 //Class I am mocking using JMock
 public class TestWrapper {

     public  java.math.BigDecimal getScheduledPaymentAmount() {
         return new BigDecimal(123);
     }
     public  long getScheduledPaymentConfirmationNumber() {
         return 123L;
     }
}

Assertion Error..

java.lang.AssertionError: unexpected invocation: paymentProgramScheduledPaymentTypeTestWrapper.getScheduledPaymentAmount()
no expectations specified: did you...
 - forget to start an expectation with a cardinality clause?
 - call a mocked method to specify the parameter of an expectation?
what happened before this: nothing!
    at org.jmock.internal.InvocationDispatcher.dispatch(InvocationDispatcher.java:56)
    at org.jmock.Mockery.dispatch(Mockery.java:218)
    at org.jmock.Mockery.access$000(Mockery.java:43)
    at org.jmock.Mockery$MockObject.invoke(Mockery.java:258)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:58:39+00:00Added an answer on May 26, 2026 at 7:58 pm

    You’re using the JMock API incorrectly. It should be

    public void testFromWebService() {
    
        mockery.checking(new Expectations() {{
    
                    //debugger throws error on the line below.
                    allowing(paymentType).getScheduledPaymentAmount();
                    will(returnValue(new BigDecimal(123)));
                    allowing(paymentType).getScheduledPaymentConfirmationNumber();
                    will(returnValue(121212L));
        }});
    
    }
    

    This is saying that when you call the method under test (which you don’t seem to be doing in your test) you will expect calls to those methods to return those values. The PaymentType would be a dependency in your class under test which you are mocking.

    See JMock Getting Started

    Also, you have a compliation error in the @Before method

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I grabbed this code form JCarousel and just trying to understand these lines below.
I just now start using knockoutjs. In below code am just trying to bind
I am just trying to clear the app data and getting below error java.lang.SecurityException:
I'm just trying reflection : using System; using System.Collections.Generic; using System.Reflection; public class CTest
Pretty simple set-up here, I'm just trying to get two divs to sit side-by-side.
Just trying to better understand why the second item below does not work. The
I am trying to use a function pointer, but the 3 lines below just
as you can see from the code below im just trying to get the
I'm just trying to run a migration, but I'm getting the following stacktrace (below).
When running the follow query i receive the error below, Im just trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.