source: josm/trunk/test/unit/org/openstreetmap/josm/gui/io/AsynchronousUploadPrimitivesTaskTest.java@ 17536

Last change on this file since 17536 was 17275, checked in by Don-vip, 3 years ago

see #16567 - upgrade almost all tests to JUnit 5, except those depending on WiremockRule

See https://github.com/tomakehurst/wiremock/issues/684

  • Property svn:eol-style set to native
File size: 3.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.io;
3
4import java.util.Collections;
5import java.util.Optional;
6
7import javax.swing.JOptionPane;
8
9import org.junit.Assert;
10import org.junit.jupiter.api.AfterEach;
11import org.junit.jupiter.api.BeforeEach;
12import org.junit.jupiter.api.Test;
13import org.junit.jupiter.api.extension.RegisterExtension;
14import org.openstreetmap.josm.TestUtils;
15import org.openstreetmap.josm.data.APIDataSet;
16import org.openstreetmap.josm.data.coor.LatLon;
17import org.openstreetmap.josm.data.osm.Changeset;
18import org.openstreetmap.josm.data.osm.DataSet;
19import org.openstreetmap.josm.data.osm.Node;
20import org.openstreetmap.josm.data.osm.Way;
21import org.openstreetmap.josm.gui.layer.OsmDataLayer;
22import org.openstreetmap.josm.io.UploadStrategySpecification;
23import org.openstreetmap.josm.testutils.JOSMTestRules;
24import org.openstreetmap.josm.testutils.mockers.JOptionPaneSimpleMocker;
25
26import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
27
28/**
29 * Unit tests of {@link AsynchronousUploadPrimitivesTask}.
30 */
31class AsynchronousUploadPrimitivesTaskTest {
32
33 private UploadStrategySpecification strategy;
34 private OsmDataLayer layer;
35 private APIDataSet toUpload;
36 private Changeset changeset;
37 private AsynchronousUploadPrimitivesTask uploadPrimitivesTask;
38
39 /**
40 * Setup tests
41 */
42 @RegisterExtension
43 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
44 public JOSMTestRules test = new JOSMTestRules().assertionsInEDT();
45
46 /**
47 * Bootstrap.
48 */
49 @BeforeEach
50 public void bootStrap() {
51 DataSet dataSet = new DataSet();
52 Node node1 = new Node();
53 Node node2 = new Node();
54 node1.setCoor(new LatLon(0, 0));
55 node2.setCoor(new LatLon(30, 30));
56 Way way = new Way();
57 way.addNode(node1);
58 way.addNode(node2);
59 dataSet.addPrimitive(node1);
60 dataSet.addPrimitive(node2);
61 dataSet.addPrimitive(way);
62
63 toUpload = new APIDataSet(dataSet);
64 layer = new OsmDataLayer(dataSet, "uploadTest", null);
65 strategy = new UploadStrategySpecification();
66 changeset = new Changeset();
67 uploadPrimitivesTask = AsynchronousUploadPrimitivesTask.createAsynchronousUploadTask(strategy, layer, toUpload, changeset).get();
68 }
69
70 /**
71 * Tear down.
72 */
73 @AfterEach
74 public void tearDown() {
75 toUpload = null;
76 layer = null;
77 strategy = null;
78 changeset = null;
79 if (uploadPrimitivesTask != null) {
80 uploadPrimitivesTask.cancel();
81 }
82 uploadPrimitivesTask = null;
83 }
84
85 /**
86 * Test single upload instance.
87 */
88 @Test
89 void testSingleUploadInstance() {
90 TestUtils.assumeWorkingJMockit();
91 new JOptionPaneSimpleMocker(Collections.singletonMap(
92 "A background upload is already in progress. Kindly wait for it to finish before uploading new changes", JOptionPane.OK_OPTION
93 ));
94 Optional<AsynchronousUploadPrimitivesTask> task = AsynchronousUploadPrimitivesTask.
95 createAsynchronousUploadTask(strategy, layer, toUpload, changeset);
96 Assert.assertNotNull(uploadPrimitivesTask);
97 Assert.assertFalse(task.isPresent());
98 }
99}
Note: See TracBrowser for help on using the repository browser.