Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Devops
  3. Question
Devops

How to verify that a specific method was not called using Mockito?

Asked by Anil Mer Jun 29, 2021 1.0K views 1 answer
Share

About this question

How to verify that a method is not called on an object's dependency?

For example:

public interface Dependency {
    void someMethod();
}
public class Foo {
    public bar(final Dependency d) {
        ...
    }
}

With the Foo test:

public class FooTest {
    @Test
    public void dependencyIsNotCalled() {
        final Foo foo = new Foo(...);
        final Dependency dependency = mock(Dependency.class);
        foo.bar(dependency);
        **// verify here that someMethod was not called??**
    }
}

Your answer

1 Answer

More Devops discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest DevOps Blogs

Guides, tips and career advice on DevOps from JanBask experts.