1   /*
2    * Copyright 2002-2006 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.springframework.richclient.progress;
17  
18  import javax.swing.JProgressBar;
19  
20  import junit.framework.TestCase;
21  
22  /**
23   * @author Peter De Bruycker
24   */
25  public class ProgressBarProgressMonitorTests extends TestCase {
26      public void testConstructorWithNullArgumentThrowsException() {
27          try {
28              new ProgressBarProgressMonitor(null);
29              fail("Should throw IllegalArgumentException");
30          }
31          catch (IllegalArgumentException e) {
32              // test passes
33          }
34      }
35  
36      public void testConstructor() {
37          JProgressBar progressBar = new JProgressBar();
38          ProgressBarProgressMonitor monitor = new ProgressBarProgressMonitor(progressBar);
39  
40          assertSame(progressBar, monitor.getProgressBar());
41      }
42  
43      public void testProgress() {
44          JProgressBar progressBar = new JProgressBar();
45          progressBar.setIndeterminate(true);
46  
47          ProgressBarProgressMonitor monitor = new ProgressBarProgressMonitor(progressBar);
48          assertTrue(progressBar.isIndeterminate());
49  
50          monitor.taskStarted("main-task", 50);
51          assertEquals("main-task", progressBar.getString());
52          assertEquals(0, progressBar.getMinimum());
53          assertEquals(50, progressBar.getMaximum());
54  
55          monitor.subTaskStarted("sub-task 1");
56          assertEquals("sub-task 1", progressBar.getString());
57  
58          monitor.worked(5);
59          assertEquals(5, progressBar.getValue());
60  
61          monitor.worked(10);
62          assertEquals(15, progressBar.getValue());
63      }
64  }