Changeset 7081 in josm for trunk/test/unit


Ignore:
Timestamp:
2014-05-09T04:49:54+02:00 (10 years ago)
Author:
Don-vip
Message:

fixes for unit tests

Location:
trunk/test/unit/org/openstreetmap/josm
Files:
41 edited

Legend:

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

    r7068 r7081  
    5454
    5555        Main.pref.init(false);
     56        I18n.set(Main.pref.get("language", "en"));
    5657
    5758        // init projection
  • trunk/test/unit/org/openstreetmap/josm/actions/CreateMultipolygonActionTest.groovy

    r7068 r7081  
    11package org.openstreetmap.josm.actions
    22
    3 import org.openstreetmap.josm.Main
    4 import org.openstreetmap.josm.TestUtils;
     3import org.junit.BeforeClass
     4import org.junit.Test
     5import org.openstreetmap.josm.JOSMFixture
     6import org.openstreetmap.josm.TestUtils
    57import org.openstreetmap.josm.actions.search.SearchCompiler
    68import org.openstreetmap.josm.data.osm.Relation
    79import org.openstreetmap.josm.data.osm.Way
    8 import org.openstreetmap.josm.data.projection.Projections
    910import org.openstreetmap.josm.io.OsmReader
    1011import org.openstreetmap.josm.tools.Utils
    1112
    12 class CreateMultipolygonActionTest extends GroovyTestCase {
     13class CreateMultipolygonActionTest {
    1314
    14     @Override
    15     void setUp() {
    16         Main.initApplicationPreferences()
    17         Main.setProjection(Projections.getProjectionByCode("EPSG:3857"));
     15    @BeforeClass
     16    public static void setUp() {
     17        JOSMFixture.createUnitTestFixture().init();
    1818    }
    1919
     
    2626    }
    2727
    28     void testCreate1() {
     28    @Test
     29    public void testCreate1() {
    2930        def ds = OsmReader.parseDataSet(new FileInputStream(TestUtils.getTestDataRoot() + "create_multipolygon.osm"), null);
    3031        def mp = CreateMultipolygonAction.createMultipolygonCommand(ds.getWays(), null)
     
    3334    }
    3435
    35     void testCreate2() {
     36    @Test
     37    public void testCreate2() {
    3638        def ds = OsmReader.parseDataSet(new FileInputStream(TestUtils.getTestDataRoot() + "create_multipolygon.osm"), null);
    3739        def ways = Utils.filter(ds.getWays(), SearchCompiler.compile("ref=1 OR ref:1.1.", false, false))
     
    4042    }
    4143
    42     void testUpdate1() {
     44    @Test
     45    public void testUpdate1() {
    4346        def ds = OsmReader.parseDataSet(new FileInputStream(TestUtils.getTestDataRoot() + "create_multipolygon.osm"), null);
    4447        def ways = Utils.filter(ds.getWays(), SearchCompiler.compile("ref=\".*1\$\"", false, true))
     
    5255    }
    5356
    54     void testUpdate2() {
     57    @Test
     58    public void testUpdate2() {
    5559        def ds = OsmReader.parseDataSet(new FileInputStream(TestUtils.getTestDataRoot() + "create_multipolygon.osm"), null);
    5660        def ways = Utils.filter(ds.getWays(), SearchCompiler.compile("ref=1 OR ref:1.1.1", false, false))
  • trunk/test/unit/org/openstreetmap/josm/actions/search/SearchCompilerTest.java

    r6881 r7081  
    44import org.junit.Before;
    55import org.junit.Test;
    6 import org.openstreetmap.josm.Main;
     6import org.openstreetmap.josm.JOSMFixture;
    77import org.openstreetmap.josm.data.osm.Node;
    88import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    1515    @Before
    1616    public void setUp() {
    17         Main.initApplicationPreferences();
     17        JOSMFixture.createUnitTestFixture().init();
    1818    }
    1919
  • trunk/test/unit/org/openstreetmap/josm/corrector/ReverseWayTagCorrectorTest.java

    r6881 r7081  
    55import org.junit.BeforeClass;
    66import org.junit.Test;
    7 import org.openstreetmap.josm.Main;
     7import org.openstreetmap.josm.JOSMFixture;
    88import org.openstreetmap.josm.data.osm.Tag;
    99
     
    1818    @BeforeClass
    1919    public static void setUp() {
    20         Main.initApplicationPreferences();
     20        JOSMFixture.createUnitTestFixture().init();
    2121    }
    2222
  • trunk/test/unit/org/openstreetmap/josm/data/PreferencesTest.groovy

    r6774 r7081  
    11package org.openstreetmap.josm.data
    22
     3import java.awt.Color
     4
     5import org.openstreetmap.josm.JOSMFixture
    36import org.openstreetmap.josm.Main
    4 
    5 import java.awt.Color
    67
    78class PreferencesTest extends GroovyTestCase {
    89    @Override
    910    void setUp() {
    10         Main.initApplicationPreferences()
     11        JOSMFixture.createUnitTestFixture().init();
    1112    }
    1213
  • trunk/test/unit/org/openstreetmap/josm/data/osm/APIDataSetTest.java

    r6881 r7081  
    99import org.junit.BeforeClass;
    1010import org.junit.Test;
    11 import org.openstreetmap.josm.Main;
     11import org.openstreetmap.josm.JOSMFixture;
    1212import org.openstreetmap.josm.actions.upload.CyclicUploadDependencyException;
    1313import org.openstreetmap.josm.data.APIDataSet;
     
    1717    @BeforeClass
    1818    public static void init() {
    19         Main.initApplicationPreferences();
     19        JOSMFixture.createUnitTestFixture().init();
    2020    }
    2121
  • trunk/test/unit/org/openstreetmap/josm/data/osm/DataSetMergerTest.java

    r6881 r7081  
    1717import org.junit.BeforeClass;
    1818import org.junit.Test;
     19import org.openstreetmap.josm.JOSMFixture;
    1920import org.openstreetmap.josm.Main;
    2021import org.openstreetmap.josm.data.coor.LatLon;
     
    2526    @BeforeClass
    2627    public static void init() {
    27         Main.initApplicationPreferences();
     28        JOSMFixture.createUnitTestFixture().init();
    2829    }
    2930
  • trunk/test/unit/org/openstreetmap/josm/data/osm/FilterTest.java

    r7033 r7081  
    1515import org.junit.BeforeClass;
    1616import org.junit.Test;
    17 import org.openstreetmap.josm.Main;
     17import org.openstreetmap.josm.JOSMFixture;
    1818import org.openstreetmap.josm.actions.search.SearchAction.SearchMode;
    1919import org.openstreetmap.josm.actions.search.SearchCompiler.ParseError;
    2020import org.openstreetmap.josm.data.coor.LatLon;
    21 import org.openstreetmap.josm.data.projection.Projections;
    2221import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    2322import org.openstreetmap.josm.io.IllegalDataException;
     
    3130    @BeforeClass
    3231    public static void setUp() {
    33         Main.setProjection(Projections.getProjectionByCode("EPSG:3857")); // Mercator
    34         Main.initApplicationPreferences();
     32        JOSMFixture.createUnitTestFixture().init();
    3533    }
    3634
  • trunk/test/unit/org/openstreetmap/josm/data/osm/OsmPrimitiveKeyHandlingTest.java

    r7063 r7081  
    66import org.junit.BeforeClass;
    77import org.junit.Test;
    8 import org.openstreetmap.josm.Main;
     8import org.openstreetmap.josm.JOSMFixture;
    99import org.openstreetmap.josm.data.coor.LatLon;
    1010
     
    1818    @BeforeClass
    1919    public static void init() {
    20         Main.initApplicationPreferences();
     20        JOSMFixture.createUnitTestFixture().init();
    2121    }
    2222
  • trunk/test/unit/org/openstreetmap/josm/data/osm/OsmPrimitiveTest.java

    r7005 r7081  
    88import org.junit.BeforeClass;
    99import org.junit.Test;
     10import org.openstreetmap.josm.JOSMFixture;
    1011import org.openstreetmap.josm.Main;
    1112import org.openstreetmap.josm.data.coor.LatLon;
     
    1617    @BeforeClass
    1718    public static void init() {
    18         Main.initApplicationPreferences();
     19        JOSMFixture.createUnitTestFixture().init();
    1920    }
    2021
  • trunk/test/unit/org/openstreetmap/josm/data/osm/QuadBucketsTest.java

    r7033 r7081  
    1414import org.junit.BeforeClass;
    1515import org.junit.Test;
     16import org.openstreetmap.josm.JOSMFixture;
    1617import org.openstreetmap.josm.Main;
    1718import org.openstreetmap.josm.data.coor.LatLon;
     
    2425    @BeforeClass
    2526    public static void init() {
    26         Main.initApplicationPreferences();
     27        JOSMFixture.createUnitTestFixture().init();
    2728    }
    2829
     
    7879        try (InputStream fis = new FileInputStream("data_nodist/restriction.osm")) {
    7980            DataSet ds = OsmReader.parseDataSet(fis, NullProgressMonitor.INSTANCE);
    80    
     81
    8182            for (Node n: ds.getNodes()) {
    8283                n.setCoor(new LatLon(10, 10));
    8384            }
    84    
     85
    8586            removeAllTest(ds);
    8687        }
  • trunk/test/unit/org/openstreetmap/josm/data/osm/RelationTest.java

    r6881 r7081  
    77import org.junit.BeforeClass;
    88import org.junit.Test;
    9 import org.openstreetmap.josm.Main;
     9import org.openstreetmap.josm.JOSMFixture;
    1010import org.openstreetmap.josm.data.coor.LatLon;
    11 import org.openstreetmap.josm.data.projection.Projections;
    1211
    1312public class RelationTest {
     
    1817    @BeforeClass
    1918    public static void setUp() {
    20         Main.setProjection(Projections.getProjectionByCode("EPSG:3857")); // Mercator
    21         Main.initApplicationPreferences();
     19        JOSMFixture.createUnitTestFixture().init();
    2220    }
    2321
  • trunk/test/unit/org/openstreetmap/josm/data/osm/visitor/MergeSourceBuildingVisitorTest.java

    r6881 r7081  
    1111import org.junit.BeforeClass;
    1212import org.junit.Test;
    13 import org.openstreetmap.josm.Main;
     13import org.openstreetmap.josm.JOSMFixture;
    1414import org.openstreetmap.josm.data.coor.LatLon;
    1515import org.openstreetmap.josm.data.osm.DataSet;
     
    2020import org.openstreetmap.josm.data.osm.RelationMember;
    2121import org.openstreetmap.josm.data.osm.Way;
    22 import org.openstreetmap.josm.data.projection.Projections;
    2322
    2423public class MergeSourceBuildingVisitorTest {
     
    3938    @BeforeClass
    4039    public static void setUp() {
    41         Main.setProjection(Projections.getProjectionByCode("EPSG:3857")); // Mercator
    42         Main.initApplicationPreferences();
    43     }
    44 
    45     @Test
    46     public void test_Nodes() {
     40        JOSMFixture.createUnitTestFixture().init();
     41    }
     42
     43    @Test
     44    public void testNodes() {
    4745        DataSet source = new DataSet();
    4846        Node n1 = new Node(1);
     
    7977
    8078    @Test
    81     public void test_OneWay() {
     79    public void testOneWay() {
    8280        DataSet source = new DataSet();
    8381        Node n1 = new Node(1);
     
    111109
    112110    @Test
    113     public void test_OneWay_NodesSelectedToo() {
     111    public void testOneWayNodesSelectedToo() {
    114112        DataSet source = new DataSet();
    115113        Node n1 = new Node(1);
     
    143141
    144142    @Test
    145     public void test_OneWay_Incomplete() {
     143    public void testOneWayIncomplete() {
    146144        DataSet source = new DataSet();
    147145        Way w1 = new Way(3);
     
    161159
    162160    @Test
    163     public void test_OneRelation_ExistingMembersSelected() {
     161    public void testOneRelationExistingMembersSelected() {
    164162        DataSet source = new DataSet();
    165163        Relation r1 = new Relation(1, 1);
     
    220218
    221219    @Test
    222     public void test_OneRelation_ExistingMembersNotSelected() {
     220    public void testOneRelationExistingMembersNotSelected() {
    223221        DataSet source = new DataSet();
    224222        Relation r1 = new Relation(1, 1);
     
    279277
    280278    @Test
    281     public void test_OneRelation_NewMembersNotSelected() {
     279    public void testOneRelationNewMembersNotSelected() {
    282280        DataSet source = new DataSet();
    283281        Relation r1 = new Relation();
     
    346344
    347345    @Test
    348     public void test_OneRelation_Existing_Recursive() {
     346    public void testOneRelationExistingRecursive() {
    349347        DataSet source = new DataSet();
    350348        Relation r1 = new Relation(1, 1);
     
    365363
    366364    @Test
    367     public void test_OneRelation_New_Recursive() {
     365    public void testOneRelationNewRecursive() {
    368366        DataSet source = new DataSet();
    369367        Relation r1 = new Relation();
     
    385383
    386384    @Test
    387     public void test_TwoRelation_Existing_Circular() {
     385    public void testTwoRelationExistingCircular() {
    388386        DataSet source = new DataSet();
    389387        Relation r1 = new Relation(1, 1);
  • trunk/test/unit/org/openstreetmap/josm/data/projection/ProjectionRegressionTest.java

    r7030 r7081  
    2323import org.junit.BeforeClass;
    2424import org.junit.Test;
    25 import org.openstreetmap.josm.Main;
     25import org.openstreetmap.josm.JOSMFixture;
    2626import org.openstreetmap.josm.data.Bounds;
    2727import org.openstreetmap.josm.data.coor.EastNorth;
     
    120120                }
    121121                TestData next = new TestData();
    122    
     122
    123123                Pair<Double,Double> ll = readLine("ll", in.readLine());
    124124                Pair<Double,Double> en = readLine("en", in.readLine());
    125125                Pair<Double,Double> ll2 = readLine("ll2", in.readLine());
    126    
     126
    127127                next.code = line;
    128128                next.ll = new LatLon(ll.a, ll.b);
    129129                next.en = new EastNorth(en.a, en.b);
    130130                next.ll2 = new LatLon(ll2.a, ll2.b);
    131    
     131
    132132                result.add(next);
    133133            }
     
    150150    @BeforeClass
    151151    public static void setUp() {
    152         Main.initApplicationPreferences();
     152        JOSMFixture.createUnitTestFixture().init();
    153153    }
    154154
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/ConditionalKeysTest.groovy

    r6605 r7081  
    22package org.openstreetmap.josm.data.validation.tests
    33
    4 import org.openstreetmap.josm.Main
     4import org.openstreetmap.josm.JOSMFixture
    55import org.openstreetmap.josm.gui.preferences.map.TaggingPresetPreference
    66
    77class ConditionalKeysTest extends GroovyTestCase {
    88
    9     def test = new ConditionalKeys()
     9    ConditionalKeys test = new ConditionalKeys()
    1010
    1111    @Override
    1212    void setUp() {
    13         Main.initApplicationPreferences();
     13        JOSMFixture.createUnitTestFixture().init();
    1414        TaggingPresetPreference.readFromPreferences()
    1515        test.initialize()
     
    4040        assert !test.isValueValid("motor_vehicle:conditional", "no @ (10:00until18:00 AND length>5)")
    4141        assert test.isValueValid("maxspeed:hgv:conditional", "60 @ (weight>7.5)")
    42 
    4342    }
    4443}
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/DuplicateNodeTest.java

    r6881 r7081  
    66import org.junit.BeforeClass;
    77import org.junit.Test;
    8 import org.openstreetmap.josm.Main;
     8import org.openstreetmap.josm.JOSMFixture;
    99import org.openstreetmap.josm.data.coor.LatLon;
    1010import org.openstreetmap.josm.data.osm.DataSet;
    1111import org.openstreetmap.josm.data.osm.Node;
    12 import org.openstreetmap.josm.data.projection.Projections;
    1312import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    1413
     
    2322    @BeforeClass
    2423    public static void setUp() {
    25         Main.setProjection(Projections.getProjectionByCode("EPSG:3857")); // Mercator
    26         Main.initApplicationPreferences();
     24        JOSMFixture.createUnitTestFixture().init();
    2725    }
    2826
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/HighwaysTest.groovy

    r6573 r7081  
    22package org.openstreetmap.josm.data.validation.tests
    33
    4 import org.openstreetmap.josm.Main
     4import org.openstreetmap.josm.JOSMFixture
    55import org.openstreetmap.josm.data.coor.LatLon
    66import org.openstreetmap.josm.data.osm.DataSet
    77import org.openstreetmap.josm.data.osm.Way
    8 import org.openstreetmap.josm.data.projection.Projections
    98
    109class HighwaysTest extends GroovyTestCase {
     
    1211    @Override
    1312    void setUp() {
    14         Main.initApplicationPreferences()
    15         Main.setProjection(Projections.getProjectionByCode("EPSG:3857"));
     13        JOSMFixture.createUnitTestFixture().init();
    1614    }
    1715
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/LanesTest.groovy

    r7068 r7081  
    11package org.openstreetmap.josm.data.validation.tests
    22
    3 import org.openstreetmap.josm.TestUtils;
     3import org.openstreetmap.josm.TestUtils
    44
    55class LanesTest extends GroovyTestCase {
    66
    7     def lanes = new Lanes()
     7    Lanes lanes = new Lanes()
    88
    99    @Override
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/MapCSSTagCheckerTest.java

    r7073 r7081  
    1515import org.junit.BeforeClass;
    1616import org.junit.Test;
    17 import org.openstreetmap.josm.Main;
     17import org.openstreetmap.josm.JOSMFixture;
    1818import org.openstreetmap.josm.TestUtils;
    1919import org.openstreetmap.josm.command.ChangePropertyCommand;
     
    3333    @BeforeClass
    3434    public static void setUp() {
    35         Main.initApplicationPreferences();
     35        JOSMFixture.createUnitTestFixture().init();
    3636    }
    3737
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/OpeningHourTestTest.java

    r7051 r7081  
    1616import org.junit.Before;
    1717import org.junit.Test;
    18 import org.openstreetmap.josm.Main;
     18import org.openstreetmap.josm.JOSMFixture;
    1919import org.openstreetmap.josm.data.osm.Tag;
    2020import org.openstreetmap.josm.data.validation.Severity;
     
    3737    @Before
    3838    public void setUp() throws Exception {
    39         Main.initApplicationPreferences();
     39        JOSMFixture.createUnitTestFixture().init();
    4040        OPENING_HOUR_TEST.initialize();
    4141    }
     
    135135        final String key = "opening_hours";
    136136        assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo,Tu 04-17").get(0).getSeverity(), is(Severity.WARNING));
    137         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo,Tu 04-17").get(0).getMessage(), 
     137        assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo,Tu 04-17").get(0).getMessage(),
    138138                is(key + " - Mo,Tu 04-17 <--- (Time range without minutes specified. Not very explicit! Please use this syntax instead e.g. \"12:00-14:00\".)"));
    139139        assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo,Tu 04-17").get(0).getPrettifiedValue(), is("Mo,Tu 04:00-17:00"));
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/UnconnectedWaysTest.java

    r7033 r7081  
    1010import org.junit.Before;
    1111import org.junit.Test;
    12 import org.openstreetmap.josm.Main;
     12import org.openstreetmap.josm.JOSMFixture;
    1313import org.openstreetmap.josm.data.osm.DataSet;
    14 import org.openstreetmap.josm.data.projection.Projections;
    1514import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    1615import org.openstreetmap.josm.io.OsmReader;
     
    2625    public void setUp() throws Exception {
    2726        bib = new UnconnectedWays.UnconnectedHighways();
    28         Main.initApplicationPreferences();
    29         Main.setProjection(Projections.getProjectionByCode("EPSG:3857"));
     27        JOSMFixture.createUnitTestFixture().init();
    3028        bib.initialize();
    3129        bib.startTest(null);
  • trunk/test/unit/org/openstreetmap/josm/gui/JosmUserIdentityManagerTest.groovy

    r7068 r7081  
    1414        final shouldFail = new GroovyTestCase().&shouldFail
    1515
    16         private static JOSMFixture josmFixture
    17 
    1816        @BeforeClass
    1917        public static void initTestCase() {
    20             josmFixture = JOSMFixture.createFunctionalTestFixture()
     18            JOSMFixture.createUnitTestFixture().init()
    2119        }
    2220
  • trunk/test/unit/org/openstreetmap/josm/gui/SystemOfMeasurementTest.java

    r6992 r7081  
    99import org.junit.BeforeClass;
    1010import org.junit.Test;
    11 import org.openstreetmap.josm.Main;
     11import org.openstreetmap.josm.JOSMFixture;
    1212import org.openstreetmap.josm.data.SystemOfMeasurement;
    1313
     
    2222    @BeforeClass
    2323    public static void setUp() {
    24         Main.initApplicationPreferences();
     24        JOSMFixture.createUnitTestFixture().init();
    2525    }
    2626
  • trunk/test/unit/org/openstreetmap/josm/gui/conflict/nodes/NodeListMergeModelTest.java

    r7005 r7081  
    1818import org.junit.BeforeClass;
    1919import org.junit.Test;
    20 import org.openstreetmap.josm.Main;
     20import org.openstreetmap.josm.JOSMFixture;
    2121import org.openstreetmap.josm.data.osm.DatasetFactory;
    2222import org.openstreetmap.josm.data.osm.Node;
     
    3131    @BeforeClass
    3232    public static void init() {
    33         Main.initApplicationPreferences();
     33        JOSMFixture.createUnitTestFixture().init();
    3434    }
    3535
  • trunk/test/unit/org/openstreetmap/josm/gui/conflict/properties/PropertiesMergeModelTest.java

    r7005 r7081  
    1212import org.junit.BeforeClass;
    1313import org.junit.Test;
    14 import org.openstreetmap.josm.Main;
     14import org.openstreetmap.josm.JOSMFixture;
    1515import org.openstreetmap.josm.data.conflict.Conflict;
    1616import org.openstreetmap.josm.data.coor.LatLon;
     
    2020import org.openstreetmap.josm.data.osm.Relation;
    2121import org.openstreetmap.josm.data.osm.Way;
    22 import org.openstreetmap.josm.data.projection.Projections;
    2322import org.openstreetmap.josm.gui.conflict.pair.MergeDecisionType;
    2423import org.openstreetmap.josm.gui.conflict.pair.properties.PropertiesMergeModel;
     
    4645    @BeforeClass
    4746    public static void init() {
    48         Main.setProjection(Projections.getProjectionByCode("EPSG:4326"));
    49         Main.initApplicationPreferences();
     47        JOSMFixture.createUnitTestFixture().init();
    5048    }
    5149
  • trunk/test/unit/org/openstreetmap/josm/gui/conflict/tags/TagMergeItemTest.java

    r7005 r7081  
    88import org.junit.BeforeClass;
    99import org.junit.Test;
    10 import org.openstreetmap.josm.Main;
     10import org.openstreetmap.josm.JOSMFixture;
    1111import org.openstreetmap.josm.data.osm.Node;
    1212import org.openstreetmap.josm.gui.conflict.pair.MergeDecisionType;
     
    1717    @BeforeClass
    1818    public static void init() {
    19         Main.initApplicationPreferences();
     19        JOSMFixture.createUnitTestFixture().init();
    2020    }
    2121
  • trunk/test/unit/org/openstreetmap/josm/gui/conflict/tags/TagMergeModelTest.java

    r7005 r7081  
    1212import org.junit.BeforeClass;
    1313import org.junit.Test;
    14 import org.openstreetmap.josm.Main;
     14import org.openstreetmap.josm.JOSMFixture;
    1515import org.openstreetmap.josm.data.osm.Node;
    1616import org.openstreetmap.josm.gui.conflict.pair.MergeDecisionType;
     
    2323    @BeforeClass
    2424    public static void init() {
    25         Main.initApplicationPreferences();
     25        JOSMFixture.createUnitTestFixture().init();
    2626    }
    2727
  • trunk/test/unit/org/openstreetmap/josm/gui/mappaint/MapCSSWithExtendedTextDirectivesTest.groovy

    r7068 r7081  
    44
    55import org.junit.*
    6 import org.openstreetmap.josm.JOSMFixture;
     6import org.openstreetmap.josm.JOSMFixture
    77import org.openstreetmap.josm.gui.mappaint.LabelCompositionStrategy.DeriveLabelFromNameTagsCompositionStrategy
    88import org.openstreetmap.josm.gui.mappaint.LabelCompositionStrategy.TagLookupCompositionStrategy
    99import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.TagKeyReference
     10
    1011class MapCSSWithExtendedTextDirectivesTest {
    11    
    1212
    1313    @BeforeClass
     
    2020        Cascade c = new Cascade()
    2121        c.put("text", new Keyword("auto"))
    22        
     22
    2323        TextElement te = TextElement.create(c, Color.WHITE, false /* no default annotate */)
    2424        assert te.labelCompositionStrategy != null
    2525        assert te.labelCompositionStrategy instanceof DeriveLabelFromNameTagsCompositionStrategy
    2626    }
    27    
     27
    2828    @Test
    2929    public void createTextElementComposingTextFromTag() {
    3030        Cascade c = new Cascade()
    3131        c.put("text", new TagKeyReference("my_name"))
    32        
     32
    3333        TextElement te = TextElement.create(c, Color.WHITE, false /* no default annotate */)
    3434        assert te.labelCompositionStrategy != null
     
    3636        assert te.labelCompositionStrategy.getDefaultLabelTag() == "my_name"
    3737    }
    38        
     38
    3939    @Test
    4040    public void createNullStrategy() {
    4141        Cascade c = new Cascade()
    42        
     42
    4343        TextElement te = TextElement.create(c, Color.WHITE, false /* no default annotate */)
    44         assert te.labelCompositionStrategy == null
     44        assert te == null
    4545    }
    4646}
    47 
  • trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/ChildOrParentSelectorTest.groovy

    r7068 r7081  
    77
    88import org.junit.*
    9 import org.openstreetmap.josm.JOSMFixture;
     9import org.openstreetmap.josm.JOSMFixture
    1010import org.openstreetmap.josm.data.coor.LatLon
    1111import org.openstreetmap.josm.data.osm.DataSet
     
    1919class ChildOrParentSelectorTest {
    2020    static private Logger logger = Logger.getLogger(ChildOrParentSelectorTest.class.getName());
    21    
     21
    2222    def shouldFail = new GroovyTestCase().&shouldFail
    23    
     23
    2424    def DataSet ds;
    25    
     25
    2626    @BeforeClass
    2727    public static void createJOSMFixture(){
    2828        JOSMFixture.createUnitTestFixture().init()
    2929    }
    30    
     30
    3131    @Before
    3232    public void setUp() {
    3333        ds = new DataSet()
    3434    }
    35    
     35
    3636    def relation(id) {
    3737        def r = new Relation(id,1)
     
    3939        return r
    4040    }
    41    
     41
    4242    def node(id) {
    4343        def n = new Node(id,1)
     
    4646        return n
    4747    }
    48    
     48
    4949    def way(id){
    5050        def w = new Way(id,1)
     
    5252        return w
    5353    }
    54    
     54
    5555    def ChildOrParentSelector parse(css){
    5656         MapCSSStyleSource source = new MapCSSStyleSource(css)
    5757         source.loadStyleSource()
    5858         assert source.rules.size() == 1
    59          assert source.rules[0].selectors.size() == 1
    60          return source.rules[0].selectors[0]
     59         return source.rules[0].selector
    6160    }
    62    
     61
    6362    @Test
    6463    @Ignore
     
    6867        """
    6968        ChildOrParentSelector selector = parse(css)
    70        
     69
    7170        Relation r = relation(1)
    7271        Node n = node(1)
    7372        r.addMember(new RelationMember("my_role", n))
    7473        Environment e = new Environment().withChild(n)
    75        
    76         assert selector.matches(e)       
     74
     75        assert selector.matches(e)
    7776    }
    78    
     77
    7978    @Test
    8079    @Ignore
     
    8483        """
    8584        ChildOrParentSelector selector = parse(css)
    86        
     85
    8786        Relation r = relation(1)
    8887        Node n = node(1)
    8988        r.addMember(new RelationMember("my_role", n))
    9089        Environment e = new Environment().withChild(n)
    91        
     90
    9291        assert selector.matches(e)
    9392    }
    94        
     93
    9594    @Test
    9695    @Ignore
     
    10099        """
    101100        ChildOrParentSelector selector = parse(css)
    102        
     101
    103102        Relation r = relation(1)
    104103        Node n = node(1)
    105104        r.addMember(new RelationMember("my_role", n))
    106105        Environment e = new Environment().withChild(n)
    107        
     106
    108107        assert !selector.matches(e)
    109108    }
    110    
     109
    111110    @Test
    112111    @Ignore
     
    114113        def css = """
    115114           way < relation {}
    116         """       
     115        """
    117116        ChildOrParentSelector selector = parse(css)
    118         assert selector.parentSelector
    119        
     117        assert selector.type == Selector.ChildOrParentSelectorType.PARENT
     118
    120119    }
    121120    @Test
     
    124123           way <[role != "my_role"] relation {}
    125124        """
    126         ChildOrParentSelector selector = parse(css)   
    127         assert selector.parentSelector     
    128        
     125        ChildOrParentSelector selector = parse(css)
     126        assert selector.type == Selector.ChildOrParentSelectorType.PARENT
     127
    129128        Relation r = relation(1)
    130129        Way w1 = way(1)
     
    133132        Way w2 = way(2)
    134133        w2.setNodes([node(21), node(22)])
    135        
     134
    136135        Way w3 = way(3)
    137136        w3.setNodes([node(31), node(32)])
     
    140139        r.addMember(new RelationMember("my_role", w2))
    141140        r.addMember(new RelationMember("another role", w3))
    142        
     141
    143142        Environment e = new Environment().withPrimitive(r)
    144143        assert selector.matches(e)
    145144    }
    146    
     145
    147146    @Test
    148147    public void matches_6() {
     
    150149           relation >[role != "my_role"] way {}
    151150        """
    152         ChildOrParentSelector selector = parse(css)     
    153        
     151        ChildOrParentSelector selector = parse(css)
     152
    154153        Relation r = relation(1)
    155154        Way w1 = way(1)
     
    158157        Way w2 = way(2)
    159158        w2.setNodes([node(21), node(22)])
    160        
     159
    161160        Way w3 = way(3)
    162161        w3.setNodes([node(31), node(32)])
     
    165164        r.addMember(new RelationMember("my_role", w2))
    166165        r.addMember(new RelationMember("another role", w3))
    167        
     166
    168167        Environment e = new Environment().withPrimitive(w1)
    169168        assert !selector.matches(e)
    170        
     169
    171170        e = new Environment().withPrimitive(w2)
    172171        assert !selector.matches(e)
    173        
     172
    174173        e = new Environment().withPrimitive(w3)
    175174        assert selector.matches(e)
  • trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/KeyConditionTest.groovy

    r7068 r7081  
    55
    66import org.junit.*
    7 import org.openstreetmap.josm.JOSMFixture;
     7import org.openstreetmap.josm.JOSMFixture
    88import org.openstreetmap.josm.data.coor.LatLon
    99import org.openstreetmap.josm.data.osm.DataSet
     
    1717
    1818    def shouldFail = new GroovyTestCase().&shouldFail
    19    
     19
    2020    def DataSet ds;
    21    
     21
    2222    @BeforeClass
    2323    public static void createJOSMFixture(){
    2424        JOSMFixture.createUnitTestFixture().init()
    2525    }
    26    
     26
    2727    @Before
    2828    public void setUp() {
    2929        ds = new DataSet()
    3030    }
    31    
     31
    3232    def relation(id) {
    3333        def r = new Relation(id,1)
     
    3535        return r
    3636    }
    37    
     37
    3838    def node(id) {
    3939        def n = new Node(id,1)
     
    4242        return n
    4343    }
    44    
     44
    4545    @Test
    4646    public void create() {
    47        
     47
    4848        // ["a label"]
    49         Condition c = Condition.create("a key", false, false, Context.PRIMITIVE)
     49        Condition c = Condition.createKeyCondition("a key", false, Condition.KeyMatchType.FALSE, Context.PRIMITIVE)
    5050        // ["a label"?]
    51         c = Condition.create("a key", false, true, Context.PRIMITIVE)
     51        c = Condition.createKeyCondition("a key", false, Condition.KeyMatchType.TRUE, Context.PRIMITIVE)
    5252        // [!"a label"]
    53         c = Condition.create("a key", true, false, Context.PRIMITIVE)
     53        c = Condition.createKeyCondition("a key", true, Condition.KeyMatchType.FALSE, Context.PRIMITIVE)
    5454        // [!"a label"?]
    55         c = Condition.create("a key", true, true, Context.PRIMITIVE)
    56        
     55        c = Condition.createKeyCondition("a key", true, Condition.KeyMatchType.TRUE, Context.PRIMITIVE)
     56
    5757        // ["a label"]
    58         c = Condition.create("a key", false, false, Context.LINK)
     58        c = Condition.createKeyCondition("a key", false, null, Context.LINK)
    5959        // [!"a label"]
    60         c = Condition.create("a key", true, false, Context.LINK)
    61        
     60        c = Condition.createKeyCondition("a key", true, null, Context.LINK)
     61
    6262        shouldFail(MapCSSException) {
    6363            // ["a label"?]
    64            c = Condition.create("a key", false, true, Context.LINK)
     64           c = Condition.createKeyCondition("a key", false, Condition.KeyMatchType.TRUE, Context.LINK)
    6565        }
    66        
     66
    6767        shouldFail(MapCSSException) {
    6868            // [!"a label"?]
    69             c = Condition.create("a key", true, true, Context.LINK)
     69            c = Condition.createKeyCondition("a key", true, Condition.KeyMatchType.TRUE, Context.LINK)
    7070        }
    7171    }
    72    
     72
    7373    @Test
    7474    public void applies_1() {
     
    7676        Node n = node(1)
    7777        r.addMember(new RelationMember("my_role", n))
    78        
     78
    7979        Environment e = new Environment().withPrimitive(n).withParent(r).withIndex(0).withLinkContext()
    80        
    81         Condition cond = Condition.create("my_role", false, false, Context.LINK)
    82         assert cond.applies(e)       
    83        
    84         cond = Condition.create("my_role", true, false, Context.LINK)
     80
     81        Condition cond = Condition.createKeyCondition("my_role", false, null, Context.LINK)
     82        assert cond.applies(e)
     83
     84        cond = Condition.createKeyCondition("my_role", true, null, Context.LINK)
    8585        assert !cond.applies(e)
    8686    }
    87    
     87
    8888    @Test
    8989    public void applies_2() {
     
    9191        Node n = node(1)
    9292        r.addMember(new RelationMember("my_role", n))
    93        
     93
    9494        Environment e = new Environment().withPrimitive(n).withParent(r).withIndex(0).withLinkContext()
    95        
    96         Condition cond = Condition.create("another_role", false, false, Context.LINK)
     95
     96        Condition cond = Condition.createKeyCondition("another_role", false, null, Context.LINK)
    9797        assert !cond.applies(e)
    98        
    99         cond = Condition.create("another_role", true, false, Context.LINK)
     98
     99        cond = Condition.createKeyCondition("another_role", true, null, Context.LINK)
    100100        assert cond.applies(e)
    101     }   
     101    }
    102102}
    103 
  • trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/KeyValueConditionTest.groovy

    r7068 r7081  
    55
    66import org.junit.*
    7 import org.openstreetmap.josm.JOSMFixture;
     7import org.openstreetmap.josm.JOSMFixture
    88import org.openstreetmap.josm.data.coor.LatLon
    99import org.openstreetmap.josm.data.osm.DataSet
     
    1919
    2020    def shouldFail = new GroovyTestCase().&shouldFail
    21    
     21
    2222    def DataSet ds;
    23    
     23
    2424    @BeforeClass
    2525    public static void createJOSMFixture(){
    2626        JOSMFixture.createUnitTestFixture().init()
    2727    }
    28    
     28
    2929    @Before
    3030    public void setUp() {
    3131        ds = new DataSet()
    3232    }
    33    
     33
    3434    def relation(id) {
    3535        def r = new Relation(id,1)
     
    3737        return r
    3838    }
    39    
     39
    4040    def node(id) {
    4141        def n = new Node(id,1)
     
    4444        return n
    4545    }
    46    
     46
    4747    @Test
    4848    public void create() {
    49         Condition c = Condition.create("a key", "a value", Op.EQ, Context.PRIMITIVE)
    50        
    51         c = Condition.create("role", "a role", Op.EQ, Context.LINK)
    52         c = Condition.create("RoLe", "a role", Op.EQ, Context.LINK)
    53        
     49        Condition c = Condition.createKeyValueCondition("a key", "a value", Op.EQ, Context.PRIMITIVE, false)
     50
     51        c = Condition.createKeyValueCondition("role", "a role", Op.EQ, Context.LINK, false)
     52        c = Condition.createKeyValueCondition("RoLe", "a role", Op.EQ, Context.LINK, false)
     53
    5454        shouldFail(MapCSSException) {
    55             c = Condition.create("an arbitry tag", "a role", Op.EQ, Context.LINK)
     55            c = Condition.createKeyValueCondition("an arbitry tag", "a role", Op.EQ, Context.LINK, false)
    5656        }
    5757    }
    58    
     58
    5959    @Test
    6060    public void applies_1() {
     
    6262        Node n = node(1)
    6363        r.addMember(new RelationMember("my_role", n))
    64        
     64
    6565        Environment e = new Environment().withPrimitive(n).withParent(r).withLinkContext().withIndex(0)
    66        
     66
    6767        Condition cond = new Condition.RoleCondition("my_role", Op.EQ)
    68         assert cond.applies(e)       
    69        
     68        assert cond.applies(e)
     69
    7070        cond = new Condition.RoleCondition("another_role", Op.EQ)
    7171        assert !cond.applies(e)
    7272    }
    73    
     73
    7474    @Test
    7575    public void applies_2() {
     
    7777        Node n = node(1)
    7878        r.addMember(new RelationMember("my_role", n))
    79        
     79
    8080        Environment e = new Environment().withPrimitive(n).withParent(r).withIndex(0).withLinkContext()
    81        
    82         Condition cond = Condition.create("role", "my_role", Op.NEQ, Context.LINK)
     81
     82        Condition cond = Condition.createKeyValueCondition("role", "my_role", Op.NEQ, Context.LINK, false)
    8383        assert !cond.applies(e)
    84        
    85         cond = Condition.create("role", "another_role", Op.NEQ, Context.LINK)
     84
     85        cond = Condition.createKeyValueCondition("role", "another_role", Op.NEQ, Context.LINK, false)
    8686        assert cond.applies(e)
    8787    }
    88    
    89    
    90    
    9188}
    92 
  • trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParserTest.groovy

    r7068 r7081  
    55import org.junit.Before
    66import org.junit.Test
     7import org.openstreetmap.josm.JOSMFixture
    78import org.openstreetmap.josm.Main
    8 import org.openstreetmap.josm.TestUtils;
     9import org.openstreetmap.josm.TestUtils
    910import org.openstreetmap.josm.data.coor.LatLon
    1011import org.openstreetmap.josm.data.osm.DataSet
    1112import org.openstreetmap.josm.data.osm.OsmPrimitive
    1213import org.openstreetmap.josm.data.osm.Way
    13 import org.openstreetmap.josm.data.projection.Projections
    1414import org.openstreetmap.josm.gui.mappaint.Environment
    1515import org.openstreetmap.josm.gui.mappaint.MultiCascade
     
    3535    @Before
    3636    public void setUp() throws Exception {
    37         Main.initApplicationPreferences()
    38         Main.setProjection(Projections.getProjectionByCode("EPSG:3857"));
     37        JOSMFixture.createUnitTestFixture().init();
    3938    }
    4039
     
    5756    public void testClassCondition() throws Exception {
    5857        def conditions = ((Selector.GeneralSelector) getParser("way[name=X].highway:closed").selector()).conds
    59         assert conditions.get(0) instanceof Condition.KeyValueCondition
     58        assert conditions.get(0) instanceof Condition.SimpleKeyValueCondition
    6059        assert conditions.get(0).applies(getEnvironment("name", "X"))
    6160        assert conditions.get(1) instanceof Condition.ClassCondition
     
    8988    @Test
    9089    public void testEqualCondition() throws Exception {
    91         def condition = (Condition.KeyValueCondition) getParser("[surface=paved]").condition(Condition.Context.PRIMITIVE)
    92         assert condition instanceof Condition.KeyValueCondition
    93         assert Condition.Op.EQ.equals(condition.op)
     90        def condition = (Condition.SimpleKeyValueCondition) getParser("[surface=paved]").condition(Condition.Context.PRIMITIVE)
     91        assert condition instanceof Condition.SimpleKeyValueCondition
    9492        assert "surface".equals(condition.k)
    9593        assert "paved".equals(condition.v)
     
    215213
    216214    @Test
    217     public void testTicket80711() throws Exception {
     215    public void testTicket8071() throws Exception {
    218216        def sheet = new MapCSSStyleSource("")
    219217        getParser("*[rcn_ref], *[name] {text: concat(tag(rcn_ref), \" \", tag(name)); }").sheet(sheet)
  • trunk/test/unit/org/openstreetmap/josm/gui/tagging/TaggingPresetReaderTest.java

    r7068 r7081  
    1313import org.junit.BeforeClass;
    1414import org.junit.Test;
    15 import org.openstreetmap.josm.Main;
     15import org.openstreetmap.josm.JOSMFixture;
    1616import org.openstreetmap.josm.TestUtils;
    1717import org.openstreetmap.josm.tools.Utils;
     
    2828    @BeforeClass
    2929    public static void setUp() {
    30         Main.initApplicationPreferences();
     30        JOSMFixture.createUnitTestFixture().init();
    3131    }
    3232
  • trunk/test/unit/org/openstreetmap/josm/io/DiffResultProcessorTest.groovy

    r2605 r7081  
    22package org.openstreetmap.josm.io;
    33
     4import static org.junit.Assert.*
    45
    5 import org.junit.Test
    6 import org.openstreetmap.josm.data.osm.Node;
    7 import org.openstreetmap.josm.data.osm.Way;
    8 import org.openstreetmap.josm.data.osm.Relation;
    9 import org.openstreetmap.josm.data.osm.Changeset;
     6import org.junit.Test
    107import org.openstreetmap.josm.data.coor.LatLon
    11 import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    12 import org.openstreetmap.josm.data.osm.SimplePrimitiveId;
    13 import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    14 
    15 import static org.junit.Assert.*;
     8import org.openstreetmap.josm.data.osm.Changeset
     9import org.openstreetmap.josm.data.osm.Node
     10import org.openstreetmap.josm.data.osm.OsmPrimitiveType
     11import org.openstreetmap.josm.data.osm.Relation
     12import org.openstreetmap.josm.data.osm.SimplePrimitiveId
     13import org.openstreetmap.josm.data.osm.Way
     14import org.openstreetmap.josm.gui.progress.NullProgressMonitor
     15import org.openstreetmap.josm.tools.XmlParsingException
    1616
    1717class DiffResultProcessorTest {
    18        
    19        
     18
     19
    2020        @Test
    2121        public void testConstructor() {
    2222                Node n = new Node(1)
    23                 // these calls should not fail 
     23                // these calls should not fail
    2424                //
    2525                def DiffResultProcessor processor  = new DiffResultProcessor(null)
     
    2727                processor  = new DiffResultProcessor([n])
    2828        }
    29        
     29
    3030        @Test
    3131        public void testParse_NOK_Cases() {
    3232                def DiffResultProcessor processor  = new DiffResultProcessor([])
    33                
     33
    3434                final shouldFail = new GroovyTestCase().&shouldFail
    35                
     35
    3636                shouldFail(IllegalArgumentException) {
    3737                    processor.parse null, NullProgressMonitor.INSTANCE
    3838                }
    39                
    40                 shouldFail(OsmDataParsingException) {
     39
     40                shouldFail(XmlParsingException) {
    4141                        processor.parse "", NullProgressMonitor.INSTANCE
    4242                }
    43                
    44                 shouldFail(OsmDataParsingException) {
     43
     44                shouldFail(XmlParsingException) {
    4545                        processor.parse "<x></x>", NullProgressMonitor.INSTANCE
    46                 }               
     46                }
    4747        }
    48        
    49         @Test 
     48
     49        @Test
    5050        public void testParse_OK_Cases() {
    5151                def DiffResultProcessor processor  = new DiffResultProcessor([])
     
    5757                </diffResult>
    5858                """
    59                
     59
    6060                processor.parse doc, null
    6161                assert processor.@diffResults.size() == 3
     
    6565                assert entry.new_id == 1
    6666                assert entry.new_version == 1
    67                
     67
    6868                id = new SimplePrimitiveId(-2, OsmPrimitiveType.WAY)
    6969                entry = processor.@diffResults[id]
     
    7171                assert entry.new_id == 2
    7272                assert entry.new_version == 1
    73                
     73
    7474                id = new SimplePrimitiveId(-3, OsmPrimitiveType.RELATION)
    7575                entry = processor.@diffResults[id]
    7676                assert entry != null
    7777                assert entry.new_id == 3
    78                 assert entry.new_version == 1           
     78                assert entry.new_version == 1
    7979        }
    80        
     80
    8181        @Test
    8282        public void testPostProcess_Invocation_Variants() {
     
    8989        </diffResult>
    9090        """
    91                
     91
    9292                processor.parse doc, null
    93                
     93
    9494                // should all be ok
    9595                //
     
    9999                processor.postProcess new Changeset(1), NullProgressMonitor.INSTANCE
    100100        }
    101        
     101
    102102        @Test
    103103        public void testPostProcess_OK() {
    104                
     104
    105105                Node n = new Node()
    106106                Way w = new Way()
    107107                Relation r = new Relation()
    108                
     108
    109109                String doc = """\
    110110                <diffResult version="0.6" generator="Test Data">
     
    114114                </diffResult>
    115115                """
    116                
     116
    117117                def DiffResultProcessor processor  = new DiffResultProcessor([n,w,r])
    118118                processor.parse doc, null
     
    122122                assert n.changesetId == 5
    123123                assert n.version == 10
    124                
     124
    125125                w = processed.find {it.uniqueId == 2}
    126126                assert w.changesetId == 5
    127127                assert w.version == 11
    128                
     128
    129129                r = processed.find {it.uniqueId == 3}
    130130                assert r.changesetId == 5
    131                 assert r.version == 12         
     131                assert r.version == 12
    132132        }
    133        
     133
    134134        @Test
    135135        public void testPostProcess_ForCreatedElement() {
    136                
    137                 Node n = new Node()             
     136
     137                Node n = new Node()
    138138                String doc = """\
    139139            <diffResult version="0.6" generator="Test Data">
     
    141141            </diffResult>
    142142            """
    143                
     143
    144144                def DiffResultProcessor processor  = new DiffResultProcessor([n])
    145145                processor.parse doc, null
     
    150150                assert n.version == 1
    151151        }
    152        
     152
    153153        @Test
    154154        public void testPostProcess_ForModifiedElement() {
    155                
     155
    156156                Node n = new Node(1)
    157157                n.coor = new LatLon(1,1)
     
    163163            </diffResult>
    164164            """
    165                
     165
    166166                def DiffResultProcessor processor  = new DiffResultProcessor([n])
    167167                processor.parse doc, null
     
    172172                assert n.version == 3
    173173        }
    174        
     174
    175175        @Test
    176176        public void testPostProcess_ForDeletedElement() {
    177                
     177
    178178                Node n = new Node(1)
    179179                n.coor = new LatLon(1,1)
     
    185185            </diffResult>
    186186            """
    187                
     187
    188188                def DiffResultProcessor processor  = new DiffResultProcessor([n])
    189189                processor.parse doc, null
  • trunk/test/unit/org/openstreetmap/josm/io/OsmChangeBuilderTest.groovy

    r2690 r7081  
    11package org.openstreetmap.josm.io;
    22
    3 import org.junit.Test
    4 import org.openstreetmap.josm.data.coor.LatLon
    5 import org.openstreetmap.josm.data.osm.Changeset
    6 
    7 import static org.junit.Assert.*;
    8  
     3import static org.junit.Assert.*
     4
     5import org.junit.Test
     6import org.openstreetmap.josm.data.coor.LatLon
     7import org.openstreetmap.josm.data.osm.Changeset
     8import org.openstreetmap.josm.data.osm.Node
     9
    910class OsmChangeBuilderTest {
    10        
    11         /**
    12          * Test various constructor invocations 
     11
     12        /**
     13         * Test various constructor invocations
    1314         */
    1415        @Test
    1516        public void testConstructor() {
    1617                def Changeset cs = new Changeset(1)
    17                 // should not fail 
    18                 OsmChangeBuilder builder = new OsmChangeBuilder(cs)
    19                
     18                // should not fail
     19                OsmChangeBuilder builder = new OsmChangeBuilder(cs)
     20
    2021                // should not fail either - null allowed
    2122                builder = new OsmChangeBuilder(null)
    22                
    23                 // should not fail 
     23
     24                // should not fail
    2425                builder = new OsmChangeBuilder(cs, "0.5")
    25                
     26
    2627                builder = new OsmChangeBuilder(cs, null)
    27                
    28                 builder = new OsmChangeBuilder(null, null)     
    29         }
    30        
     28
     29                builder = new OsmChangeBuilder(null, null)
     30        }
     31
    3132        /**
    3233         * Test the sequence of method calls. Should throw IllegalStateException if
     
    3536        @Test
    3637        public void testSequenceOfMethodCalls() {
    37                 def Changeset cs = new Changeset(1) 
    38                 OsmChangeBuilder builder = new OsmChangeBuilder(cs)
    39                
     38                def Changeset cs = new Changeset(1)
     39                OsmChangeBuilder builder = new OsmChangeBuilder(cs)
     40
    4041                final shouldFail = new GroovyTestCase().&shouldFail
    41                
    42                 // should be OK 
     42
     43                // should be OK
    4344                builder.start()
    4445                Node n = new Node(new LatLon(0,0))
    4546                builder.append n
    4647                builder.finish()
    47                
     48
    4849                shouldFail(IllegalStateException) {
    4950                        builder = new OsmChangeBuilder(cs)
    5051                        builder.append n
    5152                }
    52                
     53
    5354                shouldFail(IllegalStateException) {
    5455                        builder = new OsmChangeBuilder(cs)
    5556                        builder.append([n])
    5657                }
    57                
     58
    5859                shouldFail(IllegalStateException) {
    5960                        builder = new OsmChangeBuilder(cs)
    6061                        builder.finish()
    6162                }
    62                
     63
    6364                shouldFail(IllegalStateException) {
    6465                        builder = new OsmChangeBuilder(cs)
    6566                        builder.start()
    6667                        builder.start()
    67                 }       
    68         }
    69        
     68                }
     69        }
     70
    7071        @Test
    7172        public void testDocumentWithNewNode() {
    72                 def Changeset cs = new Changeset(1) 
     73                def Changeset cs = new Changeset(1)
    7374                OsmChangeBuilder builder = new OsmChangeBuilder(cs)
    7475                Node n = new Node(new LatLon(0,0))
    75                
    76                 builder.start()
    77                 builder.append n
    78                 builder.finish()
    79                
     76
     77                builder.start()
     78                builder.append n
     79                builder.finish()
     80
    8081                def doc = new XmlParser().parseText(builder.document)
    8182                assert doc.@version == "0.6"
     
    8586                def create = doc.create
    8687                assert create != null
    87                
     88
    8889                assert create.size() == 1
    8990                def nodes = create[0].node
     
    9394                assert node.@lat != null
    9495                assert node.@lon != null
    95                 assert node.@changeset == cs.id.toString()     
    96         }   
    97        
    98         /**
    99          * Test building a document with a modified node 
     96                assert node.@changeset == cs.id.toString()
     97        }
     98
     99        /**
     100         * Test building a document with a modified node
    100101         */
    101102        @Test
    102103        public void testDocumentWithModifiedNode() {
    103                 def Changeset cs = new Changeset(1) 
     104                def Changeset cs = new Changeset(1)
    104105                OsmChangeBuilder builder = new OsmChangeBuilder(cs)
    105106                Node n = new Node(1)
     
    107108                n.incomplete = false
    108109                n.modified = true
    109                
    110                 builder.start()
    111                 builder.append n
    112                 builder.finish()
    113                
     110
     111                builder.start()
     112                builder.append n
     113                builder.finish()
     114
    114115                def doc = new XmlParser().parseText(builder.document)
    115116                assert doc.@version == "0.6"
     
    119120                def modify = doc.modify
    120121                assert modify != null
    121                
     122
    122123                assert modify.size() == 1
    123124                def nodes = modify[0].node
     
    127128                assert node.@lat != null
    128129                assert node.@lon != null
    129                 assert node.@changeset == cs.id.toString()     
    130         }   
    131        
    132         /**
    133          * Test building a document with a deleted node 
     130                assert node.@changeset == cs.id.toString()
     131        }
     132
     133        /**
     134         * Test building a document with a deleted node
    134135         */
    135136        @Test
    136137        public void testDocumentWithDeletedNode() {
    137                 def Changeset cs = new Changeset(1) 
     138                def Changeset cs = new Changeset(1)
    138139                OsmChangeBuilder builder = new OsmChangeBuilder(cs)
    139140                Node n = new Node(1)
     
    141142                n.incomplete = false
    142143                n.deleted = true
    143                
    144                 builder.start()
    145                 builder.append n
    146                 builder.finish()
    147                
     144
     145                builder.start()
     146                builder.append n
     147                builder.finish()
     148
    148149                def doc = new XmlParser().parseText(builder.document)
    149150                assert doc.@version == "0.6"
     
    153154                def delete = doc.delete
    154155                assert delete != null
    155                
     156
    156157                assert delete.size() == 1
    157158                def nodes = delete[0].node
     
    159160                def node = nodes[0]
    160161                assert node.@id == n.uniqueId.toString()
    161                 assert node.@lat != null
    162                 assert node.@lon != null
    163                 assert node.@changeset == cs.id.toString()     
    164         }
    165        
    166         /**
    167          * Test building a mixed document. 
    168          * 
     162                assert node.@lat == null
     163                assert node.@lon == null
     164                assert node.@changeset == cs.id.toString()
     165        }
     166
     167        /**
     168         * Test building a mixed document.
     169         *
    169170         */
    170171        @Test
    171172        public void testMixed() {
    172                 def Changeset cs = new Changeset(1) 
     173                def Changeset cs = new Changeset(1)
    173174                OsmChangeBuilder builder = new OsmChangeBuilder(cs)
    174175                Node n1 = new Node(1)
     
    176177                n1.incomplete = false
    177178                n1.deleted = true
    178                
     179
    179180                Node n2 = new Node(new LatLon(0,0))
    180                
     181
    181182                Node n3 = new Node(2)
    182183                n3.coor = new LatLon(0,0)
    183184                n3.incomplete = false
    184185                n3.modified = true
    185                
     186
    186187                builder.start()
    187188                builder.append([n1,n2,n3])
    188189                builder.finish()
    189                
    190                 def doc = new XmlParser().parseText(builder.document)
    191                
     190
     191                def doc = new XmlParser().parseText(builder.document)
     192
    192193                assert doc.children().size() == 3
    193194                assert doc.children()[0].name() == "delete"
    194195                assert doc.children()[1].name() == "create"
    195196                assert doc.children()[2].name() == "modify"
    196                
     197
    197198                def node = doc.children()[0].node[0]
    198199                assert node.@id == n1.uniqueId.toString()
    199                
     200
    200201                node = doc.children()[1].node[0]
    201202                assert node.@id == n2.uniqueId.toString()
    202                
     203
    203204                node = doc.children()[2].node[0]
    204                 assert node.@id == n3.uniqueId.toString()       
     205                assert node.@id == n3.uniqueId.toString()
    205206        }
    206207}
  • trunk/test/unit/org/openstreetmap/josm/io/ParseWithChangesetReaderTest.groovy

    r2605 r7081  
    22package org.openstreetmap.josm.io;
    33
    4 import org.junit.Test
    5 
     4import static org.junit.Assert.*
     5
     6import java.nio.charset.StandardCharsets
     7
     8import org.junit.Test
     9import org.openstreetmap.josm.data.osm.DataSet
    610import org.openstreetmap.josm.data.osm.Node
    711import org.openstreetmap.josm.data.osm.OsmPrimitiveType
    8 import org.openstreetmap.josm.data.osm.DataSet
    9 
    10 import static org.junit.Assert.*;
    1112
    1213class ParseWithChangesetReaderTest {
    13        
     14
     15    private DataSet getDataSet(String doc) {
     16        InputStream is = new ByteArrayInputStream(doc.getBytes(StandardCharsets.UTF_8))
     17        DataSet ds = new OsmReader().parseDataSet(is, null)
     18        is.close()
     19        return ds
     20    }
     21
    1422        /**
    1523         * A new node with a changeset id. Ignore it.
     
    1927                String doc = """\
    2028         <osm version="0.6">
    21         <node id="-1" lat="0.0" lon="0.0" changeset="1"/>
    22         </osm>
    23         """
    24                
    25                 OsmReader reader = new OsmReader()
    26                 DataSet ds = reader.parseDataSet(new StringBufferInputStream(doc), null)
    27                 Node n = ds.getPrimitiveById(-1, OsmPrimitiveType.NODE)
    28                 assert n != null
    29                 assert n.uniqueId == -1
    30                 assert n.changesetId == 0
    31         }
    32        
     29        <node id="-1" lat="0.0" lon="0.0" changeset="1">
     30            <tag k="external-id" v="-1"/>
     31        </node>
     32        </osm>
     33        """
     34
     35                DataSet ds = getDataSet(doc)
     36        Node n = ds.nodes.find {it.get("external-id") == "-1"}
     37                assert n != null
     38                assert n.changesetId == 0
     39        }
     40
    3341        /**
    3442         * A new node with an invalid changeset id. Ignore it.
     
    4351        </osm>
    4452        """
    45                
    46                 OsmReader reader = new OsmReader()
    47                 DataSet ds = reader.parseDataSet(new StringBufferInputStream(doc), null)
    48                 Node n = ds.nodes.find {it.get("external-id") == "-1"}
    49                 assert n != null
    50                 assert n.changesetId == 0
    51         }
    52        
     53
     54        DataSet ds = getDataSet(doc)
     55                Node n = ds.nodes.find {it.get("external-id") == "-1"}
     56                assert n != null
     57                assert n.changesetId == 0
     58        }
     59
    5360        /**
    5461         * A new node with an invalid changeset id. Ignore it.
     
    6370        </osm>
    6471        """
    65                
    66                 OsmReader reader = new OsmReader()
    67                 DataSet ds = reader.parseDataSet(new StringBufferInputStream(doc), null)
    68                 Node n = ds.nodes.find {it.get("external-id") == "-1"}
    69                 assert n != null
    70                 assert n.changesetId == 0
    71         }
    72        
     72
     73        DataSet ds = getDataSet(doc)
     74                Node n = ds.nodes.find {it.get("external-id") == "-1"}
     75                assert n != null
     76                assert n.changesetId == 0
     77        }
     78
    7379        /**
    7480         * A new node with an invalid changeset id. Ignore it.
     
    8389        </osm>
    8490        """
    85                
    86                 OsmReader reader = new OsmReader()
    87                 DataSet ds = reader.parseDataSet(new StringBufferInputStream(doc), null)
    88                 Node n = ds.nodes.find {it.get("external-id") == "-1"}
    89                 assert n != null
    90                 assert n.changesetId == 0
    91         }
    92        
     91
     92        DataSet ds = getDataSet(doc)
     93                Node n = ds.nodes.find {it.get("external-id") == "-1"}
     94                assert n != null
     95                assert n.changesetId == 0
     96        }
     97
    9398        /**
    9499         * A new node with a missing changeset id. That's fine. The changeset id
     
    104109        </osm>
    105110        """
    106                
    107                 OsmReader reader = new OsmReader()
    108                 DataSet ds = reader.parseDataSet(new StringBufferInputStream(doc), null)
    109                 Node n = ds.nodes.find {it.get("external-id") == "-1"}
    110                 assert n != null
    111                 assert n.changesetId == 0
    112         }
    113        
    114        
     111
     112        DataSet ds = getDataSet(doc)
     113                Node n = ds.nodes.find {it.get("external-id") == "-1"}
     114                assert n != null
     115                assert n.changesetId == 0
     116        }
     117
     118
    115119        /**
    116120         * An existing node with a missing changeset id. That's fine. The changeset id
     
    124128        </osm>
    125129        """
    126                
    127                 OsmReader reader = new OsmReader()
    128                 DataSet ds = reader.parseDataSet(new StringBufferInputStream(doc), null)
     130
     131        DataSet ds = getDataSet(doc)
    129132                Node n = ds.getPrimitiveById(1, OsmPrimitiveType.NODE)
    130133                assert n != null
     
    132135                assert n.changesetId == 0
    133136        }
    134        
     137
    135138        /**
    136139     * An existing node with a valid changeset id id. That's fine. The changeset id
     
    144147        </osm>
    145148        """
    146                
    147                 OsmReader reader = new OsmReader()
    148                 DataSet ds = reader.parseDataSet(new StringBufferInputStream(doc), null)
     149
     150        DataSet ds = getDataSet(doc)
    149151                Node n = ds.getPrimitiveById(1, OsmPrimitiveType.NODE)
    150152                assert n != null
     
    152154                assert n.changesetId == 4
    153155        }
    154        
     156
    155157        /**
    156158         * An existing node with an invalid changeset id. That's a problem. An exception
     
    164166        </osm>
    165167        """
    166                
     168
    167169                final shouldFail = new GroovyTestCase().&shouldFail
    168                
    169                 OsmReader reader = new OsmReader()
     170
    170171                shouldFail(IllegalDataException) {
    171                     DataSet ds = reader.parseDataSet(new StringBufferInputStream(doc), null)
     172            DataSet ds = getDataSet(doc)
    172173                }
    173         }       
     174        }
    174175        /**
    175176         * An existing node with an invalid changeset id. That's a problem. An exception
     
    183184        </osm>
    184185        """
    185                
     186
    186187                final shouldFail = new GroovyTestCase().&shouldFail
    187                
    188                 OsmReader reader = new OsmReader()
     188
    189189                shouldFail(IllegalDataException) {
    190                         DataSet ds = reader.parseDataSet(new StringBufferInputStream(doc), null)
     190            DataSet ds = getDataSet(doc)
    191191                }
    192         }   
     192        }
    193193        /**
    194194         * An existing node with an invalid changeset id. That's a problem. An exception
     
    202202                </osm>
    203203                """
    204                
     204
    205205                final shouldFail = new GroovyTestCase().&shouldFail
    206                
    207                 OsmReader reader = new OsmReader()
     206
    208207                shouldFail(IllegalDataException) {
    209                         DataSet ds = reader.parseDataSet(new StringBufferInputStream(doc), null)
     208            DataSet ds = getDataSet(doc)
    210209                }
    211         }   
     210        }
    212211}
  • trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/RemoteControlTest.java

    r7040 r7081  
    2626import org.junit.Before;
    2727import org.junit.Test;
     28import org.openstreetmap.josm.JOSMFixture;
    2829import org.openstreetmap.josm.Main;
    2930import org.openstreetmap.josm.tools.Utils;
     
    3637    private String httpBase;
    3738    private String httpsBase;
    38    
     39
    3940    /**
    4041     * Starts Remote control before testing requests.
     
    4243    @Before
    4344    public void setUp() {
    44         Main.initApplicationPreferences();
     45        JOSMFixture.createUnitTestFixture().init();
    4546        RemoteControl.start();
    4647        disableCertificateValidation();
     
    4849        httpsBase = "https://127.0.0.1:"+Main.pref.getInteger("remote.control.https.port", 8112);
    4950    }
    50    
     51
    5152    /**
    52      * Disable all HTTPS validation mechanisms as described 
     53     * Disable all HTTPS validation mechanisms as described
    5354     * <a href="http://stackoverflow.com/a/2893932/2257172">here</a> and
    5455     * <a href="http://stackoverflow.com/a/19542614/2257172">here</a>
     
    5657    public void disableCertificateValidation() {
    5758        // Create a trust manager that does not validate certificate chains
    58         TrustManager[] trustAllCerts = new TrustManager[] { 
     59        TrustManager[] trustAllCerts = new TrustManager[] {
    5960            new X509TrustManager() {
    6061                public X509Certificate[] getAcceptedIssuers() {
     
    7677            fail(e.getMessage());
    7778        }
    78        
     79
    7980        // Create all-trusting host name verifier
    8081        HostnameVerifier allHostsValid = new HostnameVerifier() {
     
    100101     * Tests that sending an HTTP request without command results in HTTP 400, with all available commands in error message.
    101102     * @throws IOException if an I/O error occurs
    102      * @throws MalformedURLException if HTTP URL is invalid 
     103     * @throws MalformedURLException if HTTP URL is invalid
    103104     */
    104105    @Test
     
    110111     * Tests that sending an HTTPS request without command results in HTTP 400, with all available commands in error message.
    111112     * @throws IOException if an I/O error occurs
    112      * @throws MalformedURLException if HTTPS URL is invalid 
     113     * @throws MalformedURLException if HTTPS URL is invalid
    113114     */
    114115    @Test
     
    122123        assertEquals(connection.getResponseCode(), HttpURLConnection.HTTP_BAD_REQUEST);
    123124        try (InputStream is = connection.getErrorStream()) {
    124             // TODO this code should be refactored somewhere in Utils as it is used in several JOSM classes 
     125            // TODO this code should be refactored somewhere in Utils as it is used in several JOSM classes
    125126            StringBuilder responseBody = new StringBuilder();
    126127            try (BufferedReader in = new BufferedReader(new InputStreamReader(is, Utils.UTF_8))) {
  • trunk/test/unit/org/openstreetmap/josm/io/session/SessionWriterTest.java

    r7075 r7081  
    1111import org.junit.BeforeClass;
    1212import org.junit.Test;
     13import org.openstreetmap.josm.JOSMFixture;
    1314import org.openstreetmap.josm.Main;
    1415import org.openstreetmap.josm.data.gpx.GpxData;
     
    7475    @BeforeClass
    7576    public static void setUpBeforeClass() {
    76         Main.initApplicationPreferences();
    77         Main.determinePlatformHook();
     77        JOSMFixture.createUnitTestFixture().init();
    7878        ProjectionPreference.setProjection();
    7979        Main.toolbar = new ToolbarPreferences();
  • trunk/test/unit/org/openstreetmap/josm/tools/BugReportExceptionHandlerTest.java

    r7060 r7081  
    1313import org.junit.Before;
    1414import org.junit.Test;
     15import org.openstreetmap.josm.JOSMFixture;
    1516import org.openstreetmap.josm.Main;
    1617import org.openstreetmap.josm.actions.ShowStatusReportAction;
     
    2728    public void setUp() {
    2829        Main.commandLineArgs = new String[0];
    29         Main.determinePlatformHook();
    30         Main.initApplicationPreferences();
     30        JOSMFixture.createUnitTestFixture().init();
    3131    }
    3232
    3333    /**
    3434     * Test method for {@link org.openstreetmap.josm.tools.BugReportExceptionHandler#getBugReportUrl(java.lang.String)}.
    35      * @throws IOException 
     35     * @throws IOException
    3636     */
    3737    @Test
     
    4141        String prefix = Main.getJOSMWebsite()+"/josmticket?gdata=";
    4242        assertTrue(url.startsWith(prefix));
    43        
     43
    4444        String gdata = url.substring(prefix.length());
    4545        // JAXB only provides support for "base64" decoding while we encode url in "base64url", so switch encoding, only for test purpose
  • trunk/test/unit/org/openstreetmap/josm/tools/TextTagParserTest.java

    r6881 r7081  
    99import org.junit.BeforeClass;
    1010import org.junit.Test;
    11 import org.openstreetmap.josm.Main;
     11import org.openstreetmap.josm.JOSMFixture;
    1212
    1313public class TextTagParserTest {
     
    1818    @BeforeClass
    1919    public static void setUp() {
    20         Main.initApplicationPreferences();
     20        JOSMFixture.createUnitTestFixture().init();
    2121    }
    2222
  • trunk/test/unit/org/openstreetmap/josm/tools/template_engine/TemplateEngineTest.java

    r6881 r7081  
    88import org.junit.BeforeClass;
    99import org.junit.Test;
    10 import org.openstreetmap.josm.Main;
     10import org.openstreetmap.josm.JOSMFixture;
    1111import org.openstreetmap.josm.actions.search.SearchCompiler;
    1212import org.openstreetmap.josm.actions.search.SearchCompiler.Match;
     
    2424    @BeforeClass
    2525    public static void setUp() {
    26         Main.initApplicationPreferences();
     26        JOSMFixture.createUnitTestFixture().init();
    2727    }
    2828
Note: See TracChangeset for help on using the changeset viewer.