Skip to content

Commit

Permalink
Merge pull request #16341 from stuartwdouglas/mock-check
Browse files Browse the repository at this point in the history
Change assignability check for interfaces
  • Loading branch information
gsmet authored Apr 8, 2021
2 parents 5a707a9 + 678ff11 commit d99092b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ static <T> void installMock(T instance, T mock) {
if (inst == null) {
throw new IllegalStateException("No test in progress");
}
if (!(instance.getClass().getSuperclass().isAssignableFrom(mock.getClass()))) {
throw new RuntimeException(mock
+ " is not assignable to type " + instance.getClass().getSuperclass());
}
try {
Method setMethod = instance.getClass().getDeclaredMethod("arc$setMock", Object.class);
setMethod.invoke(instance, mock);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ public static <T> void installMockForInstance(T mock, T instance) {
*/
public static <T> void installMockForType(T mock, Class<? super T> instance, Annotation... qualifiers) {
//mock support does the actual work, but exposes other methods that are not part of the user API
if (!instance.isAssignableFrom(mock.getClass())) {
if (!(instance.getClass().getSuperclass().isAssignableFrom(mock.getClass()))) {
throw new RuntimeException(mock
+ " is not assignable to type " + instance.getClass().getSuperclass());
}
}
MockSupport.installMock(CDI.current().select(instance, qualifiers).get(), mock);
}
}

0 comments on commit d99092b

Please sign in to comment.