001 /* 002 * Copyright 2002-2006 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.springframework.richclient.progress; 017 018 import javax.swing.JProgressBar; 019 020 import junit.framework.TestCase; 021 022 /** 023 * @author Peter De Bruycker 024 */ 025 public class ProgressBarProgressMonitorTests extends TestCase { 026 public void testConstructorWithNullArgumentThrowsException() { 027 try { 028 new ProgressBarProgressMonitor(null); 029 fail("Should throw IllegalArgumentException"); 030 } 031 catch (IllegalArgumentException e) { 032 // test passes 033 } 034 } 035 036 public void testConstructor() { 037 JProgressBar progressBar = new JProgressBar(); 038 ProgressBarProgressMonitor monitor = new ProgressBarProgressMonitor(progressBar); 039 040 assertSame(progressBar, monitor.getProgressBar()); 041 } 042 043 public void testProgress() { 044 JProgressBar progressBar = new JProgressBar(); 045 progressBar.setIndeterminate(true); 046 047 ProgressBarProgressMonitor monitor = new ProgressBarProgressMonitor(progressBar); 048 assertTrue(progressBar.isIndeterminate()); 049 050 monitor.taskStarted("main-task", 50); 051 assertEquals("main-task", progressBar.getString()); 052 assertEquals(0, progressBar.getMinimum()); 053 assertEquals(50, progressBar.getMaximum()); 054 055 monitor.subTaskStarted("sub-task 1"); 056 assertEquals("sub-task 1", progressBar.getString()); 057 058 monitor.worked(5); 059 assertEquals(5, progressBar.getValue()); 060 061 monitor.worked(10); 062 assertEquals(15, progressBar.getValue()); 063 } 064 }