Skip to content

Commit 39af09b

Browse files
author
nokutu
committed
Fixed bug related to progress numbers during upload and added unit test for PluginState class
git-svn-id: http://svn.openstreetmap.org/applications/editors/josm/plugins/mapillary@31482 b9d5c4c9-76e1-0310-9c85-f3177eceb1e4
1 parent 8699b80 commit 39af09b

File tree

5 files changed

+83
-25
lines changed

5 files changed

+83
-25
lines changed

build.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
55
<property name="plugin.main.version" value="8433"/>
66
<property name="plugin.canloadatruntime" value="true"/>
7-
<property name="plugin.version" value="0.9.1"/>
7+
<property name="plugin.version" value="0.9.2"/>
88
<property name="plugin.author" value="nokutu &lt;nokutu@openmailbox.org&gt;"/>
99
<property name="plugin.class" value="org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin"/>
1010
<property name="plugin.description" value="Allows the user to work with pictures hosted at mapillary.com"/>

src/org/openstreetmap/josm/plugins/mapillary/oauth/UploadUtils.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ public void run() {
175175
}
176176
}
177177
this.ex.shutdown();
178-
PluginState.finishUpload();
179178
}
180179
}
181180

src/org/openstreetmap/josm/plugins/mapillary/utils/PluginState.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class PluginState {
1717

1818
private static int runningDownloads = 0;
1919
/** Images that have to be uploaded. */
20-
public static int imagesToUpload = 0;
20+
protected static int imagesToUpload = 0;
2121
/** Images that have been uploaded. */
2222
public static int imagesUploaded = 0;
2323

@@ -32,6 +32,9 @@ public static void startDownload() {
3232
* Called when a download is finished.
3333
*/
3434
public static void finishDownload() {
35+
if (runningDownloads == 0)
36+
throw new IllegalStateException(
37+
"The amount of running downlaods is less or equals to 0");
3538
runningDownloads--;
3639
}
3740

@@ -44,16 +47,6 @@ public static boolean isDownloading() {
4447
return runningDownloads > 0;
4548
}
4649

47-
/**
48-
* Called when an upload is finished.
49-
*/
50-
public static void finishUpload() {
51-
if (imagesUploaded >= imagesToUpload) {
52-
imagesUploaded = 0;
53-
imagesToUpload = 0;
54-
}
55-
}
56-
5750
/**
5851
* Checks if there is any running upload.
5952
*
@@ -70,6 +63,10 @@ public static boolean isUploading() {
7063
* The amount of images that are going to be uploaded.
7164
*/
7265
public static void imagesToUpload(int amount) {
66+
if (imagesToUpload <= imagesUploaded) {
67+
imagesToUpload = 0;
68+
imagesUploaded = 0;
69+
}
7370
imagesToUpload += amount;
7471
}
7572

@@ -79,7 +76,8 @@ public static void imagesToUpload(int amount) {
7976
public static void imageUploaded() {
8077
imagesUploaded++;
8178
if (imagesToUpload == imagesUploaded) {
82-
finishedUploadDialog();
79+
if (Main.main != null)
80+
finishedUploadDialog();
8381
}
8482
}
8583

test/unit/org/openstreetmap/josm/plugins/mapillary/commands/MapillaryRecordTest.java

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,23 @@ public void setUp() {
4040
*/
4141
@Test
4242
public void commandTest() {
43-
MapillaryCommand cmd1 = new CommandMoveImage(
43+
MapillaryCommand cmd12 = new CommandMoveImage(
4444
Arrays.asList(new MapillaryAbstractImage[] { this.img1, this.img2 }),
4545
0.1, 0.1);
46-
MapillaryCommand cmd2 = new CommandMoveImage(
46+
MapillaryCommand cmd23 = new CommandMoveImage(
4747
Arrays.asList(new MapillaryAbstractImage[] { this.img2, this.img3 }),
4848
0.1, 0.1);
49-
MapillaryCommand cmd3 = new CommandMoveImage(
49+
MapillaryCommand cmd13 = new CommandMoveImage(
5050
Arrays.asList(new MapillaryAbstractImage[] { this.img1, this.img3 }),
5151
0.1, 0.1);
52+
MapillaryCommand cmd1 = new CommandMoveImage(
53+
Arrays.asList(new MapillaryAbstractImage[] { this.img1 }),
54+
0.1, 0.1);
5255
MapillaryCommand cmd31 = new CommandMoveImage(
5356
Arrays.asList(new MapillaryAbstractImage[] { this.img3, this.img1 }),
5457
0.2, 0.2);
55-
this.record.addCommand(cmd1);
56-
this.record.addCommand(cmd2);
58+
this.record.addCommand(cmd12);
59+
this.record.addCommand(cmd23);
5760

5861
assertEquals(1, this.record.position);
5962
assertEquals(2, this.record.commandList.size());
@@ -63,21 +66,30 @@ public void commandTest() {
6366
assertEquals(0, this.record.position);
6467
assertEquals(2, this.record.commandList.size());
6568

66-
this.record.addCommand(cmd3);
69+
this.record.addCommand(cmd1);
6770

6871
assertEquals(1, this.record.position);
69-
assertEquals(2, this.record.commandList.size());
72+
73+
this.record.addCommand(cmd13);
74+
75+
assertEquals(2, this.record.position);
76+
assertEquals(3, this.record.commandList.size());
7077

7178
this.record.undo();
7279
this.record.redo();
7380

74-
assertEquals(1, this.record.position);
75-
assertEquals(2, this.record.commandList.size());
81+
assertEquals(2, this.record.position);
82+
assertEquals(3, this.record.commandList.size());
7683

7784
this.record.addCommand(cmd31);
7885

79-
assertEquals(1, this.record.position);
80-
assertEquals(2, this.record.commandList.size());
86+
assertEquals(2, this.record.position);
87+
assertEquals(3, this.record.commandList.size());
88+
89+
this.record.addCommand(cmd1);
90+
91+
assertEquals(3, this.record.position);
92+
assertEquals(4, this.record.commandList.size());
8193
}
8294

8395
/**
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package org.openstreetmap.josm.plugins.mapillary.utils;
2+
3+
import static org.junit.Assert.assertEquals;
4+
5+
import org.junit.Test;
6+
7+
/**
8+
* Tests {@link PluginState} class.
9+
*
10+
* @author nokutu
11+
* @see PluginState
12+
*/
13+
public class PluginStateTest {
14+
15+
/**
16+
* Test the methods related to the download.
17+
*/
18+
@Test
19+
public void downloadTest() {
20+
assertEquals(false, PluginState.isDownloading());
21+
PluginState.startDownload();
22+
assertEquals(true, PluginState.isDownloading());
23+
PluginState.startDownload();
24+
assertEquals(true, PluginState.isDownloading());
25+
PluginState.finishDownload();
26+
assertEquals(true, PluginState.isDownloading());
27+
PluginState.finishDownload();
28+
assertEquals(false, PluginState.isDownloading());
29+
}
30+
31+
/**
32+
* Tests the methods related to the upload.
33+
*/
34+
@Test
35+
public void uploadTest() {
36+
assertEquals(false, PluginState.isUploading());
37+
PluginState.imagesToUpload(2);
38+
assertEquals(2, PluginState.imagesToUpload);
39+
assertEquals(0, PluginState.imagesUploaded);
40+
assertEquals(true, PluginState.isUploading());
41+
PluginState.imageUploaded();
42+
assertEquals(1, PluginState.imagesUploaded);
43+
assertEquals(true, PluginState.isUploading());
44+
PluginState.imageUploaded();
45+
assertEquals(false, PluginState.isUploading());
46+
assertEquals(0, PluginState.imagesToUpload);
47+
assertEquals(0, PluginState.imagesUploaded);
48+
}
49+
}

0 commit comments

Comments
 (0)