better percentage values from Progressmonitor
authorAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Mon, 12 Sep 2016 13:28:35 +0000 (15:28 +0200)
committerAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Mon, 12 Sep 2016 13:28:35 +0000 (15:28 +0200)
cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/monitor/DefaultProgressMonitor.java
cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/monitor/IRestServiceProgressMonitor.java
cdmlib-commons/src/test/java/eu/etaxonomy/cdm/common/ProgresMonitorTest.java [new file with mode: 0644]

index a030962f1c1d0e671a3d57a34b3b5811efe0ec15..d244ba83a7e19de08ae87c50936a63505d3a12c2 100644 (file)
@@ -144,7 +144,9 @@ public class DefaultProgressMonitor implements IProgressMonitor {
         if(totalWork == 0 ){
             return null;
         }
+
         double result = this.workDone * 100 / this.totalWork ;
+        result = Math.ceil((result * 100.0)) / 100.0;
         return result;
     }
 
index 20f98190ffc9f6057aa8058a33505d0c81b660af..ca7f89d069f3bc457a80945320bd4dd5ec7c2b8d 100644 (file)
@@ -9,7 +9,9 @@ public interface IRestServiceProgressMonitor extends IProgressMonitor{
     public String getSubTask();
 
     /**
-     * @return the percentage of the work done, or <code>null</code> in case the <code>totalWork</code> was <code>0</code>.
+     * @return the percentage with an accuracy of two decimal digits
+     * of the work done, or <code>null</code>
+     * in case the <code>totalWork</code> was <code>0</code>.
      */
     public Double getPercentage();
 
diff --git a/cdmlib-commons/src/test/java/eu/etaxonomy/cdm/common/ProgresMonitorTest.java b/cdmlib-commons/src/test/java/eu/etaxonomy/cdm/common/ProgresMonitorTest.java
new file mode 100644 (file)
index 0000000..672613a
--- /dev/null
@@ -0,0 +1,32 @@
+// $Id$
+/**
+* Copyright (C) 2016 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.cdm.common;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import eu.etaxonomy.cdm.common.monitor.DefaultProgressMonitor;
+
+/**
+ * @author a.kohlbecker
+ * @date Sep 12, 2016
+ *
+ */
+public class ProgresMonitorTest extends Assert {
+
+    @Test
+    public void testPercentage() {
+        DefaultProgressMonitor monitor = DefaultProgressMonitor.NewInstance();
+        monitor.beginTask("test", 33);
+        monitor.worked(5);
+        assertEquals(Double.valueOf(15.16), Double.valueOf(monitor.getPercentage()));
+    }
+
+}