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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:10:00+00:00 2026-05-19T03:10:00+00:00

I have am having a problem with EasyMock returning null for an expected (defined)

  • 0

I have am having a problem with EasyMock returning null for an expected (defined) method call.

Creation of the mocked Object

mock = EasyMock.createMock(DAO.class);

Mock Set up in unit test.

expect(mock.update(myObj).andReturn(myObjUpdated).once();
replayAll();
service.setDao(mock);
service.processData(myObj);
verifyAll();

processData method simply calls

MyObject objUpdated = dao.update(myObj);

here is the interface that the mock is being built from.

public interface DAO {
   public <ENTITY> ENTITY update(ENTITY entity);
}

I am pretty confused by what might be causing the problem. I have confirmed that ‘obj’ is the same object as I defined in the unit test. I have also not experienced this problem (that I am aware of) with any other methods that mocked.

Could the problem possibly be with the Object that is being passed in?

Thanks in advance. I am really not sure what other information might be helpful to you here.

edit: this is the test class (and as it turns out where my misunderstanding began)

public class TestMyService extends EasyMockHelper {...}
  • 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-19T03:10:01+00:00Added an answer on May 19, 2026 at 3:10 am

    So it turns out that my main problem isn’t with the expectations or even with the creation of the mock object. I had a fundamental misunderstanding about how the EasyMockSupport class which my test is extending functions. This isn’t covered very well in the documentation, but if you exam the examples a bit more closely my error became obvious.

    The EasyMockSupport class gives my test class access to methods such as replayAll(), verifyAll(), and resetAll(). what these do is allow me to now worry about manually controlling each created mock object. However, what the documentation failed to mention was that you have to create you Mock object USING the methods provided by the EasyMockSupport class so that it can properly register the controls. ((this makes total sense btw, I simply wasn’t reading it anywhere)). The EasyMockSupport class if you look into the API provides the child class with all the methods that it would normally use statically from the EasyMock class, such as createMock(Class class).

    So as for the updated code

    public class TestMyService extends EasyMockSupport {
       private MyService service;
       private MyDao dao;
    
       private MyObject myObj;
    
       @Before public void setUp() {
          service = new MyService();
    
          // THIS IS THE KEY
          mock = createMock(IDao.class); //CORRECT
          // mock = EasyMock.createMock(IDao.class); //WRONG
    
          service.setDao(mock);
          myObj = new MyObject("expectedData");
       }
       @After public void tearDown() {
          verifyAll();
       }
       @Test public void testMyService() {
          expect(mock.update(myObj)).andReturn(myObj);
          replayAll();
          service.myService(myObj);
       }
    }
    
    public class MyService() {
       private IDao dao;
       public void setDao(IDao dao) {this.dao = dao; }
       public MyObject myService(MyObject myObj) {
          return dao.update(myObj);
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been having some problem with the stringByAddingPercentEscapesUsingEncoding: method. Here's what happens: When
I am having problem with ViewDidLoad Method.I have one .Xib File in my app
I have following method that does some stringbuilding, but unfortunately i am having problem
I'm having problem about web service method with auto increment ID. I have a
Im having problem in my UIscrollView ,this is what I have done: Whenever a
I have this problem having to display my jasper report on my grails application.
I have been having this annoying problem when trying to implement a picture gallery
I have been having the following problem, i think it's probably due to the
I am having problem with overriding Form Action URL I have a class to
I'm having problem with datagrid view. I have attached an image with the code

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.