Top "Mockito" questions

Mockito is a mocking framework for Java.

Mockito: InvalidUseOfMatchersException

I have a command line tool that performs a DNS check. If the DNS check succeeds, the command proceeds with …

java unit-testing mockito
Using Mockito to mock classes with generic parameters

Is there a clean method of mocking a class with generic parameters? Say I have to mock a class Foo&…

java generics mockito
Mockito: Mock private field initialization

How I can mock a field variable which is being initialized inline? class Test { private Person person = new Person(); ... public …

java mockito junit4 powermockito
Using Mockito to test abstract classes

I'd like to test an abstract class. Sure, I can manually write a mock that inherits from the class. Can …

java unit-testing mocking abstract-class mockito
Mockito - NullpointerException when stubbing Method

So I started writing tests for our Java-Spring-project. What I use is JUnit and Mockito. It's said, that when I …

java testing junit mockito stubbing
Test class with a new() call in it with Mockito

I have a legacy class that contains a new() call to instantiate a LoginContext(): public class TestedClass { public LoginContext login(…

java unit-testing junit mockito
How to use ArgumentCaptor for stubbing?

In Mockito documentation and javadocs it says It is recommended to use ArgumentCaptor with verification but not with stubbing. but …

java unit-testing junit mockito
Mockito - difference between doReturn() and when()

I am currently in the process of using Mockito to mock my service layer objects in a Spring MVC application …

java unit-testing mockito
How to mock private method for testing using PowerMock?

I have a class which I would like to test with a public method that calls private one. I'd like …

java testing junit mockito powermock
How do I mock an autowired @Value field in Spring with Mockito?

I'm using Spring 3.1.4.RELEASE and Mockito 1.9.5. In my Spring class I have: @Value("#{myProps['default.url']}") private String defaultUrl; @Value("#{…

spring mockito autowired value-initialization