package com.airhacks.stateful.machine.boundary;

import com.airhacks.stateful.machine.boundary.StateManager;
import com.airhacks.stateful.machine.control.DefinitionStore;
import java.io.IOException;
import javax.json.JsonArray;
import javax.json.JsonObject;
import javax.xml.stream.XMLStreamException;
import org.apache.commons.scxml2.SCXMLExecutor;
import org.apache.commons.scxml2.io.SCXMLReader;
import org.apache.commons.scxml2.model.ModelException;
import org.apache.commons.scxml2.model.SCXML;
import org.junit.Before;
import org.junit.Test;

/**
 *
 * @author airhacks.com
 */
public class StateManagerTest {

    DefinitionStore ds;
    StateManager cut;

    @Before
    public void init() {
        this.ds = new DefinitionStore();
        this.ds.init();
        this.cut = new StateManager();
        this.cut.store = this.ds;
    }

    @Test
    public void trigger() throws IOException, ModelException, XMLStreamException {
        String stateMachineId = "test";
        SCXML scxml = SCXMLReader.read(this.getClass().getResourceAsStream("/state.xml"));
        SCXMLExecutor executor = new SCXMLExecutor();
        executor.setStateMachine(scxml);
        executor.go();
        this.ds.store(stateMachineId, executor);
        String event = "login";
        JsonObject result = this.cut.trigger(stateMachineId, event);
        System.out.println("result = " + result);
        JsonArray results = result.getJsonArray("current-state");
    }

}

@@ -75,35 +75,31 @@
 ful.
-machine.boundary.StateManag
+TestSCXMLExecutorProvid
 er;%0A
@@ -164,36 +164,8 @@
 re;%0A
-import java.io.IOException;%0A
 impo
@@ -223,52 +223,8 @@
 ct;%0A
-import javax.xml.stream.XMLStreamException;%0A
 impo
@@ -282,193 +282,123 @@
 org.
-apache.commons.scxml2.io.SCXMLReader;%0Aimport org.apache.commons.scxml2.model.ModelException;%0Aimport org.apache.commons.scxml2.model.SCXML;%0Aimport org.junit.Before;%0Aimport org.junit.Test
+junit.Before;%0Aimport org.junit.Test;%0Aimport static org.mockito.Mockito.mock;%0Aimport static org.mockito.Mockito.when
 ;%0A%0A/
@@ -472,48 +472,64 @@
     
-DefinitionStore ds;%0A    StateManager cut
+private StateManager cut;%0A    private DefinitionStore ds
 ;%0A%0A 
@@ -582,20 +582,21 @@
 is.ds = 
-new 
+mock(
 Definiti
@@ -606,33 +606,14 @@
 tore
-();%0A        this.ds.init(
+.class
 );%0A 
@@ -738,46 +738,8 @@
 ows 
-IOException, ModelException, XMLStream
 Exce
@@ -790,99 +790,8 @@
 t%22;%0A
-        SCXML scxml = SCXMLReader.read(this.getClass().getResourceAsStream(%22/state.xml%22));%0A
     
@@ -819,20 +819,20 @@
 cutor = 
-new 
+Test
 SCXMLExe
@@ -840,92 +840,48 @@
 utor
-();%0A        executor.setStateMachine(scxml);%0A        executor.go();%0A        
+Provider.create();%0A        when(
 this.ds.
 stor
@@ -876,21 +876,20 @@
 this.ds.
-store
+find
 (stateMa
@@ -895,18 +895,30 @@
 achineId
-, 
+)).thenReturn(
 executor

Test fixed