Project

General

Profile

« Previous | Next » 

Revision 1ec5d31b

Added by Andreas Kohlbecker over 7 years ago

better percentage values from Progressmonitor

View differences:

cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/monitor/DefaultProgressMonitor.java
144 144
        if(totalWork == 0 ){
145 145
            return null;
146 146
        }
147

  
147 148
        double result = this.workDone * 100 / this.totalWork ;
149
        result = Math.ceil((result * 100.0)) / 100.0;
148 150
        return result;
149 151
    }
150 152

  
cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/monitor/IRestServiceProgressMonitor.java
9 9
    public String getSubTask();
10 10

  
11 11
    /**
12
     * @return the percentage of the work done, or <code>null</code> in case the <code>totalWork</code> was <code>0</code>.
12
     * @return the percentage with an accuracy of two decimal digits
13
     * of the work done, or <code>null</code>
14
     * in case the <code>totalWork</code> was <code>0</code>.
13 15
     */
14 16
    public Double getPercentage();
15 17

  
cdmlib-commons/src/test/java/eu/etaxonomy/cdm/common/ProgresMonitorTest.java
1
// $Id$
2
/**
3
* Copyright (C) 2016 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.cdm.common;
11

  
12
import org.junit.Assert;
13
import org.junit.Test;
14

  
15
import eu.etaxonomy.cdm.common.monitor.DefaultProgressMonitor;
16

  
17
/**
18
 * @author a.kohlbecker
19
 * @date Sep 12, 2016
20
 *
21
 */
22
public class ProgresMonitorTest extends Assert {
23

  
24
    @Test
25
    public void testPercentage() {
26
        DefaultProgressMonitor monitor = DefaultProgressMonitor.NewInstance();
27
        monitor.beginTask("test", 33);
28
        monitor.worked(5);
29
        assertEquals(Double.valueOf(15.16), Double.valueOf(monitor.getPercentage()));
30
    }
31

  
32
}

Also available in: Unified diff