Skip to content

Commit

Permalink
feat: test for add abstract chain action impl
Browse files Browse the repository at this point in the history
  • Loading branch information
wxasacoder committed Nov 11, 2024
1 parent 4d462cf commit e531d4c
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.alibaba.cola.statemachine.builder.StateMachineBuilder;
import com.alibaba.cola.statemachine.builder.StateMachineBuilderFactory;
import com.alibaba.cola.statemachine.exception.TransitionFailException;
import com.alibaba.cola.statemachine.impl.AbsChainAction;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -92,6 +93,38 @@ public void testVerify() {
Assertions.assertFalse(stateMachine.verify(States.STATE1, Events.EVENT2));
}

@Test
public void testChainAction(){
StateMachineBuilder<States, Events, Context> builder = StateMachineBuilderFactory.create();
builder.externalTransition()
.from(States.STATE1)
.to(States.STATE2)
.on(Events.EVENT1)
.when(checkCondition())
.perform(
new AbsChainAction<States, Events, Context>() {
@Override
protected void doExecute(States from, States to, Events event, Context context) {
System.out.println("first action to execute");
}
}.next(new AbsChainAction() {
@Override
protected void doExecute(Object from, Object to, Object event, Object context) {
System.out.println("second action to execute");
}
}.next(new AbsChainAction() {
@Override
protected void doExecute(Object from, Object to, Object event, Object context) {
System.out.println("third action to execute");
}
}))
)
;
builder.build("test-perform-chan-action").fireEvent(States.STATE1,Events.EVENT1,new Context());

}


@Test
public void testExternalTransitionsNormal() {
StateMachineBuilder<States, Events, Context> builder = StateMachineBuilderFactory.create();
Expand Down

0 comments on commit e531d4c

Please sign in to comment.