|
29 | 29 | import java.util.stream.Collectors; |
30 | 30 | import java.util.stream.Stream; |
31 | 31 |
|
| 32 | +import org.apache.commons.lang3.ClassUtils; |
32 | 33 | import org.openqa.selenium.By; |
33 | 34 | import org.openqa.selenium.JavascriptExecutor; |
34 | 35 | import org.openqa.selenium.WebDriver; |
@@ -84,16 +85,23 @@ default <T> T createCallableProxy(Class<T> intf) { |
84 | 85 | public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { |
85 | 86 | Object result = call(method.getName(), args); |
86 | 87 |
|
87 | | - if (result == null || method.getReturnType() == Void.TYPE) { |
| 88 | + Class<?> returnType = method.getReturnType(); |
| 89 | + if (result == null || returnType == Void.TYPE) { |
88 | 90 | return null; |
89 | 91 | } |
90 | 92 |
|
91 | | - if (method.getReturnType() == JsonArrayList.class) { |
| 93 | + if (returnType == JsonArrayList.class) { |
92 | 94 | return JsonArrayList.wrapForTestbench((List<?>) result); |
93 | 95 | } |
94 | 96 |
|
95 | | - // this implementation is incomplete. |
96 | | - // other types that should be supported are: Double, Integer, Boolean, String, JsonValue |
| 97 | + if (returnType.isPrimitive()) { |
| 98 | + returnType = ClassUtils.primitiveToWrapper(method.getReturnType()); |
| 99 | + } |
| 100 | + |
| 101 | + if (returnType.isInstance(result)) { |
| 102 | + return result; |
| 103 | + } |
| 104 | + |
97 | 105 | throw new ClassCastException(String.format("%s as %s", result.getClass().getName(), method.getReturnType().getName())); |
98 | 106 | } |
99 | 107 | })); |
|
0 commit comments