コード例 #1
0
  @Test
  public void testBreakAndContinue() throws Exception {
    State s1 = new State("s1");
    s1.addTransition(new BreakAndContinueTransition("foo"));
    s1.addTransition(new SuccessTransition("foo"));

    StateContext context = new DefaultStateContext();
    StateMachine sm = new StateMachine(new State[] {s1}, "s1");
    sm.handle(new Event("foo", context));
    assertEquals(true, context.getAttribute("success"));
  }
コード例 #2
0
  @Test
  public void testBreakAndGotoNext() throws Exception {
    State s1 = new State("s1");
    State s2 = new State("s2");
    s1.addTransition(new BreakAndGotoNextTransition("foo", "s2"));
    s2.addTransition(new SuccessTransition("foo"));

    StateContext context = new DefaultStateContext();
    StateMachine sm = new StateMachine(new State[] {s1, s2}, "s1");
    sm.handle(new Event("foo", context));
    assertSame(s2, context.getCurrentState());
    sm.handle(new Event("foo", context));
    assertEquals(true, context.getAttribute("success"));
  }
コード例 #3
0
  @Test
  public void testOnEntry() throws Exception {
    State s1 = new State("s1");
    State s2 = new State("s2");

    s1.addTransition(new SuccessTransition("foo", s2));
    s1.addOnExitSelfTransaction(new SampleSelfTransition());
    s2.addOnEntrySelfTransaction(new SampleSelfTransition());

    StateContext context = new DefaultStateContext();
    StateMachine sm = new StateMachine(new State[] {s1, s2}, "s1");
    sm.handle(new Event("foo", context));
    assertEquals(true, context.getAttribute("success"));
    assertEquals(true, context.getAttribute("SelfSuccess" + s1.getId()));
    assertEquals(true, context.getAttribute("SelfSuccess" + s2.getId()));
  }
コード例 #4
0
 @Override
 protected boolean doExecute(StateContext stateContext, State state) {
   stateContext.setAttribute("SelfSuccess" + state.getId(), true);
   return true;
 }