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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:24:48+00:00 2026-06-08T23:24:48+00:00

I am learning unit testing and mocking. I have JUnit running, and instead of

  • 0

I am learning unit testing and mocking. I have JUnit running, and instead of using a Mocking Framework, I have manually created mock classes by extending existing classes and interfaces. I would like to learn the mocking framework EasyMock because thats all thats available here at my work. While you might suggest some other mocking framework, they will not be available to me.

The Setup:

I have a View and a Presenter and a API backend. When the user clicks a button: “Check For Updates”, the view calls the presenter.checkForUpdates() which does a call to api.checkForUpdates() and expects an callback. If the an exception occurs, the api will notify the presenter via a callback, and the controller will call the view method view.showUserError(). Callbacks are used not return parameters because of the async nature of hitting our API bac
kend.

The Object under test is the Presenter. Specifically, I want to test that the View.showUserError() gets called when an exception occurs in the Api. I believe I can mock Api.checkForUpdates() to immediately call the exception callback instead of doing an actual network call.

The problem is, I only see EasyMock mocking return values. For example:

EasyMock.expect(api.checkForUpdates()).andReturn(xxxx)

wont work for me, since api.checkForUpdates() does not return anything and instead does a callback. What I really want to do is something like:

EasyMock.expect(api.checkForUpdates()).andExecute(exceptionCallback(NetworkError));

But I don’t see how to do that. Is there something that can do what I want or am I missing something basic?

Thanks

  • 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-08T23:24:49+00:00Added an answer on June 8, 2026 at 11:24 pm

    I think you can make a stub using ‘ Expect().andDelegateTo()’ API.

    http://devlearnings.wordpress.com/2010/07/10/easymock-assert-arguments-of-method-call/

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

Sidebar

Related Questions

I am learning the Moles framework for unit testing. I have a template ASP
I have a problem. I'm learning JPA. I'm using embedded OpenEJB container in unit
I am learning the ropes with Unit testing Zend Framework applications. So far I
I'm learning how unit testing is done in Rails, and I've run into a
I am just learning how to do unit-testing. I'm on Python / nose /
i'm just learning to put in unit testing for my asp.net mvc when i
After learning about TDD and unit testing, I'm really looking to write tests when
I'm new to unit testing, and I'm learning how to use NUnit and Moq.
I am learning about Unit Testing and want to know how to write testable
I am fairly new to unit testing in C# and learning to use Moq.

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.