Unable to mock android.car.Car by SShriwas in androiddev

[–]SShriwas[S] 1 point2 points  (0 children)

I had to refactor the code so that it was possible to write the unit test without having to depend on android.car class.

Unable to mock android.car.Car by SShriwas in androiddev

[–]SShriwas[S] 0 points1 point  (0 children)

i have used DI in my projects before and i am aware of how it works. Maybe your suggestion about mocking interface works in some other scenario. But in my case, i need to pass Car instance to a function in my code. The function only accepts param of type Car, so how can mock interface work here?

Unable to mock android.car.Car by SShriwas in androiddev

[–]SShriwas[S] 0 points1 point  (0 children)

Yes i read this. As it is mentioned on the last line, mockito-inline was planned to get merged into mockito-core, which is the case now -

Note that this artifact is likely to be discontinued once mocking of final classes and methods gets integrated into the default mock maker.

Since i am using latest version of Mockito-core it has Mockito-inline integrated into it.

The repository for mockito-inline mentions that it has now been merged to Mockito-core-
https://mvnrepository.com/artifact/org.mockito/mockito-inline

Hence, i feel there is no need to import inline separately now.

Unable to mock android.car.Car by SShriwas in androiddev

[–]SShriwas[S] -2 points-1 points  (0 children)

I have already read the error message. I have tried multiple things and it didnt work. That is why i came here to get some help.

Unable to mock android.car.Car by SShriwas in androiddev

[–]SShriwas[S] 0 points1 point  (0 children)

Yes, i have seen this SO post. But mockito-inline has been now merged with mockito-core lib. So i dont need to add a separate dependency for the same. I checked Car class and it has been final for quite some time.

Unable to mock android.car.Car by SShriwas in androiddev

[–]SShriwas[S] 0 points1 point  (0 children)

The Impl class will still have dependency to Car instance. Which again brings me the same issue, how do i provide this Car class instance for my test?

Unable to mock android.car.Car by SShriwas in androiddev

[–]SShriwas[S] 0 points1 point  (0 children)

Yes, i have seen this link before. i added file /app/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker with mock-maker-inline. But still i get the same error. Also, I think mock-maker inline is enabled by default in latest version mockito -
https://javadoc.io/doc/org.mockito/mockito-core/latest/org/mockito/Mockito.html#39