Changeset 32377 in osm for applications/editors/josm/plugins/turnrestrictions
- Timestamp:
- 2016-06-23T01:51:57+02:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/turnrestrictions/test/unit/org/openstreetmap/josm/plugins/turnrestrictions/editor/JosmSelectionListModelTest.groovy
r32363 r32377 1 1 package org.openstreetmap.josm.plugins.turnrestrictions.editor; 2 2 3 import groovy.util.GroovyTestCase;3 import static org.junit.Assert.* 4 4 5 import org.openstreetmap.josm.gui.MainApplication; 5 import javax.swing.DefaultListSelectionModel 6 7 import org.junit.* 8 import org.openstreetmap.josm.Main 9 import org.openstreetmap.josm.data.coor.* 10 import org.openstreetmap.josm.data.osm.* 6 11 import 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; 12 import org.openstreetmap.josm.testutils.JOSMTestRules 20 13 21 14 /** … … 23 16 */ 24 17 class JosmSelectionListModelTest extends GroovyTestCase { 25 final shouldFail = new GroovyTestCase().&shouldFail26 18 27 19 @Rule 28 20 public JOSMTestRules rules = new JOSMTestRules().preferences(); 21 22 final shouldFail = new GroovyTestCase().&shouldFail 29 23 30 24 @Test … … 32 26 DataSet ds = new DataSet() 33 27 OsmDataLayer layer = new OsmDataLayer(ds, "test", null) 34 JosmSelectionListModel model = new JosmSelectionListModel(layer); 35 28 JosmSelectionListModel model = new JosmSelectionListModel(layer); 29 36 30 shouldFail(IllegalArgumentException){ 37 31 model = new JosmSelectionListModel(null) 38 32 } 39 33 } 40 34 41 35 @Test 42 36 public void test_setJOSMSelection() { … … 44 38 OsmDataLayer layer = new OsmDataLayer(ds, "test", null) 45 39 JosmSelectionListModel model = new JosmSelectionListModel(layer); 46 47 // set a selection with three objects 40 41 // set a selection with three objects 48 42 def objects = [new Node(new LatLon(1,1)), new Way(), new Relation()] 49 43 model.setJOSMSelection objects 50 44 assert model.getSize() == 3 51 52 // null is allowed 45 46 // null is allowed 53 47 model.setJOSMSelection(null) 54 48 assert model.getSize() == 0 55 49 assert model.getSelected().isEmpty() 56 50 57 51 // empty has the same effect 58 52 model.setJOSMSelection([]) … … 60 54 assert model.getSelected().isEmpty() 61 55 } 62 56 63 57 @Test 64 58 public void test_setJOSMSelection_withSelected() { … … 66 60 OsmDataLayer layer = new OsmDataLayer(ds, "test", null) 67 61 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()] 69 63 model.setJOSMSelection(objects) 70 64 model.setSelected(objects[0..1]) 71 65 assert model.getSelected().asList() as Set == objects[0..1] as Set 72 73 66 67 // set new selection which includes one object which is currently 74 68 // selected in the model. Should still be selected after setting 75 76 objects = objects[1..2] 69 // the new JOSM selection 70 objects = objects[1..2] 77 71 model.setJOSMSelection(objects) 78 72 assert model.getSelected().asList() == [objects[0]] 79 } 80 73 } 74 81 75 @Test 82 76 public void test_getSelected() { 83 77 DataSet ds = new DataSet() 84 78 OsmDataLayer layer = new OsmDataLayer(ds, "test", null) 85 79 86 80 JosmSelectionListModel model = new JosmSelectionListModel(layer); 87 81 DefaultListSelectionModel selectionModel = model.getListSelectionModel() 88 82 89 83 assert model.getSelected() != null 90 84 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()] 94 88 model.setJOSMSelection(objects) 95 89 selectionModel.setSelectionInterval(0, 0) 96 90 assert model.getSelected().asList() == [model.getElementAt(0)]; 97 91 98 92 // select two elements 99 93 selectionModel.setSelectionInterval(1,2) 100 94 assert model.getSelected().asList() as Set == [model.getElementAt(1),model.getElementAt(2)] as Set; 101 95 } 102 96 103 97 @Test 104 98 public void test_setSelected() { 105 99 DataSet ds = new DataSet() 106 100 OsmDataLayer layer = new OsmDataLayer(ds, "test", null) 107 101 108 102 // set selected with null is OK - nothing selected thereafter 109 103 JosmSelectionListModel model = new JosmSelectionListModel(layer); … … 111 105 model.setSelected(null) 112 106 assert model.getSelected().isEmpty() 113 107 114 108 // set selected with empty list is OK - nothing selected thereafter 115 109 model.setSelected([]) 116 110 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()] 120 114 model.setJOSMSelection(objects) 121 115 model.setSelected([objects[0]]) 122 116 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 125 119 model.setJOSMSelection(objects) 126 120 model.setSelected([new Way()]) 127 121 assert model.getSelected().isEmpty() 128 122 } 129 130 @Test 123 124 @Test 131 125 public void test_editLayerChanged() { 132 126 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()] 135 129 objects.each {ds.addPrimitive(it)} 136 130 137 131 OsmDataLayer layer1 = new OsmDataLayer(ds,"layer1", null) 138 132 OsmDataLayer layer2 = new OsmDataLayer(new DataSet(),"layer2", null) 139 133 134 Main.getLayerManager().addLayer(layer1) 135 Main.getLayerManager().addLayer(layer2) 136 140 137 JosmSelectionListModel model = new JosmSelectionListModel(layer1); 141 138 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) 145 143 assert model.getSize() == 0 146 144 147 145 // 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 149 147 ds.setSelected([objects[0]]) 150 model.editLayerChanged(layer2,layer1)148 Main.getLayerManager().setActiveLayer(layer1) 151 149 assert model.getSize() == 1 152 150 assert model.getElementAt(0) == objects[0]; 153 151 154 152 // 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) 157 156 assert model.getSize() == 0 158 157 }
Note:
See TracChangeset
for help on using the changeset viewer.