package org.graphwalker.core.machine;

import org.graphwalker.core.condition.VertexCoverage;
import org.graphwalker.core.generator.ShortestAllPaths;
import org.graphwalker.core.model.Action;
import org.graphwalker.core.model.Edge;
import org.graphwalker.core.model.Model;
import org.graphwalker.core.model.Vertex;
import org.junit.Assert;
import org.junit.Test;

import static org.hamcrest.core.Is.is;

/**
 * @author Nils Olsson
 */
public class AccessModelTest {

    @Test
    public void read() {
        ExecutionContext context = createContext();
        Assert.assertThat((Double)context.getAttribute("x"), is(1.0));
    }

    @Test
    public void write() {
        ExecutionContext context = createContext();
        context.setAttribute("y", 2);
        Assert.assertThat((Integer)context.getAttribute("y"), is(2));
    }

    private ExecutionContext createContext() {
        Model model = new Model();
        model.addEdge(new Edge()
                .setSourceVertex(new Vertex())
                .setTargetVertex(new Vertex()));
        ExecutionContext context = new TestExecutionContext(model, new ShortestAllPaths(new VertexCoverage(100)));
        context.execute(new Action("x = 1;"));
        return context;
    }
}

@@ -576,16 +576,14 @@
 hat(
-(Double)
+round(
 cont
@@ -607,19 +607,218 @@
 %22x%22)
+)
 , is(1
-.0
 ));
+%0A    %7D%0A%0A    private int round(Object value) %7B%0A        if (value instanceof Double) %7B%0A            return (int) Math.round((Double) value);%0A        %7D else %7B%0A            return (Integer) value;%0A        %7D
 %0A   

Fix test issue with different jdk (javascript engines)