Skip to content

Commit

Permalink
Change assignability check for interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas committed Apr 8, 2021
1 parent ecb6be6 commit 678ff11
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 678ff11

Please sign in to comment.