Skip to content

Commit 9aa2600

Browse files
committed
test: add support for primitive-typed RPC
1 parent c9d08a1 commit 9aa2600

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/test/java/com/flowingcode/vaadin/addons/chipfield/integration/rpc/HasRpcSupport.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.stream.Collectors;
3030
import java.util.stream.Stream;
3131

32+
import org.apache.commons.lang3.ClassUtils;
3233
import org.openqa.selenium.By;
3334
import org.openqa.selenium.JavascriptExecutor;
3435
import org.openqa.selenium.WebDriver;
@@ -84,16 +85,23 @@ default <T> T createCallableProxy(Class<T> intf) {
8485
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
8586
Object result = call(method.getName(), args);
8687

87-
if (result == null || method.getReturnType() == Void.TYPE) {
88+
Class<?> returnType = method.getReturnType();
89+
if (result == null || returnType == Void.TYPE) {
8890
return null;
8991
}
9092

91-
if (method.getReturnType() == JsonArrayList.class) {
93+
if (returnType == JsonArrayList.class) {
9294
return JsonArrayList.wrapForTestbench((List<?>) result);
9395
}
9496

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+
97105
throw new ClassCastException(String.format("%s as %s", result.getClass().getName(), method.getReturnType().getName()));
98106
}
99107
}));

0 commit comments

Comments
 (0)