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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:41:13+00:00 2026-06-05T03:41:13+00:00

I am new to jmockit, although the framework is currently in use slightly inside

  • 0

I am new to jmockit, although the framework is currently in use slightly inside our application.

I am attempting to mock out my DAOs for my services layer. I understand how to use returns on my expectations to return my objects for my read methods, but I want to capture the objects created using the create methods so that I can test them.

How do I do this?

for instance, DAO contains:

public void create(Person person){
    //code to create person here.
}

I want to mock it up so that I capture the person coming into this method so I can interrogate later in my tests.

Based on feedback, I made a test using the following…

@Mocked @NonStrict
private PaymentStubDAO mockPaymentStubDAO;

…

new Expectations() {
    {
    mockPaymentStubDAO.create((PaymentStub) any);
    returns(any);
    }
};

…

//set up the verifications
new Verifications() {{
  mockPaymentStubDAO.create((PaymentStub) any);
  forEachInvocation = new Object() {
     @SuppressWarnings("unused")
    void validate(PaymentStub stub) {
         assertEquals(1, (int)stub.getDaysJuror());
     }
  };

}};

And when I run it, I get the following error on the line with new Verifications():

java.lang.AssertionError: Missing 1 invocation to:
Object com.acs.gs.juror.dao.accounting.PaymentStubDAO#create(Object)
with arguments: null
on mock instance: $Impl_PaymentStubDAO@424f8ad5
    at com.acs.gs.juror.manager.accounting.impl.AccountingManagerImplTest$2.<init>(AccountingManagerImplTest.java:1925)
    at com.acs.gs.juror.manager.accounting.impl.AccountingManagerImplTest.testPayOverUnderLimit(AccountingManagerImplTest.java:1924)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: Missing invocations
    at com.acs.gs.juror.manager.accounting.impl.AccountingManagerImplTest$1.<init>(AccountingManagerImplTest.java:1859)
    at com.acs.gs.juror.manager.accounting.impl.AccountingManagerImplTest.testPayOverUnderLimit(AccountingManagerImplTest.java:1845)
    ... 12 more
  • 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-05T03:41:15+00:00Added an answer on June 5, 2026 at 3:41 am

    Per the documentation:

     @Test
    public void verifyExpectationWithArgumentValidatorForEachInvocation(
         final Collaborator  mock)
    {
      // Inside tested code:
      new Collaborator().doSomething(true, new int[2], "test");
    
      new Verifications() {{
         mock.doSomething(anyBoolean, null, null);
         forEachInvocation = new Object()
         {
            void validate(Boolean b, int[] i, String s)
            {
               assertTrue(b);
               assertEquals(2, i.length);
               assertEquals("test", s);
            }
         };
      }};
    

    }

    Found at JMockit Docs

    FYI, as I mentioned in your previous question Mockito makes this a lot easier in my opinion. Ask yourself if you are really locked down to JMockit.

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

Sidebar

Related Questions

New to Git and just started to use Github. Just created my first public
New to android, when I debugging in Eclipse I use to press F6 to
New to Python and trying to figure out what went wrong here. Making a
new Timer().scheduleAtFixedRate(new TimerTask() { @Override public void run() { System.out.println(run); throw new SomeRandomException(); }
I'm using the JMockit framework and I'm trying to test my simple EventBus implementation
I am trying to mock a DAO with JMockit: public interface MyDao { Details
New to MVC, working on an MVC application where the users do searching on
I am trying to mock java.awt.Toolkit.beep() using JMockit Expectations. I have the following code
New to MVVM...and I am noticing our ViewModel's are doing the following: They are
New to PHP, would love to get to know it better. Currently working on

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.