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 9277477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T17:07:07+00:00 2026-06-18T17:07:07+00:00

I have a strange problem with EasyMock This is the call I’m making which

  • 0

I have a strange problem with EasyMock

This is the call I’m making which throws an IllegalStateException : Matcher expected as expected

expect(this.mock.expectedOperation(gt(0l), MyClass.class)).andReturn(createClassObject());

If I replace the above call with

expect(this.mock.expectedOperation(gt(0l), createClass(MyClass.class))).andReturn(createClassObject());

@SuppressWarnings("unchecked")
public static <T> Class<T> createClass(Class<T> clazz)
{
    return (Class<T>) EasyMock.anyObject();
}

Most times i don’t get an error, but sometimes I do. It stays IllegalStateException : Matcher expected ..

Sometimes I get the IllegalStateException : 2 Matchers expected 1 recorder error for doing this:

MyClass object = createClassObject();
expect(this.mock.expectedOperation(anyLong(), anyLong()).andReturn(object);

public MyClass createClassObject() {
    // Actually sets properties and then returns
    return new MyClass();
}

But it runs when I do this:

expect(this.mock.expectedOperation(anyLong(), anyLong()).andReturn(createClassObject());

In the above example, sometimes the former runs and latter fails.

Sometimes this fails :

MyClass object = createClassObject();
expect(this.mock.expectedOperation(1, MyClass.class)).andReturn(object);

I have quadruple checked the reset, replay, verify calls. These tests run sometimes and sometimes fail.

If i run my unit test, it randomly fails at least once in one of the above listed situations. Why? How do I get it running?

EDIT : I’m using EasyMock version 3.1 and

MockedClass mock = EasyMock.createMock(MockedClass.class);
  • 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-06-18T17:07:09+00:00Added an answer on June 18, 2026 at 5:07 pm

    Found the problem. We can’t use the gt(0) etc methods to pass parameters into the unit being tested.

    In another test by my mistake had used :

    service.performOperation(1, gt(0l));
    

    service was not a mock, but the unit i was testing.

    On checking the documentation I saw that gt(0l) returns 0, which was causing this test to pass by others to fail. (Dunno why?) Since tests are executed randomly, random conditions were failing.

    Using the reset(mocks..) at the beginning of the tests did nothing to help.

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

Sidebar

Related Questions

I have a strange problem. I do this query in a node.js server using
I have strange problem for which I can't think of a solution. I have
I have strange problem. I have class which behaves similar dropdown list. package test.view;
I know that this question has already been asked, but I have strange problem
I have this strange problem with AppBarButton. I have binded the button to a
I have this strange problem. I have this script: echo $comment_content = $_POST['comment_content']; echo
I have this strange problem. In my app I'm asking the device, if DeviceMotion
I have strange problem with an MVC3 application. The application works as expected on
I have a strange problem with paths, this one works (on Windows): <div style=background:url('folder1/image.gif')...
i have strange problem doing reporting: i have numerous clients with different issued invoices.

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.