Skip to content

Commit

Permalink
mockito#2921: Android 26 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Jörg von Frantzius committed Feb 26, 2023
1 parent 2f6cf4e commit b8e1cd5
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ public OngoingInjector filterCandidate(
Type genericType = candidateFieldToBeInjected.getGenericType();
// be more specific if generic type information is available
if (genericTypeToMock!=null || genericType!=null) {
if (genericTypeToMock!=null && genericType!=null && genericTypeToMock.getTypeName().equals(genericType.getTypeName())) {
// would rather like to use Type.getTypeName(), but that doesn't exist in Android SDK 26
// which Mockito aims to maintain compatibility with.
// Type.getTypeName() is documented to simply call Type.toString(), so use that instead
if (genericTypeToMock!=null && genericType!=null && genericTypeToMock.toString().equals(genericType.toString())) {
mockTypeMatches.add(mock);
} // else: filter out mock, as generic types don't match
} else {
Expand Down

0 comments on commit b8e1cd5

Please sign in to comment.