package de.bmoth.ltl;

import static de.bmoth.TestConstants.MACHINE_NAME;
import static org.junit.Assert.*;

import java.util.ArrayList;

import org.junit.Test;

import de.bmoth.parser.Parser;
import de.bmoth.parser.ParserException;
import de.bmoth.parser.ast.nodes.MachineNode;
import de.bmoth.parser.ast.nodes.ltl.LTLFormula;

public class LTLMachineTest {

    @Test
    public void testSimpleLTLTestMachine() {
        String machine = MACHINE_NAME;
        machine += "DEFINITIONS ASSERT_LTL_1 == \"F({x=7})\"  ";
        machine += "VARIABLES x \n";
        machine += "INVARIANT x : 1..10 \n";
        machine += "INITIALISATION x := 1\n";
        machine += "OPERATIONS foo = SELECT x < 5 THEN x := x + 1 END\n";
        machine += "END";
        MachineNode machineAST = getMachineAST(machine);
        ArrayList<LTLFormula> ltlFormulas = machineAST.getLTLFormulas();
        LTLFormula ltl1 = ltlFormulas.get(0);
        assertEquals("ASSERT_LTL_1", ltl1.getName());
        System.out.println(ltl1.getLTLNode());
    }

    private MachineNode getMachineAST(String machine) {
        try {
            return Parser.getMachineAsSemanticAst(machine);
        } catch (ParserException e) {
            e.printStackTrace();
            fail(e.getMessage());
            return null;
        }
    }
}

@@ -27,65 +27,130 @@
 ort 
-static de.bmoth.TestConstants.MACHINE_NAME;%0Aimport static
+de.bmoth.TestParser;%0Aimport de.bmoth.parser.ast.nodes.MachineNode;%0Aimport de.bmoth.parser.ast.nodes.ltl.LTLFormula;%0Aimport
  org
@@ -160,16 +160,12 @@
 nit.
-Assert.*
+Test
 ;%0A%0Ai
@@ -180,21 +180,16 @@
 va.util.
-Array
 List;%0A%0Ai
@@ -186,32 +186,39 @@
 l.List;%0A%0Aimport 
+static 
 org.junit.Test;%0A
@@ -215,179 +215,110 @@
 nit.
-Test;%0A%0Aimport de.bmoth.parser.Parser;%0Aimport de.bmoth.parser.ParserException;%0Aimport de.bmoth.par
+Assert.assertEquals;%0Aimport static org.junit.As
 ser
+t
 .as
-t.nodes.MachineNode;%0Aimport de.bmoth.parser.ast.nodes.ltl.LTLFormula
+sertNotNull;%0Aimport static org.junit.Assert.fail
 ;%0A%0Ap
@@ -344,16 +344,35 @@
 ineTest 
+extends TestParser 
 %7B%0A%0A    @
@@ -433,71 +433,125 @@
     
-String machine = MACHINE_NAME;%0A        machine += %22DEFINITIONS 
+MachineNode machine = new MachineBuilder()%0A            .setName(%22SimpleLTLTestMachine%22)%0A            .setDefinitions(%22
 ASSE
@@ -578,12 +578,10 @@
 %7D)%5C%22
-  %22;
+%22)
 %0A   
@@ -589,67 +589,58 @@
     
-machine += %22VARIABLES x %5Cn%22;%0A        machine += %22INVARIANT 
+    .setVariables(%22x%22)%0A            .setInvariant(%22
 x : 
@@ -648,13 +648,10 @@
 ..10
- %5Cn%22;
+%22)
 %0A   
@@ -659,45 +659,40 @@
     
-machine += %22INITIALISATION 
+    .setInitialization(%22
 x := 1
-%5Cn%22;
+%22)
 %0A   
@@ -700,31 +700,27 @@
     
-machine += %22OPERATIONS 
+    .addOperation(%22
 foo 
@@ -757,12 +757,10 @@
  END
-%5Cn%22;
+%22)
 %0A   
@@ -768,72 +768,44 @@
     
-machine += %22END%22;%0A        MachineNode machineAST = getMachineAST
+    .build();%0A%0A        assertNotNull
 (mac
@@ -823,13 +823,8 @@
     
-Array
 List
@@ -857,19 +857,16 @@
  machine
-AST
 .getLTLF
@@ -980,332 +980,8 @@
 ));%0A
-        System.out.println(ltl1.getLTLNode());%0A    %7D%0A%0A    private MachineNode getMachineAST(String machine) %7B%0A        try %7B%0A            return Parser.getMachineAsSemanticAst(machine);%0A        %7D catch (ParserException e) %7B%0A            e.printStackTrace();%0A            fail(e.getMessage());%0A            return null;%0A        %7D%0A
     

use TestParser and MachineBuilder assert non-null machine removed sysout