package pipe.views.builder;

import org.junit.Before;
import org.junit.Test;
import pipe.models.Transition;
import pipe.views.TransitionView;

import static org.junit.Assert.assertEquals;

public class TransitionViewBuilderTest {
    private static final double DOUBLE_DELTA = 0.001;
    Transition transition;
    TransitionViewBuilder builder;

    @Before
    public void setUp()
    {
        transition = new Transition("id", "name");
        builder = new TransitionViewBuilder(transition);
    }

    @Test
    public void correctlySetsModel()
    {
        TransitionView transitionView = builder.build();
        assertEquals(transition, transitionView.getModel());
    }

    @Test
    public void correctlySetsViewAttributes()
    {
        TransitionView transitionView = builder.build();
        transition.setX(200);
        assertEquals(transition.getX(), transitionView.getX(), DOUBLE_DELTA);
        assertEquals(transition.getY(), transitionView.getY(), DOUBLE_DELTA);
        assertEquals(transition.getId(), transitionView.getId());
        assertEquals(transition.getName(), transitionView.getName());
        assertEquals(transition.getNameXOffset(), transitionView._nameLabel.getX() - transition.getX(), DOUBLE_DELTA);
        assertEquals(transition.getNameYOffset(), transitionView._nameLabel.getY()- transition.getY(), DOUBLE_DELTA);
        assertEquals(transition.getAngle(), transitionView.getAngle());
        assertEquals(transition.isTimed(), transitionView.isTimed());
        assertEquals(transition.isInfiniteServer(), transitionView.isInfiniteServer());
    }

}

@@ -119,30 +119,123 @@
 e.views.
-TransitionView
+PetriNetView;%0Aimport pipe.views.PetriNetViewComponent;%0Aimport pipe.views.TransitionView;%0A%0Aimport java.awt.*
 ;%0A%0Aimpor
@@ -822,32 +822,62 @@
 ributes()%0A    %7B%0A
+        transition.setX(200);%0A
         Transiti
@@ -917,24 +917,25 @@
 uild();%0A
+%0A
         
 transiti
@@ -930,51 +930,197 @@
     
-transition.setX(200);%0A        assertEquals(
+//TODO: SHOULDNT REALLY USE HEIGHT x HEIGHT ITS CONFUSING, its because the transition is actually a square%0A        // element only partly drawn.%0A        Rectangle rect = new Rectangle((int)
 tran
@@ -1130,24 +1130,29 @@
 ion.getX(), 
+(int)
 transitionVi
@@ -1153,44 +1153,75 @@
 tion
-View.getX(), DOUBLE_DELTA
+.getY(), transition.getHeight(), transition.getHeight()
 );%0A
+%0A
         
 asse
@@ -1220,75 +1220,117 @@
     
-assertEquals(transition.getY(), transitionView.getY(), DOUBLE_DELTA
+//This - 5 comes from updating the bounds. Its a variable set in PetriNetViewComponent%0A        rect.grow(5, 5
 );%0A 
@@ -1353,24 +1353,17 @@
 als(
-transition
+rect
 .get
-Id
+X
 (), 
@@ -1384,12 +1384,25 @@
 .get
-Id()
+X(), DOUBLE_DELTA
 );%0A 
@@ -1421,34 +1421,25 @@
 tEquals(
-transition.getName
+rect.getY
 (), tran
@@ -1456,14 +1456,25 @@
 .get
-Name()
+Y(), DOUBLE_DELTA
 );%0A 
@@ -1511,19 +1511,10 @@
 .get
-NameXOffset
+Id
 (), 
@@ -1532,59 +1532,15 @@
 iew.
-_nameLabel.getX() - transition.getX(), DOUBLE_DELTA
+getId()
 );%0A 
@@ -1581,15 +1581,8 @@
 Name
-YOffset
 (), 
@@ -1600,58 +1600,17 @@
 iew.
-_nameLabel.getY()- transition.getY(), DOUBLE_DELTA
+getName()
 );%0A 

Fix TransitionViewBuilderTest