View Javadoc
1 /* 2 * Scope: a generic MVC framework. 3 * Copyright (c) 2000-2002, The Scope team 4 * All rights reserved. 5 * 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 14 * Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * Neither the name "Scope" nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR 27 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 * 35 * 36 * $Id: TestSModelButton.java,v 1.1 2002/09/13 17:12:12 ludovicc Exp $ 37 */ 38 package test.view.swing; 39 40 import java.lang.Integer; 41 import junit.framework.TestCase; 42 import org.scopemvc.core.Control; 43 import org.scopemvc.core.Selector; 44 import org.scopemvc.view.swing.SModelButton; 45 import org.scopemvc.view.swing.SPanel; 46 47 /*** 48 * TODO: document the class 49 * 50 * @author <a href="mailto:ludovicc@users.sourceforge.net>;Ludovic Claude</a> 51 * @created 12 September 2002 52 */ 53 54 public class TestSModelButton extends TestCase { 55 56 private SwingDummyModel model; 57 private SModelButton button; 58 private SwingDummyController controller; 59 private SPanel panel; 60 61 /*** 62 * Constructor for the TestSModelButton object 63 * 64 * @param inName Name of the test 65 */ 66 public TestSModelButton(String inName) { 67 super(inName); 68 } 69 70 /*** 71 * A unit test for JUnit 72 * 73 * @throws Exception Any abnormal exception 74 */ 75 public void testControl() throws Exception { 76 button = new SModelButton("Test", Selector.fromString("stringProperty")); 77 panel.add(button); 78 controller.setModel(model); 79 80 assertEquals("Test", button.getText()); 81 SuiteViewSwing.waitForAWT(); 82 assertTrue(button.isEnabled()); 83 84 button.doClick(); 85 SuiteViewSwing.waitForAWT(); 86 assertEquals(new Control("Test", model.getStringProperty()), controller.lastControl); 87 } 88 89 /*** 90 * A unit test for JUnit 91 * 92 * @throws Exception Any abnormal exception 93 */ 94 public void testDisabledControl() throws Exception { 95 button = new SModelButton("Test", Selector.fromString("stringProperty")); 96 panel.add(button); 97 controller.setModel(model); 98 99 model.setStringProperty(null); 100 SuiteViewSwing.waitForAWT(); 101 assertTrue(!button.isEnabled()); 102 103 model.setStringProperty("notnull"); 104 SuiteViewSwing.waitForAWT(); 105 assertTrue(button.isEnabled()); 106 } 107 108 /*** 109 * A unit test for JUnit 110 * 111 * @throws Exception Any abnormal exception 112 */ 113 public void testValueTest() throws Exception { 114 button = new SModelButton("Test", Selector.fromString("intProperty")); 115 panel.add(button); 116 controller.setModel(model); 117 118 // should be enabled if the bound value is an integer less than 1 119 button.setValueTest(new Integer(1)); 120 121 model.setIntProperty(0); 122 SuiteViewSwing.waitForAWT(); 123 assertTrue(button.isEnabled()); 124 125 model.setIntProperty(1); 126 SuiteViewSwing.waitForAWT(); 127 assertTrue(!button.isEnabled()); 128 129 model.setIntProperty(2); 130 SuiteViewSwing.waitForAWT(); 131 assertTrue(!button.isEnabled()); 132 133 } 134 135 /*** 136 * The JUnit setup method 137 * 138 * @throws Exception Any abnormal exception 139 */ 140 protected void setUp() throws Exception { 141 142 model = new SwingDummyModel(); 143 panel = new SPanel(); 144 145 controller = new SwingDummyController(); 146 controller.setView(panel); 147 148 controller.startup(); 149 } 150 151 152 /*** 153 * The teardown method for JUnit 154 */ 155 protected void tearDown() { 156 controller.shutdown(); 157 } 158 159 }

This page was automatically generated by Maven