Skip to content

Test for strong types #684

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

Merged
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 @@ -55,7 +55,8 @@ public WorkflowFilter buildFilter(String expr, Object value) {
if (value instanceof Function func) {
return (w, t, n) -> modelFactory.fromAny(func.apply(n.asJavaObject()));
} else if (value instanceof TypedFunction func) {
return (w, t, n) -> modelFactory.fromAny(func.function().apply(n.as(func.argClass())));
return (w, t, n) ->
modelFactory.fromAny(func.function().apply(n.as(func.argClass()).orElseThrow()));
} else if (value instanceof Predicate pred) {
return fromPredicate(pred);
} else if (value instanceof TypedPredicate pred) {
Expand All @@ -78,7 +79,7 @@ private WorkflowFilter fromPredicate(Predicate pred) {

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public Class<?> objectClass() {

@Override
public <T> Optional<T> as(Class<T> clazz) {
return object != null && object.getClass().isAssignableFrom(clazz)
return object != null && clazz.isAssignableFrom(object.getClass())
? Optional.of(clazz.cast(object))
: Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ void testJavaFunction() throws InterruptedException, ExecutionException {
"javaCall",
new Task()
.withCallTask(
new CallTaskJava(CallJava.function(JavaFunctions::getName))))));
new CallTaskJava(
CallJava.function(JavaFunctions::getName, Person.class))))));

assertThat(
app.workflowDefinition(workflow)
Expand Down Expand Up @@ -84,7 +85,7 @@ void testForLoop() throws InterruptedException, ExecutionException {
.withForTask(
new ForTaskFunction()
.withWhile(CallTest::isEven)
.withCollection(v -> (Collection) v)
.withCollection(v -> v, Collection.class)
.withFor(forConfig)
.withDo(
List.of(
Expand Down Expand Up @@ -127,7 +128,7 @@ void testSwitch() throws InterruptedException, ExecutionException {
new SwitchItem(
"odd",
new SwitchCaseFunction()
.withPredicate(CallTest::isOdd)
.withPredicate(CallTest::isOdd, Integer.class)
.withThen(
new FlowDirective()
.withFlowDirectiveEnum(
Expand Down
Loading