Category "mockito"

Mockito when() method not working and getting null pointer exception

I am writing unit test cases using Mockito and JUnit . But getting NullPointerException when running a test. On debugging I get to know that Mockito on method:

Mockito verify unit test - Wanted but not invoked. Actually, there were zero interactions with this mock

At first I want to sorry for my english. I started to make some unit tests (i've never done this before, i'm a new guy in programming). I have to test simple

Use Mockito 2.0.7 to mock lambda expressions

I want to mock a query provided on my repository like this: @Test public void GetByEmailSuccessful() { // setup mocks Mockito.when(this.personRepo.find

How to mock a local variables using mockito/powermock

I have a function as follows : private Response getHttpResponse(String url) { WebTarget target = client.target(url); Invocation.Builder requestBuilder =

Mockito ClassCastException - A mock cannot be cast

I have a method in the class AppleProcessor which I would like to test: public void process(Fruit fruit) { if(fruit.getType() == Fruit.APPLE) { fru

Mocking java.lang.reflect.Method using Mockito

I need to mock java.lang.reflect.Method for my test (I have dynamic things). We have written all the test cases using Junit spring & mockito. But I am facin

How to mock ResourceBundle.getString()?

I'm failing to mock ResourceBundle.getString(). This is my code: ResourceBundle schemaBundle = Mockito.mock(ResourceBundle.class); Mockito.when(schemaBundle.g

How to use Mockito with JUnit5

How can I use injection with Mockito and JUnit 5? In JUnit4 I can just use the @RunWith(MockitoJUnitRunner.class) Annotation. In JUnit5 is no @RunWith Annotati

Mockito.when().thenReturn() doesn't work or returns null

During the test there is a NullPointerException thrown. I tried to debug it and the only thing I worked out was that eventOptional is always null. Just as if Mo