Issue
Is there anything i can do to get the @Mock and @InjectMocks annotation to work with java 11?
Solution
Not sure why this worked for you in Java7, but you clearly use @InjectMocks
in a wrong way.
@InjectMocks
private ByVehicleIdRequest request = new ByVehicleIdRequest(
locale,
additionalInfo,
permissions,
switches,
vehicleId,
aftermarketDescriptions,
enhancedStringMatchingSettings);
If you use Mockito runner (or extension in JUnit5), you should not initialize the field yourself:
@InjectMocks
private ByVehicleIdRequest request;
As described in MockitoJUnitRunner documentation:
Mocks are initialized before each test method.
If you use the mock values in the field initialization of request
object, you are passing not-yet-initialized values to the constructor, and hence null values you observe.
Note
The answer refers to question version 3.
Answered By - Lesiak
Answer Checked By - Senaida (JavaFixing Volunteer)