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

fixes for unit tests

Location:
trunk/test/unit/org/openstreetmap/josm/gui
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.