Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change assignability check for interfaces #16341

Merged
merged 1 commit into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}