Changeset 12562 in josm
- Timestamp:
- 2017-08-03T19:57:36+02:00 (8 years ago)
- Location:
- trunk
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/AlignInLineAction.java
r12527 r12562 170 170 return; 171 171 172 DataSet ds = getLayerManager().getEditDataSet();173 List<Node> selectedNodes = new ArrayList<>(ds.getSelectedNodes());174 List<Way> selectedWays = new ArrayList<>(ds.getSelectedWays());175 selectedWays.removeIf(OsmPrimitive::isIncomplete);176 177 172 try { 178 Command cmd; 179 // Decide what to align based on selection: 180 181 if (selectedNodes.isEmpty() && !selectedWays.isEmpty()) { 182 // Only ways selected -> For each way align their nodes taking care of intersection 183 cmd = alignMultiWay(selectedWays); 184 } else if (selectedNodes.size() == 1) { 185 // Only 1 node selected -> align this node relative to referers way 186 Node selectedNode = selectedNodes.get(0); 187 List<Way> involvedWays; 188 if (selectedWays.isEmpty()) 189 // No selected way, all way containing this node are used 190 involvedWays = selectedNode.getParentWays(); 191 else 192 // Selected way, use only these ways 193 involvedWays = selectedWays; 194 List<Line> lines = getInvolvedLines(selectedNode, involvedWays); 195 if (lines.size() > 2 || lines.isEmpty()) 196 throw new InvalidSelection(); 197 cmd = alignSingleNode(selectedNodes.get(0), lines); 198 } else if (selectedNodes.size() >= 3) { 199 // More than 3 nodes and way(s) selected -> align selected nodes. Don't care of way(s). 200 cmd = alignOnlyNodes(selectedNodes); 201 } else { 202 // All others cases are invalid 203 throw new InvalidSelection(); 204 } 205 206 // Do it! 207 Main.main.undoRedo.add(cmd); 208 173 Main.main.undoRedo.add(buildCommand()); 209 174 } catch (InvalidSelection except) { 210 175 Main.debug(except); … … 212 177 .setIcon(JOptionPane.INFORMATION_MESSAGE) 213 178 .show(); 179 } 180 } 181 182 /** 183 * Builds "align in line" command depending on the selected objects. 184 * @return the resulting command to execute to perform action 185 * @throws InvalidSelection if a polygon is selected, or if a node is used by 3 or more ways 186 * @since 12562 187 */ 188 public Command buildCommand() throws InvalidSelection { 189 DataSet ds = getLayerManager().getEditDataSet(); 190 List<Node> selectedNodes = new ArrayList<>(ds.getSelectedNodes()); 191 List<Way> selectedWays = new ArrayList<>(ds.getSelectedWays()); 192 selectedWays.removeIf(OsmPrimitive::isIncomplete); 193 194 // Decide what to align based on selection: 195 if (selectedNodes.isEmpty() && !selectedWays.isEmpty()) { 196 // Only ways selected -> For each way align their nodes taking care of intersection 197 return alignMultiWay(selectedWays); 198 } else if (selectedNodes.size() == 1) { 199 // Only 1 node selected -> align this node relative to referers way 200 Node selectedNode = selectedNodes.get(0); 201 List<Way> involvedWays; 202 if (selectedWays.isEmpty()) 203 // No selected way, all way containing this node are used 204 involvedWays = selectedNode.getParentWays(); 205 else 206 // Selected way, use only these ways 207 involvedWays = selectedWays; 208 List<Line> lines = getInvolvedLines(selectedNode, involvedWays); 209 if (lines.size() > 2 || lines.isEmpty()) 210 throw new InvalidSelection(); 211 return alignSingleNode(selectedNodes.get(0), lines); 212 } else if (selectedNodes.size() >= 3) { 213 // More than 3 nodes and way(s) selected -> align selected nodes. Don't care of way(s). 214 return alignOnlyNodes(selectedNodes); 215 } else { 216 // All others cases are invalid 217 throw new InvalidSelection(); 214 218 } 215 219 } -
trunk/test/functional/org/openstreetmap/josm/tools/HttpClientTest.java
r12555 r12562 154 154 @Test 155 155 public void testRelativeRedirects() throws IOException { 156 final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/relative-redirect/ 5")).connect(progress);156 final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/relative-redirect/3")).connect(progress); 157 157 assertThat(response.getResponseCode(), is(200)); 158 158 assertThat(response.getContentLength() > 100, is(true)); … … 161 161 @Test 162 162 public void testAbsoluteRedirects() throws IOException { 163 final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/absolute-redirect/ 5")).connect(progress);163 final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/absolute-redirect/3")).connect(progress); 164 164 assertThat(response.getResponseCode(), is(200)); 165 165 assertThat(response.getContentLength() > 100, is(true)); … … 168 168 @Test(expected = IOException.class) 169 169 public void testTooMuchRedirects() throws IOException { 170 HttpClient.create(new URL("https://httpbin.org/redirect/ 5")).setMaxRedirects(4).connect(progress);170 HttpClient.create(new URL("https://httpbin.org/redirect/3")).setMaxRedirects(2).connect(progress); 171 171 } 172 172 -
trunk/test/unit/org/openstreetmap/josm/MainTest.java
r12554 r12562 20 20 import javax.swing.UIManager; 21 21 22 import org.junit.Before;23 22 import org.junit.Rule; 24 23 import org.junit.Test; … … 47 46 @Rule 48 47 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 49 public JOSMTestRules test = new JOSMTestRules().platform().https().devAPI(); 50 51 /** 52 * Setup test. 53 */ 54 @Before 55 public void setUp() { 56 JOSMFixture.initContentPane(); 57 JOSMFixture.initMainPanel(); 58 } 48 public JOSMTestRules test = new JOSMTestRules().platform().https().devAPI().main(); 59 49 60 50 /** -
trunk/test/unit/org/openstreetmap/josm/actions/AddImageryLayerActionTest.java
r12557 r12562 30 30 /** 31 31 * We need prefs for this. We need platform for actions and the OSM API for checking blacklist. 32 * The timeout is set to default httpclient read timeout + connect timeout + a small delay to ignore33 * common but harmless network issues.34 32 */ 35 33 @Rule 36 34 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 37 public JOSMTestRules test = new JOSMTestRules().preferences().platform().fakeAPI() .timeout(45500);35 public JOSMTestRules test = new JOSMTestRules().preferences().platform().fakeAPI(); 38 36 39 37 /** -
trunk/test/unit/org/openstreetmap/josm/actions/AlignInLineActionTest.java
r12110 r12562 6 6 7 7 import org.junit.Before; 8 import org.junit.Rule; 8 9 import org.junit.Test; 9 import org.openstreetmap.josm.JOSMFixture;10 10 import org.openstreetmap.josm.Main; 11 11 import org.openstreetmap.josm.actions.AlignInLineAction.InvalidSelection; … … 17 17 import org.openstreetmap.josm.data.osm.Way; 18 18 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 19 import org.openstreetmap.josm.testutils.JOSMTestRules; 20 21 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 19 22 20 23 /** … … 23 26 public final class AlignInLineActionTest { 24 27 28 /** 29 * Setup test. 30 */ 31 @Rule 32 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 33 public JOSMTestRules test = new JOSMTestRules().mainMenu().projection(); 34 25 35 /** Class under test. */ 26 36 private static AlignInLineAction action; … … 31 41 @Before 32 42 public void setUp() { 33 JOSMFixture.createUnitTestFixture().init(true);34 35 43 // Enable "Align in line" feature. 36 44 action = Main.main.menu.alignInLine; … … 43 51 * https://josm.openstreetmap.de/ticket/9605#comment:3. Note that in this test, after alignment, way is overlapping 44 52 * itself. 45 */ 46 @Test 47 public void testNodesOpenWay() { 53 * @throws InvalidSelection never 54 */ 55 @Test 56 public void testNodesOpenWay() throws InvalidSelection { 48 57 DataSet dataSet = new DataSet(); 49 58 OsmDataLayer layer = new OsmDataLayer(dataSet, OsmDataLayer.createNewName(), null); … … 67 76 dataSet.addSelected(point1, point2, point3); 68 77 69 action. actionPerformed(null);78 action.buildCommand().executeCommand(); 70 79 } finally { 71 80 // Ensure we clean the place before leaving, even if test fails. … … 82 91 * Test case: only nodes selected, part of a closed way: align these nodes on the line passing through the most 83 92 * distant nodes. 84 */ 85 @Test 86 public void testNodesClosedWay() { 93 * @throws InvalidSelection never 94 */ 95 @Test 96 public void testNodesClosedWay() throws InvalidSelection { 87 97 DataSet dataSet = new DataSet(); 88 98 OsmDataLayer layer = new OsmDataLayer(dataSet, OsmDataLayer.createNewName(), null); … … 106 116 dataSet.addSelected(point4, point1, point2); 107 117 108 action. actionPerformed(null);118 action.buildCommand().executeCommand(); 109 119 } finally { 110 120 // Ensure we clean the place before leaving, even if test fails. … … 122 132 * Test case: only nodes selected, part of multiple ways: align these nodes on the line passing through the most 123 133 * distant nodes. 124 */ 125 @Test 126 public void testNodesOpenWays() { 134 * @throws InvalidSelection never 135 */ 136 @Test 137 public void testNodesOpenWays() throws InvalidSelection { 127 138 DataSet dataSet = new DataSet(); 128 139 OsmDataLayer layer = new OsmDataLayer(dataSet, OsmDataLayer.createNewName(), null); … … 149 160 150 161 // Points must align between points 1 and 4. 151 action. actionPerformed(null);162 action.buildCommand().executeCommand(); 152 163 } finally { 153 164 // Ensure we clean the place before leaving, even if test fails. -
trunk/test/unit/org/openstreetmap/josm/actions/CreateCircleActionTest.java
r12111 r12562 38 38 @Rule 39 39 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 40 public JOSMTestRules test = new JOSMTestRules().platform().projection(). commands();40 public JOSMTestRules test = new JOSMTestRules().platform().projection().main(); 41 41 42 42 /** -
trunk/test/unit/org/openstreetmap/josm/actions/FullscreenToggleActionTest.java
r11278 r12562 17 17 @Rule 18 18 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 19 public JOSMTestRules test = new JOSMTestRules().platform(). commands();19 public JOSMTestRules test = new JOSMTestRules().platform().main(); 20 20 21 21 /** -
trunk/test/unit/org/openstreetmap/josm/actions/JoinAreasActionTest.java
r12357 r12562 47 47 @Rule 48 48 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 49 public JOSMTestRules test = new JOSMTestRules(). commands();49 public JOSMTestRules test = new JOSMTestRules().platform().mainMenu().projection(); 50 50 51 51 /** -
trunk/test/unit/org/openstreetmap/josm/actions/MergeLayerActionTest.java
r11885 r12562 10 10 import org.openstreetmap.josm.Main; 11 11 import org.openstreetmap.josm.data.osm.DataSet; 12 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; 12 13 import org.openstreetmap.josm.gui.layer.LayerManagerTest.TestLayer; 13 14 import org.openstreetmap.josm.gui.layer.OsmDataLayer; … … 26 27 @Rule 27 28 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 28 public JOSMTestRules test = new JOSMTestRules().platform(). commands();29 public JOSMTestRules test = new JOSMTestRules().platform().mainMenu(); 29 30 30 31 private MergeLayerAction action; … … 35 36 @Before 36 37 public void setUp() { 38 try { 39 LayerListDialog.getInstance(); 40 } catch (IllegalStateException e) { 41 LayerListDialog.createInstance(Main.getLayerManager()); 42 Main.trace(e); 43 } 37 44 if (action == null) { 38 45 action = new MergeLayerAction(); -
trunk/test/unit/org/openstreetmap/josm/actions/MergeNodesActionTest.java
r11110 r12562 28 28 @Rule 29 29 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 30 public JOSMTestRules test = new JOSMTestRules().platform(). commands();30 public JOSMTestRules test = new JOSMTestRules().platform().projection(); 31 31 32 32 /** -
trunk/test/unit/org/openstreetmap/josm/actions/PurgeActionTest.java
r10966 r12562 32 32 @Rule 33 33 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 34 public JOSMTestRules test = new JOSMTestRules().platform(). commands();34 public JOSMTestRules test = new JOSMTestRules().platform().main(); 35 35 36 36 /** -
trunk/test/unit/org/openstreetmap/josm/actions/SimplifyWayActionTest.java
r11121 r12562 10 10 import java.util.stream.Stream; 11 11 12 import org.junit.BeforeClass; 12 import org.junit.Before; 13 import org.junit.Rule; 13 14 import org.junit.Test; 14 import org.openstreetmap.josm.JOSMFixture;15 15 import org.openstreetmap.josm.Main; 16 16 import org.openstreetmap.josm.command.DeleteCommand; … … 21 21 import org.openstreetmap.josm.data.osm.Way; 22 22 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 23 import org.openstreetmap.josm.testutils.JOSMTestRules; 23 24 import org.openstreetmap.josm.tools.Utils; 25 26 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 24 27 25 28 /** … … 34 37 * Setup test. 35 38 */ 36 @BeforeClass 37 public static void setUp() { 38 JOSMFixture.createUnitTestFixture().init(true); 39 action = Main.main.menu.simplifyWay; 40 action.setEnabled(true); 39 @Rule 40 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 41 public JOSMTestRules test = new JOSMTestRules().mainMenu(); 42 43 /** 44 * Setup test. 45 */ 46 @Before 47 public void setUp() { 48 if (action == null) { 49 action = Main.main.menu.simplifyWay; 50 action.setEnabled(true); 51 } 41 52 } 42 53 -
trunk/test/unit/org/openstreetmap/josm/actions/SplitWayActionTest.java
r10599 r12562 11 11 import java.util.Iterator; 12 12 13 import org.junit.BeforeClass; 13 import org.junit.Before; 14 import org.junit.Rule; 14 15 import org.junit.Test; 15 import org.openstreetmap.josm.JOSMFixture;16 16 import org.openstreetmap.josm.Main; 17 17 import org.openstreetmap.josm.actions.SplitWayAction.Strategy; … … 25 25 import org.openstreetmap.josm.data.osm.Way; 26 26 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 27 import org.openstreetmap.josm.testutils.JOSMTestRules; 28 29 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 27 30 28 31 /** … … 37 40 * Setup test. 38 41 */ 39 @BeforeClass 40 public static void setUp() { 41 JOSMFixture.createUnitTestFixture().init(true); 42 action = Main.main.menu.splitWay; 43 action.setEnabled(true); 42 @Rule 43 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 44 public JOSMTestRules test = new JOSMTestRules().mainMenu().projection(); 45 46 /** 47 * Setup test. 48 */ 49 @Before 50 public void setUp() { 51 if (action == null) { 52 action = Main.main.menu.splitWay; 53 action.setEnabled(true); 54 } 44 55 } 45 56 -
trunk/test/unit/org/openstreetmap/josm/actions/UnGlueActionTest.java
r10436 r12562 5 5 import static org.junit.Assert.assertTrue; 6 6 7 import org.junit.BeforeClass; 7 import org.junit.Before; 8 import org.junit.Rule; 8 9 import org.junit.Test; 9 import org.openstreetmap.josm.JOSMFixture;10 10 import org.openstreetmap.josm.Main; 11 11 import org.openstreetmap.josm.data.coor.LatLon; … … 14 14 import org.openstreetmap.josm.data.osm.Way; 15 15 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 16 import org.openstreetmap.josm.testutils.JOSMTestRules; 17 18 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 16 19 17 20 /** … … 26 29 * Setup test. 27 30 */ 28 @BeforeClass 29 public static void setUp() { 30 JOSMFixture.createUnitTestFixture().init(true); 31 action = Main.main.menu.unglueNodes; 32 action.setEnabled(true); 31 @Rule 32 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 33 public JOSMTestRules test = new JOSMTestRules().mainMenu(); 34 35 /** 36 * Setup test. 37 */ 38 @Before 39 public void setUp() { 40 if (action == null) { 41 action = Main.main.menu.unglueNodes; 42 action.setEnabled(true); 43 } 33 44 } 34 45 -
trunk/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java
r12558 r12562 213 213 214 214 /** 215 * Use the {@link Main#main} applicationin this test.215 * Use the {@link Main#main}, {@code Main.contentPanePrivate}, {@code Main.mainPanel}, {@link Main#toolbar} global variables in this test. 216 216 * @return this instance, for easy chaining 217 217 * @since 12557 … … 340 340 if (main) { 341 341 new MainApplication(); 342 JOSMFixture.initContentPane(); 343 JOSMFixture.initMainPanel(); 344 JOSMFixture.initToolbar(); 342 345 } 343 346 344 347 if (mainMenu) { 345 JOSMFixture.initContentPane();346 JOSMFixture.initToolbar();347 348 Main.main.menu = new MainMenu(); 348 349 }
Note:
See TracChangeset
for help on using the changeset viewer.