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

  • Home
  • SEARCH
  • 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 1092551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:41:58+00:00 2026-05-16T23:41:58+00:00

What is the difference between using andReturn(T value) vs andStubReturn(T value) for EasyMock? In

  • 0

What is the difference between using andReturn(T value) vs andStubReturn(T value) for EasyMock?

In what situation would you use andStubReturn() where andReturn() can’t achieve the same result?

  • 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-16T23:41:59+00:00Added an answer on May 16, 2026 at 11:41 pm

    You use a stub return for a method call on the mock that you expect to happen but aren’t otherwise interested in. You use a regular return for a “regular” method call.

    Consider the following method:

    public void someMethod(String arg) {
        if (logger.isDebugEnabled()) {
            logger.debug("Calling doSomething() on service " 
                           + service.getName().hashCode());
        }
    
        service.postMessage("{" + arg + "}");
    
        if (logger.isDebugEnabled()) {
            logger.info("Finished calling doSomething() on service " 
                          + service.getName().hashCode());
        }
    }
    

    …where service is a mockable field. The hashCode() thing in the log statements is contrived, but the point is that your mock needs to respond to any number of calls to getName() to avoid an NPE, while you couldn’t otherwise care less about it.

    When writing an EasyMock based unit test for this method, you’d andStubReturn() the call to getName() and use a normal andReturn() for the call to postMessage(String). When you verify the mock object, it’ll only consider the latter and your the test doesn’t break if you change the log4j config.

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

Sidebar

Related Questions

What is the difference between using @class & #import ? I had a situation
Is there any difference between using the Microsoft.VisualBasic.DateAndTime.Now compared to the System.DateTime.Now? I seem
What is the difference between using output cache in view: <%@ Page Language=C# Inherits=System.Web.Mvc.ViewPage<Mahmure.WebUI.ViewModels.NewsletterVM>
what is Difference between using XMLRoot/XMLElement and using Serializable() attributes? how do i know
What is the difference between using location.hostname and document.domain? I think an explanation with
What is the difference between using this [self performSelectorOnMainThread:@selector(doStuff:) withObject:myObject waitUntilDone:YES]; instead of simply
I'm trying to implement something that finds the common suffix between a number of
Let's say I have a screen that shows the animals in my farm. If
Consider the following class: class SquareErrorDistance(object): def __init__(self, dataSample): variance = var(list(dataSample)) if variance
so far I thought that any operation done on shared object (common for multiple

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.