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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:40:48+00:00 2026-05-15T10:40:48+00:00

Mockito api provides method: Mockito.verifyNoMoreInteractions(someMock); but is it possible in Mockito to declare that

  • 0

Mockito api provides method:

Mockito.verifyNoMoreInteractions(someMock);

but is it possible in Mockito to declare that I don’t want more interactions with a given mock with the exceptions of interactions with its getter methods?

The simple scenario is the one in which I test that the SUT changes only certain properties of a given mock and leaves other properties untapped.

In example I want to test that UserActivationService changes property Active on an instance of class User but does’t do anything to properties like Role, Password, AccountBalance, etc.

  • 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-15T10:40:49+00:00Added an answer on May 15, 2026 at 10:40 am

    No this functionality is not currently in Mockito. If you need it often you can create it yourself using reflection wizzardry although that’s going to be a bit painful.

    My suggestion would be to verify the number of interactions on the methods you don’t want called too often using VerificationMode:

    @Test
    public void worldLeaderShouldNotDestroyWorldWhenMakingThreats() {
      new WorldLeader(nuke).makeThreats();
    
      //prevent leaving nuke in armed state
      verify(nuke, times(2)).flipArmSwitch();
      assertThat(nuke.isDisarmed(), is(true));
      //prevent total annihilation
      verify(nuke, never()).destroyWorld();
    }
    

    Of course the sensibility of the WorldLeader API design might be debatable, but as an example it should do.

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

Sidebar

Related Questions

I'm verifying that a function was called using Mockito, but Mockito is telling me
I've got a method that I'd like to test with JUnit/Mockito. The method takes
I'm having problems with counting method calls with Mockito. Problem is that the method
I've been trying to get to mock a method with vararg parameters using Mockito:
Can I use Mockito to capture what was passed to the HttpServletResponse#sendError() method? I
Consider a method signature like: public String myFunction(String abc); Can Mockito help return the
How do I write a Mockito-based JUnit method to test this method adduser() ?
I'm writing a JUnit test and also using Mockito, and I want to call
PowerMock provides the method expectPrivate to mock out private methods, however it appears only
I'm new to Mockito and want to use it in unit tests. What I

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.