Skip to content

Commit a2f8863

Browse files
committed
Test for strong types
Signed-off-by: fjtirado <ftirados@redhat.com>
1 parent 20d2789 commit a2f8863

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

experimental/lambda/src/main/java/io/serverlessworkflow/impl/expressions/func/JavaExpressionFactory.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ public WorkflowFilter buildFilter(String expr, Object value) {
5555
if (value instanceof Function func) {
5656
return (w, t, n) -> modelFactory.fromAny(func.apply(n.asJavaObject()));
5757
} else if (value instanceof TypedFunction func) {
58-
return (w, t, n) -> modelFactory.fromAny(func.function().apply(n.as(func.argClass())));
58+
return (w, t, n) ->
59+
modelFactory.fromAny(func.function().apply(n.as(func.argClass()).orElseThrow()));
5960
} else if (value instanceof Predicate pred) {
6061
return fromPredicate(pred);
6162
} else if (value instanceof TypedPredicate pred) {
@@ -78,7 +79,7 @@ private WorkflowFilter fromPredicate(Predicate pred) {
7879

7980
@SuppressWarnings({"rawtypes", "unchecked"})
8081
private WorkflowFilter fromPredicate(TypedPredicate pred) {
81-
return (w, t, n) -> modelFactory.from(pred.pred().test(n.as(pred.argClass())));
82+
return (w, t, n) -> modelFactory.from(pred.pred().test(n.as(pred.argClass()).orElseThrow()));
8283
}
8384

8485
@Override

experimental/lambda/src/main/java/io/serverlessworkflow/impl/expressions/func/JavaModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public Class<?> objectClass() {
113113

114114
@Override
115115
public <T> Optional<T> as(Class<T> clazz) {
116-
return object != null && object.getClass().isAssignableFrom(clazz)
116+
return object != null && clazz.isAssignableFrom(object.getClass())
117117
? Optional.of(clazz.cast(object))
118118
: Optional.empty();
119119
}

experimental/lambda/src/test/java/io/serverless/workflow/impl/CallTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ void testJavaFunction() throws InterruptedException, ExecutionException {
5555
"javaCall",
5656
new Task()
5757
.withCallTask(
58-
new CallTaskJava(CallJava.function(JavaFunctions::getName))))));
58+
new CallTaskJava(
59+
CallJava.function(JavaFunctions::getName, Person.class))))));
5960

6061
assertThat(
6162
app.workflowDefinition(workflow)
@@ -84,7 +85,7 @@ void testForLoop() throws InterruptedException, ExecutionException {
8485
.withForTask(
8586
new ForTaskFunction()
8687
.withWhile(CallTest::isEven)
87-
.withCollection(v -> (Collection) v)
88+
.withCollection(v -> v, Collection.class)
8889
.withFor(forConfig)
8990
.withDo(
9091
List.of(
@@ -127,7 +128,7 @@ void testSwitch() throws InterruptedException, ExecutionException {
127128
new SwitchItem(
128129
"odd",
129130
new SwitchCaseFunction()
130-
.withPredicate(CallTest::isOdd)
131+
.withPredicate(CallTest::isOdd, Integer.class)
131132
.withThen(
132133
new FlowDirective()
133134
.withFlowDirectiveEnum(

0 commit comments

Comments
 (0)