Null pointer exception when stubbing
Mockito advices against Mocking classes you don't own. So an Application mock is a bad idea.
Junit can give you the application context needed : https://developer.android.com/training/testing/junit-runner
For other info about stubbing fail, Mockito fails on stubbing : it tries to execute the function that should be stubbed
Mockito when() method not working and getting null pointer exception
You have classes calling each others methods so it is better to use Mockito.RETURNS_DEEP_STUBS
In your Case:
A
is callingB
andB
is callingC
Just replace:
@InjectMock
A a;
@Mock
B b;
C c;
With :
A a = Mockito.mock(A.class, Mockito.RETURNS_DEEP_STUBS);
B b = Mockito.mock(B.class, Mockito.RETURNS_DEEP_STUBS);
C c = Mockito.mock(C.class, Mockito.RETURNS_DEEP_STUBS);
Related Topics
How to Remove Trailing Zeros from a Double
Maven Build Cannot Find Symbol When Accessing Project Lombok Annotated Methods,
Passing List from Thymeleaf to Spring Controller
Use String.Split() With Multiple Delimiters
Mockito How to Mock Only the Call of a Method of the Superclass
Finding Max Value in an Array Using Recursion
How to Solve Liquibase Checksum Validation Fail After Liquibase Upgrade
How to Hide a Request Field in Swagger API
Maven Builds Are Working, But Junit Is Throwing a Nosuchmethoderror
Error Starting Applicationcontext in Spring Boot App
How to Fix Expected Begin_Object But Was String in Retrofit