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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:51:17+00:00 2026-06-01T17:51:17+00:00

I am using EasyMock and EasyMock CE 3.0 to mock dependent layers and test

  • 0

I am using EasyMock and EasyMock CE 3.0 to mock dependent layers and test my classes. Below is the scenario for which I am not able to find any solution

I have class to be tested, which calls a dependent class void method that takes an input param, and alters the same param. The method that I am testing is doing some operations based on the altered param, which I have to test now for various scenarios

Consider the below sample, where I have tried to put the same scenario

public boolean voidCalling(){
    boolean status = false;
    SampleMainBean mainBean = new SampleMainBean();
    dependentMain.voidCalled(mainBean);
    if(mainBean.getName() != null){
        status = true; 
    }else{
        status = false;
    }
    return status;
}

And the dependentMain class the below method

public void voidCalled(SampleMainBean mainBean){
    mainBean.setName("Sathiesh");
}

To have full coverage, I need to have 2 test cases to test both the scenarios where true and false are returned, but I always get false as I am not able to set the behaviour of the void method to alter this input bean. How can I get a true as result in this scenario using EasyMock

Thanks in advance for any help.

  • 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-01T17:51:18+00:00Added an answer on June 1, 2026 at 5:51 pm

    Starting from the answer in this answer: EasyMock: Void Methods, you can use IAnswer.

    // create the mock object
    DependentMain dependentMain = EasyMock.createMock(DependentMain.class);
    
    // register the expected method
    dependentMain.voidCalled(mainBean);
    
    // register the expectation settings: this will set the name 
    // on the SampleMainBean instance passed to voidCalled
    EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
        @Override
        public Object answer() throws Throwable {
            ((SampleMainBean) EasyMock.getCurrentArguments()[0])
                    .setName("Sathiesh");
            return null; // required to be null for a void method
        }
    });
    
    // rest of test here
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using EasyMock to create mock classes in test cases. expect(entity.getType()).andReturn(string); Type belongs
I'm using EasyMock to create mock that is one of private parameters (without setter)
Using Nunit, I want to be able to write a test fixture that will
I am currently using EasyMock and creating mock objects like this mockedObject = createMock(myInterface.class);
I have to mock the following security step using EasyMock or UnitilsMock. Could you
Is there any good feature in EasyMock that is not there or not properly
I am using EasyMock to unit test my Java code. The class I'm trying
Using EasyMock I want to be able to say that I expect a specific
i am writing the junit using easy mock for my program. Below is the
I have been looking at EasyMock and tutorials/examples around using it for Unit Testing

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.