Changeset 11275 in josm for trunk/test/unit


Ignore:
Timestamp:
2016-11-17T22:32:04+01:00 (8 years ago)
Author:
Don-vip
Message:

see #10387 - fix unit test

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/actions/CreateCircleActionTest.java

    r11267 r11275  
    55import static org.junit.Assert.assertTrue;
    66
    7 import java.awt.geom.Area;
    87import java.lang.reflect.Field;
    98import java.lang.reflect.Method;
    10 import java.util.ArrayList;
    119import java.util.Arrays;
    1210import java.util.Collection;
     
    4341    @Rule
    4442    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    45     public JOSMTestRules test = new JOSMTestRules().platform();
     43    public JOSMTestRules test = new JOSMTestRules().platform().projection().commands();
    4644
    4745    /**
     
    152150
    153151        // Mock left/right hand traffic database
    154         Field leftHandTrafficPolygons = RightAndLefthandTraffic.class
    155             .getDeclaredField("leftHandTrafficPolygons");
    156152        Field rlCache = RightAndLefthandTraffic.class.getDeclaredField("rlCache");
    157         Utils.setObjectsAccessible(leftHandTrafficPolygons, rlCache);
    158         leftHandTrafficPolygons.set(null, new ArrayList<Area>());
     153        Utils.setObjectsAccessible(rlCache);
     154        Object origRlCache = rlCache.get(null);
    159155        rlCache.set(null, new GeoPropertyIndex<>(new ConstantTrafficHand(true), 24));
    160156
    161         CreateCircleAction action = new CreateCircleAction();
    162         action.setEnabled(true);
    163157        try {
    164             Main.getLayerManager().addLayer(layer);
    165             action.actionPerformed(null);
     158            CreateCircleAction action = new CreateCircleAction();
     159            action.setEnabled(true);
     160            try {
     161                Main.getLayerManager().addLayer(layer);
     162                action.actionPerformed(null);
     163            } finally {
     164                // Ensure we clean the place before leaving, even if test fails.
     165                Main.getLayerManager().removeLayer(layer);
     166            }
     167
     168            // Expected result: Dataset contain one closed way, clockwise
     169            Collection<Way> resultingWays = dataSet.getWays();
     170            assertSame(String.format("Expect one way after perform action. %d found", resultingWays.size()),
     171                       resultingWays.size(), 1);
     172            Way resultingWay = resultingWays.iterator().next();
     173            assertTrue("Resulting way is not closed",
     174                       resultingWay.isClosed());
     175            assertTrue("Found anti-clockwise way while traffic is left hand.",
     176                       Geometry.isClockwise(resultingWay));
    166177        } finally {
    167             // Ensure we clean the place before leaving, even if test fails.
    168             Main.getLayerManager().removeLayer(layer);
     178            // Restore left/right hand traffic database
     179            rlCache.set(null, origRlCache);
    169180        }
    170 
    171         // Expected result: Dataset contain one closed way, clockwise
    172         Collection<Way> resultingWays = dataSet.getWays();
    173         assertSame(String.format("Expect one way after perform action. %d found", resultingWays.size()),
    174                    resultingWays.size(), 1);
    175         Way resultingWay = resultingWays.iterator().next();
    176         assertTrue("Resulting way is not closed",
    177                    resultingWay.isClosed());
    178         assertTrue("Found anti-clockwise way while traffic is left hand.",
    179                    Geometry.isClockwise(resultingWay));
    180181    }
    181182}
Note: See TracChangeset for help on using the changeset viewer.