modules/graphics/src/test/java/test/javafx/concurrent/TaskProgressTest.java

Print this page
rev 9250 : 8134762: Refactor Javafx graphics module tests for clear separation of tests
Reviewed-by:


   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javafx.concurrent;
  27 
  28 import javafx.concurrent.mocks.ProgressingTask;


  29 import org.junit.Before;
  30 import org.junit.Test;
  31 
  32 import static org.junit.Assert.*;
  33 
  34 /**
  35  * A Task which always completes normally, but which also progresses from
  36  * 0 to 20 (inclusive). Initially the indeterminate state is used for
  37  * progress and maxProgress, but during execution the progress and
  38  * maxProgress are updated.
  39  */
  40 public class TaskProgressTest {
  41     private Task task;
  42 
  43     @Before public void setup() {
  44         task = new ProgressingTask();
  45     }
  46 
  47     /************************************************************************
  48      * Run the task and check that the final progress and maxProgress and


  53         task.run();
  54         assertEquals(20, task.getWorkDone(), 0);
  55     }
  56 
  57     @Test public void afterRunningTotalWorkShouldBe_20() {
  58         task.run();
  59         assertEquals(20, task.getTotalWork(), 0);
  60     }
  61 
  62     @Test public void afterRunningProgressShouldBe_1() {
  63         task.run();
  64         assertEquals(1, task.getProgress(), 0);
  65     }
  66 
  67     /************************************************************************
  68      * Test the updateProgress method on Task, that various inputs lead to
  69      * expected outputs according to the specification
  70      ***********************************************************************/
  71 
  72     @Test public void updateProgress_Long_0_100() {
  73         task.updateProgress(0, 100);
  74         assertEquals(0, task.getProgress(), 0);
  75         assertEquals(0, task.getWorkDone(), 0);
  76         assertEquals(100, task.getTotalWork(), 0);
  77     }
  78 
  79     @Test public void updateProgress_Long_n1_100() {
  80         task.updateProgress(-1, 100);
  81         assertEquals(-1, task.getProgress(), 0);
  82         assertEquals(-1, task.getWorkDone(), 0);
  83         assertEquals(100, task.getTotalWork(), 0);
  84     }
  85 
  86     @Test public void updateProgress_Long_n10_100() {
  87         task.updateProgress(-10, 100);
  88         assertEquals(-1, task.getProgress(), 0);
  89         assertEquals(-1, task.getWorkDone(), 0);
  90         assertEquals(100, task.getTotalWork(), 0);
  91     }
  92 
  93     @Test public void updateProgress_Long_MIN_VALUE_100() {
  94         task.updateProgress(Long.MIN_VALUE, 100);
  95         assertEquals(-1, task.getProgress(), 0);
  96         assertEquals(-1, task.getWorkDone(), 0);
  97         assertEquals(100, task.getTotalWork(), 0);
  98     }
  99 
 100     @Test public void updateProgress_Long_10_100() {
 101         task.updateProgress(10, 100);
 102         assertEquals(.1, task.getProgress(), 0);
 103         assertEquals(10, task.getWorkDone(), 0);
 104         assertEquals(100, task.getTotalWork(), 0);
 105     }
 106 
 107     @Test public void updateProgress_Long_100_100() {
 108         task.updateProgress(100, 100);
 109         assertEquals(1, task.getProgress(), 0);
 110         assertEquals(100, task.getWorkDone(), 0);
 111         assertEquals(100, task.getTotalWork(), 0);
 112     }
 113 
 114     @Test public void updateProgress_Long_110_100() {
 115         task.updateProgress(110, 100);
 116         assertEquals(1, task.getProgress(), 0);
 117         assertEquals(100, task.getWorkDone(), 0);
 118         assertEquals(100, task.getTotalWork(), 0);
 119     }
 120 
 121     @Test public void updateProgress_Long_MAX_VALUE_100() {
 122         task.updateProgress(Long.MAX_VALUE, 100);
 123         assertEquals(1, task.getProgress(), 0);
 124         assertEquals(100, task.getWorkDone(), 0);
 125         assertEquals(100, task.getTotalWork(), 0);
 126     }
 127 
 128     @Test public void updateProgress_Long_0_n1() {
 129         task.updateProgress(0, -1);
 130         assertEquals(-1, task.getProgress(), 0);
 131         assertEquals(-1, task.getWorkDone(), 0);
 132         assertEquals(-1, task.getTotalWork(), 0);
 133     }
 134 
 135     @Test public void updateProgress_Long_0_n10() {
 136         task.updateProgress(0, -10);
 137         assertEquals(-1, task.getProgress(), 0);
 138         assertEquals(-1, task.getWorkDone(), 0);
 139         assertEquals(-1, task.getTotalWork(), 0);
 140     }
 141 
 142     @Test public void updateProgress_Long_0_MIN_VALUE() {
 143         task.updateProgress(0, Long.MIN_VALUE);
 144         assertEquals(-1, task.getProgress(), 0);
 145         assertEquals(-1, task.getWorkDone(), 0);
 146         assertEquals(-1, task.getTotalWork(), 0);
 147     }
 148 
 149     @Test public void updateProgress_Long_100_10() {
 150         task.updateProgress(100, 10);
 151         assertEquals(1, task.getProgress(), 0);
 152         assertEquals(10, task.getWorkDone(), 0);
 153         assertEquals(10, task.getTotalWork(), 0);
 154     }
 155 
 156     @Test public void updateProgress_Long_100_MAX_VALUE() {
 157         task.updateProgress(100, Long.MAX_VALUE);
 158         assertEquals(100.0 / Long.MAX_VALUE, task.getProgress(), 0);
 159         assertEquals(100, task.getWorkDone(), 0);
 160         assertEquals(Long.MAX_VALUE, task.getTotalWork(), 0);
 161     }
 162 
 163     /* Now test the Double variants (Infinity, NaN)*/
 164     @Test public void updateProgress_Double_Infinity_100() {
 165         task.updateProgress(Double.POSITIVE_INFINITY, 100);
 166         assertEquals(-1, task.getProgress(), 0);
 167         assertEquals(-1, task.getWorkDone(), 0);
 168         assertEquals(100, task.getTotalWork(), 0);
 169     }
 170 
 171     @Test public void updateProgress_Double_NInfinity_100() {
 172         task.updateProgress(Double.NEGATIVE_INFINITY, 100);
 173         assertEquals(-1, task.getProgress(), 0);
 174         assertEquals(-1, task.getWorkDone(), 0);
 175         assertEquals(100, task.getTotalWork(), 0);
 176     }
 177 
 178     @Test public void updateProgress_Double_NaN_100() {
 179         task.updateProgress(Double.NaN, 100);
 180         assertEquals(-1, task.getProgress(), 0);
 181         assertEquals(-1, task.getWorkDone(), 0);
 182         assertEquals(100, task.getTotalWork(), 0);
 183     }
 184 
 185     @Test public void updateProgress_Double_0_Infinity() {
 186         task.updateProgress(0, Double.POSITIVE_INFINITY);
 187         assertEquals(-1, task.getProgress(), 0);
 188         assertEquals(-1, task.getWorkDone(), 0);
 189         assertEquals(-1, task.getTotalWork(), 0);
 190     }
 191 
 192     @Test public void updateProgress_Double_0_NInfinity() {
 193         task.updateProgress(0, Double.NEGATIVE_INFINITY);
 194         assertEquals(-1, task.getProgress(), 0);
 195         assertEquals(-1, task.getWorkDone(), 0);
 196         assertEquals(-1, task.getTotalWork(), 0);
 197     }
 198 
 199     @Test public void updateProgress_Double_0_NaN() {
 200         task.updateProgress(0, Double.NaN);
 201         assertEquals(-1, task.getProgress(), 0);
 202         assertEquals(-1, task.getWorkDone(), 0);
 203         assertEquals(-1, task.getTotalWork(), 0);
 204     }
 205 
 206     @Test public void updateProgress_Double_Infinity_Infinity() {
 207         task.updateProgress(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY);
 208         assertEquals(-1, task.getProgress(), 0);
 209         assertEquals(-1, task.getWorkDone(), 0);
 210         assertEquals(-1, task.getTotalWork(), 0);
 211     }
 212 
 213     @Test public void updateProgress_Double_NInfinity_Infinity() {
 214         task.updateProgress(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
 215         assertEquals(-1, task.getProgress(), 0);
 216         assertEquals(-1, task.getWorkDone(), 0);
 217         assertEquals(-1, task.getTotalWork(), 0);
 218     }
 219 
 220     @Test public void updateProgress_Double_Infinity_NInfinity() {
 221         task.updateProgress(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY);
 222         assertEquals(-1, task.getProgress(), 0);
 223         assertEquals(-1, task.getWorkDone(), 0);
 224         assertEquals(-1, task.getTotalWork(), 0);
 225     }
 226 
 227     @Test public void updateProgress_Double_NInfinity_NInfinity() {
 228         task.updateProgress(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY);
 229         assertEquals(-1, task.getProgress(), 0);
 230         assertEquals(-1, task.getWorkDone(), 0);
 231         assertEquals(-1, task.getTotalWork(), 0);
 232     }
 233 
 234     @Test public void updateProgress_Double_Infinity_NaN() {
 235         task.updateProgress(Double.POSITIVE_INFINITY, Double.NaN);
 236         assertEquals(-1, task.getProgress(), 0);
 237         assertEquals(-1, task.getWorkDone(), 0);
 238         assertEquals(-1, task.getTotalWork(), 0);
 239     }
 240 
 241     @Test public void updateProgress_Double_NInfinity_NaN() {
 242         task.updateProgress(Double.NEGATIVE_INFINITY, Double.NaN);
 243         assertEquals(-1, task.getProgress(), 0);
 244         assertEquals(-1, task.getWorkDone(), 0);
 245         assertEquals(-1, task.getTotalWork(), 0);
 246     }
 247 
 248     @Test public void updateProgress_Double_NaN_Infinity() {
 249         task.updateProgress(Double.NaN, Double.POSITIVE_INFINITY);
 250         assertEquals(-1, task.getProgress(), 0);
 251         assertEquals(-1, task.getWorkDone(), 0);
 252         assertEquals(-1, task.getTotalWork(), 0);
 253     }
 254 
 255     @Test public void updateProgress_Double_NaN_NInfinity() {
 256         task.updateProgress(Double.NaN, Double.NEGATIVE_INFINITY);
 257         assertEquals(-1, task.getProgress(), 0);
 258         assertEquals(-1, task.getWorkDone(), 0);
 259         assertEquals(-1, task.getTotalWork(), 0);
 260     }
 261 
 262     @Test public void updateProgress_Double_NaN_NaN() {
 263         task.updateProgress(Double.NaN, Double.NaN);
 264         assertEquals(-1, task.getProgress(), 0);
 265         assertEquals(-1, task.getWorkDone(), 0);
 266         assertEquals(-1, task.getTotalWork(), 0);
 267     }
 268 }


   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package test.javafx.concurrent;
  27 
  28 import javafx.concurrent.Task;
  29 import javafx.concurrent.TaskShim;
  30 import test.javafx.concurrent.mocks.ProgressingTask;
  31 import org.junit.Before;
  32 import org.junit.Test;
  33 
  34 import static org.junit.Assert.*;
  35 
  36 /**
  37  * A Task which always completes normally, but which also progresses from
  38  * 0 to 20 (inclusive). Initially the indeterminate state is used for
  39  * progress and maxProgress, but during execution the progress and
  40  * maxProgress are updated.
  41  */
  42 public class TaskProgressTest {
  43     private Task task;
  44 
  45     @Before public void setup() {
  46         task = new ProgressingTask();
  47     }
  48 
  49     /************************************************************************
  50      * Run the task and check that the final progress and maxProgress and


  55         task.run();
  56         assertEquals(20, task.getWorkDone(), 0);
  57     }
  58 
  59     @Test public void afterRunningTotalWorkShouldBe_20() {
  60         task.run();
  61         assertEquals(20, task.getTotalWork(), 0);
  62     }
  63 
  64     @Test public void afterRunningProgressShouldBe_1() {
  65         task.run();
  66         assertEquals(1, task.getProgress(), 0);
  67     }
  68 
  69     /************************************************************************
  70      * Test the updateProgress method on Task, that various inputs lead to
  71      * expected outputs according to the specification
  72      ***********************************************************************/
  73 
  74     @Test public void updateProgress_Long_0_100() {
  75         TaskShim.updateProgress(task, 0, 100);
  76         assertEquals(0, task.getProgress(), 0);
  77         assertEquals(0, task.getWorkDone(), 0);
  78         assertEquals(100, task.getTotalWork(), 0);
  79     }
  80 
  81     @Test public void updateProgress_Long_n1_100() {
  82         TaskShim.updateProgress(task, -1, 100);
  83         assertEquals(-1, task.getProgress(), 0);
  84         assertEquals(-1, task.getWorkDone(), 0);
  85         assertEquals(100, task.getTotalWork(), 0);
  86     }
  87 
  88     @Test public void updateProgress_Long_n10_100() {
  89         TaskShim.updateProgress(task, -10, 100);
  90         assertEquals(-1, task.getProgress(), 0);
  91         assertEquals(-1, task.getWorkDone(), 0);
  92         assertEquals(100, task.getTotalWork(), 0);
  93     }
  94 
  95     @Test public void updateProgress_Long_MIN_VALUE_100() {
  96         TaskShim.updateProgress(task, Long.MIN_VALUE, 100);
  97         assertEquals(-1, task.getProgress(), 0);
  98         assertEquals(-1, task.getWorkDone(), 0);
  99         assertEquals(100, task.getTotalWork(), 0);
 100     }
 101 
 102     @Test public void updateProgress_Long_10_100() {
 103         TaskShim.updateProgress(task, 10, 100);
 104         assertEquals(.1, task.getProgress(), 0);
 105         assertEquals(10, task.getWorkDone(), 0);
 106         assertEquals(100, task.getTotalWork(), 0);
 107     }
 108 
 109     @Test public void updateProgress_Long_100_100() {
 110         TaskShim.updateProgress(task, 100, 100);
 111         assertEquals(1, task.getProgress(), 0);
 112         assertEquals(100, task.getWorkDone(), 0);
 113         assertEquals(100, task.getTotalWork(), 0);
 114     }
 115 
 116     @Test public void updateProgress_Long_110_100() {
 117         TaskShim.updateProgress(task, 110, 100);
 118         assertEquals(1, task.getProgress(), 0);
 119         assertEquals(100, task.getWorkDone(), 0);
 120         assertEquals(100, task.getTotalWork(), 0);
 121     }
 122 
 123     @Test public void updateProgress_Long_MAX_VALUE_100() {
 124         TaskShim.updateProgress(task, Long.MAX_VALUE, 100);
 125         assertEquals(1, task.getProgress(), 0);
 126         assertEquals(100, task.getWorkDone(), 0);
 127         assertEquals(100, task.getTotalWork(), 0);
 128     }
 129 
 130     @Test public void updateProgress_Long_0_n1() {
 131         TaskShim.updateProgress(task, 0, -1);
 132         assertEquals(-1, task.getProgress(), 0);
 133         assertEquals(-1, task.getWorkDone(), 0);
 134         assertEquals(-1, task.getTotalWork(), 0);
 135     }
 136 
 137     @Test public void updateProgress_Long_0_n10() {
 138         TaskShim.updateProgress(task, 0, -10);
 139         assertEquals(-1, task.getProgress(), 0);
 140         assertEquals(-1, task.getWorkDone(), 0);
 141         assertEquals(-1, task.getTotalWork(), 0);
 142     }
 143 
 144     @Test public void updateProgress_Long_0_MIN_VALUE() {
 145         TaskShim.updateProgress(task, 0, Long.MIN_VALUE);
 146         assertEquals(-1, task.getProgress(), 0);
 147         assertEquals(-1, task.getWorkDone(), 0);
 148         assertEquals(-1, task.getTotalWork(), 0);
 149     }
 150 
 151     @Test public void updateProgress_Long_100_10() {
 152         TaskShim.updateProgress(task, 100, 10);
 153         assertEquals(1, task.getProgress(), 0);
 154         assertEquals(10, task.getWorkDone(), 0);
 155         assertEquals(10, task.getTotalWork(), 0);
 156     }
 157 
 158     @Test public void updateProgress_Long_100_MAX_VALUE() {
 159         TaskShim.updateProgress(task, 100, Long.MAX_VALUE);
 160         assertEquals(100.0 / Long.MAX_VALUE, task.getProgress(), 0);
 161         assertEquals(100, task.getWorkDone(), 0);
 162         assertEquals(Long.MAX_VALUE, task.getTotalWork(), 0);
 163     }
 164 
 165     /* Now test the Double variants (Infinity, NaN)*/
 166     @Test public void updateProgress_Double_Infinity_100() {
 167         TaskShim.updateProgress(task, Double.POSITIVE_INFINITY, 100);
 168         assertEquals(-1, task.getProgress(), 0);
 169         assertEquals(-1, task.getWorkDone(), 0);
 170         assertEquals(100, task.getTotalWork(), 0);
 171     }
 172 
 173     @Test public void updateProgress_Double_NInfinity_100() {
 174         TaskShim.updateProgress(task, Double.NEGATIVE_INFINITY, 100);
 175         assertEquals(-1, task.getProgress(), 0);
 176         assertEquals(-1, task.getWorkDone(), 0);
 177         assertEquals(100, task.getTotalWork(), 0);
 178     }
 179 
 180     @Test public void updateProgress_Double_NaN_100() {
 181         TaskShim.updateProgress(task, Double.NaN, 100);
 182         assertEquals(-1, task.getProgress(), 0);
 183         assertEquals(-1, task.getWorkDone(), 0);
 184         assertEquals(100, task.getTotalWork(), 0);
 185     }
 186 
 187     @Test public void updateProgress_Double_0_Infinity() {
 188         TaskShim.updateProgress(task, 0, Double.POSITIVE_INFINITY);
 189         assertEquals(-1, task.getProgress(), 0);
 190         assertEquals(-1, task.getWorkDone(), 0);
 191         assertEquals(-1, task.getTotalWork(), 0);
 192     }
 193 
 194     @Test public void updateProgress_Double_0_NInfinity() {
 195         TaskShim.updateProgress(task, 0, Double.NEGATIVE_INFINITY);
 196         assertEquals(-1, task.getProgress(), 0);
 197         assertEquals(-1, task.getWorkDone(), 0);
 198         assertEquals(-1, task.getTotalWork(), 0);
 199     }
 200 
 201     @Test public void updateProgress_Double_0_NaN() {
 202         TaskShim.updateProgress(task, 0, Double.NaN);
 203         assertEquals(-1, task.getProgress(), 0);
 204         assertEquals(-1, task.getWorkDone(), 0);
 205         assertEquals(-1, task.getTotalWork(), 0);
 206     }
 207 
 208     @Test public void updateProgress_Double_Infinity_Infinity() {
 209         TaskShim.updateProgress(task, Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY);
 210         assertEquals(-1, task.getProgress(), 0);
 211         assertEquals(-1, task.getWorkDone(), 0);
 212         assertEquals(-1, task.getTotalWork(), 0);
 213     }
 214 
 215     @Test public void updateProgress_Double_NInfinity_Infinity() {
 216         TaskShim.updateProgress(task, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
 217         assertEquals(-1, task.getProgress(), 0);
 218         assertEquals(-1, task.getWorkDone(), 0);
 219         assertEquals(-1, task.getTotalWork(), 0);
 220     }
 221 
 222     @Test public void updateProgress_Double_Infinity_NInfinity() {
 223         TaskShim.updateProgress(task, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY);
 224         assertEquals(-1, task.getProgress(), 0);
 225         assertEquals(-1, task.getWorkDone(), 0);
 226         assertEquals(-1, task.getTotalWork(), 0);
 227     }
 228 
 229     @Test public void updateProgress_Double_NInfinity_NInfinity() {
 230         TaskShim.updateProgress(task, Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY);
 231         assertEquals(-1, task.getProgress(), 0);
 232         assertEquals(-1, task.getWorkDone(), 0);
 233         assertEquals(-1, task.getTotalWork(), 0);
 234     }
 235 
 236     @Test public void updateProgress_Double_Infinity_NaN() {
 237         TaskShim.updateProgress(task, Double.POSITIVE_INFINITY, Double.NaN);
 238         assertEquals(-1, task.getProgress(), 0);
 239         assertEquals(-1, task.getWorkDone(), 0);
 240         assertEquals(-1, task.getTotalWork(), 0);
 241     }
 242 
 243     @Test public void updateProgress_Double_NInfinity_NaN() {
 244         TaskShim.updateProgress(task, Double.NEGATIVE_INFINITY, Double.NaN);
 245         assertEquals(-1, task.getProgress(), 0);
 246         assertEquals(-1, task.getWorkDone(), 0);
 247         assertEquals(-1, task.getTotalWork(), 0);
 248     }
 249 
 250     @Test public void updateProgress_Double_NaN_Infinity() {
 251         TaskShim.updateProgress(task, Double.NaN, Double.POSITIVE_INFINITY);
 252         assertEquals(-1, task.getProgress(), 0);
 253         assertEquals(-1, task.getWorkDone(), 0);
 254         assertEquals(-1, task.getTotalWork(), 0);
 255     }
 256 
 257     @Test public void updateProgress_Double_NaN_NInfinity() {
 258         TaskShim.updateProgress(task, Double.NaN, Double.NEGATIVE_INFINITY);
 259         assertEquals(-1, task.getProgress(), 0);
 260         assertEquals(-1, task.getWorkDone(), 0);
 261         assertEquals(-1, task.getTotalWork(), 0);
 262     }
 263 
 264     @Test public void updateProgress_Double_NaN_NaN() {
 265         TaskShim.updateProgress(task, Double.NaN, Double.NaN);
 266         assertEquals(-1, task.getProgress(), 0);
 267         assertEquals(-1, task.getWorkDone(), 0);
 268         assertEquals(-1, task.getTotalWork(), 0);
 269     }
 270 }