Category "mockito"

Mocking Unirest with mockito

I am in my starting programming phase and I wanted to ask about mocking Objects with Mockito, more specifically is the Unirest response. Let's say I have a data

Mock redis template

I am facing a issue in mock redis template. Can any one help me to write unit test for below class. @Repository public class CasheRepo { @Autowired pr

Creating strict mock when using @MockBean of spring boot?

I use @MockBean of spring boot (with @RunWith(SpringRunner.class)) and everything was ok so far. However the mock provides default implementation for every meth

How to mock Base64 in Android?

I am writing a Unit test for a class that uses android.util.Base64 and I get this error: java.lang.RuntimeException: Method encode in android.util.Base64 not m

how to mock global variable in Mockito

I have a global variable global. My method has a line: global.getListOfObjects() I am trying to write a unit test and keep getting a NPE on the above line.

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