Ignore:
Timestamp:
2016-06-23T01:51:57+02:00 (8 years ago)
Author:
donvip
Message:

update unit test

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/turnrestrictions/test/unit/org/openstreetmap/josm/plugins/turnrestrictions/editor/JosmSelectionListModelTest.groovy

    r32363 r32377  
    11package org.openstreetmap.josm.plugins.turnrestrictions.editor;
    22
    3 import groovy.util.GroovyTestCase;
     3import static org.junit.Assert.*
    44
    5 import org.openstreetmap.josm.gui.MainApplication;
     5import javax.swing.DefaultListSelectionModel
     6
     7import org.junit.*
     8import org.openstreetmap.josm.Main
     9import org.openstreetmap.josm.data.coor.*
     10import org.openstreetmap.josm.data.osm.*
    611import org.openstreetmap.josm.gui.layer.OsmDataLayer
    7 import org.openstreetmap.josm.testutils.JOSMTestRules;
    8 
    9 import javax.swing.DefaultListSelectionModel;
    10 import org.openstreetmap.josm.data.osm.*;
    11 import org.openstreetmap.josm.data.coor.*;
    12 import org.openstreetmap.josm.JOSMFixture;
    13 
    14 import static org.junit.Assert.*;
    15 import org.junit.*;
    16 import javax.swing.JFrame;
    17 
    18 import junit.framework.TestCase;
    19 import junit.framework.TestResult;
     12import org.openstreetmap.josm.testutils.JOSMTestRules
    2013
    2114/**
     
    2316 */
    2417class JosmSelectionListModelTest extends GroovyTestCase {
    25     final shouldFail = new GroovyTestCase().&shouldFail
    2618
    2719    @Rule
    2820    public JOSMTestRules rules = new JOSMTestRules().preferences();
     21
     22    final shouldFail = new GroovyTestCase().&shouldFail
    2923
    3024        @Test
     
    3226                DataSet ds = new DataSet()
    3327                OsmDataLayer layer = new OsmDataLayer(ds, "test", null)
    34                 JosmSelectionListModel model = new JosmSelectionListModel(layer);               
    35                
     28                JosmSelectionListModel model = new JosmSelectionListModel(layer);
     29
    3630                shouldFail(IllegalArgumentException){
    3731                        model = new JosmSelectionListModel(null)
    3832                }
    3933        }
    40        
     34
    4135        @Test
    4236        public void test_setJOSMSelection() {
     
    4438                OsmDataLayer layer = new OsmDataLayer(ds, "test", null)
    4539                JosmSelectionListModel model = new JosmSelectionListModel(layer);
    46                
    47                 // set a selection with three objects 
     40
     41                // set a selection with three objects
    4842                def objects = [new Node(new LatLon(1,1)), new Way(), new Relation()]
    4943                model.setJOSMSelection objects
    5044                assert model.getSize() == 3
    51                
    52                 // null is allowed 
     45
     46                // null is allowed
    5347                model.setJOSMSelection(null)
    5448                assert model.getSize() == 0
    5549                assert model.getSelected().isEmpty()
    56                
     50
    5751                // empty has the same effect
    5852                model.setJOSMSelection([])
     
    6054                assert model.getSelected().isEmpty()
    6155        }
    62        
     56
    6357        @Test
    6458        public void test_setJOSMSelection_withSelected() {
     
    6660                OsmDataLayer layer = new OsmDataLayer(ds, "test", null)
    6761                JosmSelectionListModel model = new JosmSelectionListModel(layer);
    68                 def objects = [new Node(new LatLon(1,1)), new Way(), new Relation()]   
     62                def objects = [new Node(new LatLon(1,1)), new Way(), new Relation()]
    6963                model.setJOSMSelection(objects)
    7064                model.setSelected(objects[0..1])
    7165                assert model.getSelected().asList() as Set == objects[0..1] as Set
    72                
    73                 // set new selection which includes one object which is currently
     66
     67        // set new selection which includes one object which is currently
    7468        // selected in the model. Should still be selected after setting
    75                 // the new JOSM selection
    76                 objects = objects[1..2] 
     69        // the new JOSM selection
     70                objects = objects[1..2]
    7771                model.setJOSMSelection(objects)
    7872                assert model.getSelected().asList() == [objects[0]]
    79         }       
    80        
     73        }
     74
    8175        @Test
    8276        public void test_getSelected() {
    8377                DataSet ds = new DataSet()
    8478                OsmDataLayer layer = new OsmDataLayer(ds, "test", null)
    85                
     79
    8680                JosmSelectionListModel model = new JosmSelectionListModel(layer);
    8781                DefaultListSelectionModel selectionModel = model.getListSelectionModel()
    88                
     82
    8983                assert model.getSelected() != null
    9084                assert model.getSelected().isEmpty()
    91        
    92                 // select one element 
    93                 def objects = [new Node(new LatLon(1,1)), new Way(), new Relation()]   
     85
     86                // select one element
     87                def objects = [new Node(new LatLon(1,1)), new Way(), new Relation()]
    9488                model.setJOSMSelection(objects)
    9589                selectionModel.setSelectionInterval(0, 0)
    9690                assert model.getSelected().asList() == [model.getElementAt(0)];
    97                
     91
    9892                // select two elements
    9993                selectionModel.setSelectionInterval(1,2)
    10094                assert model.getSelected().asList() as Set == [model.getElementAt(1),model.getElementAt(2)] as Set;
    10195        }
    102        
     96
    10397        @Test
    10498        public void test_setSelected() {
    10599                DataSet ds = new DataSet()
    106100                OsmDataLayer layer = new OsmDataLayer(ds, "test", null)
    107                
     101
    108102                // set selected with null is OK - nothing selected thereafter
    109103                JosmSelectionListModel model = new JosmSelectionListModel(layer);
     
    111105                model.setSelected(null)
    112106                assert model.getSelected().isEmpty()
    113                
     107
    114108                // set selected with empty list is OK - nothing selected thereafter
    115109                model.setSelected([])
    116110                assert model.getSelected().isEmpty()
    117                
    118                 // select an object existing in the list of displayed objects 
    119                 def objects = [new Node(new LatLon(1,1)), new Way(), new Relation()]   
     111
     112                // select an object existing in the list of displayed objects
     113                def objects = [new Node(new LatLon(1,1)), new Way(), new Relation()]
    120114                model.setJOSMSelection(objects)
    121115                model.setSelected([objects[0]])
    122116                assert model.getSelected().asList() == [objects[0]];
    123                
    124                 // select an object not-existing in the list of displayed objects       
     117
     118                // select an object not-existing in the list of displayed objects
    125119                model.setJOSMSelection(objects)
    126120                model.setSelected([new Way()])
    127121                assert model.getSelected().isEmpty()
    128122        }
    129        
    130         @Test 
     123
     124        @Test
    131125        public void test_editLayerChanged() {
    132126                DataSet ds = new DataSet()
    133                        
    134                 def objects = [new Node(new LatLon(1,1)), new Way(), new Relation()]   
     127
     128                def objects = [new Node(new LatLon(1,1)), new Way(), new Relation()]
    135129                objects.each {ds.addPrimitive(it)}
    136                
     130
    137131                OsmDataLayer layer1 = new OsmDataLayer(ds,"layer1", null)
    138132                OsmDataLayer layer2 = new OsmDataLayer(new DataSet(),"layer2", null)
    139                
     133
     134        Main.getLayerManager().addLayer(layer1)
     135        Main.getLayerManager().addLayer(layer2)
     136
    140137                JosmSelectionListModel model = new JosmSelectionListModel(layer1);
    141138                DefaultListSelectionModel selectionModel = model.getListSelectionModel()
    142                 // switch from edit layer1 to edit layer2. content of the JOSM selection
    143                 // should be empty thereafter
    144                 model.editLayerChanged(layer1, layer2)
     139                // switch from edit layer1 to edit layer2. content of the JOSM selection
     140                // should be empty thereafter
     141        Main.getLayerManager().setActiveLayer(layer1)
     142        Main.getLayerManager().setActiveLayer(layer2)
    145143                assert model.getSize() == 0
    146                
     144
    147145                // switch from layer2 to layer1 which has one object selected. Object should
    148                 // be displayed in the JOSM selection list 
     146                // be displayed in the JOSM selection list
    149147                ds.setSelected([objects[0]])
    150                 model.editLayerChanged(layer2, layer1)
     148        Main.getLayerManager().setActiveLayer(layer1)
    151149                assert model.getSize() == 1
    152150                assert model.getElementAt(0) == objects[0];
    153                
     151
    154152                // switch to a "null" edit layer (i.e. no edit layer)- nothing should
    155                 // be displayed in the selection list
    156                 model.editLayerChanged(layer1, null)
     153                // be displayed in the selection list
     154        Main.getLayerManager().removeLayer(layer2)
     155        Main.getLayerManager().removeLayer(layer1)
    157156                assert model.getSize() == 0
    158157        }
Note: See TracChangeset for help on using the changeset viewer.