1 53 package org.swixml; 54 55 import junit.framework.TestCase; 56 57 import javax.swing.*; 58 import java.awt.*; 59 import java.util.Enumeration ; 60 64 public class ButtonGroupTest extends TestCase { 65 66 public static final String DESCRIPTOR = "xml/test1.xml"; 67 private Container container; 68 private SwingEngine se; 69 70 private JRadioButton am, fm; 71 private ButtonGroup radio; 72 73 public ButtonGroupTest() { 74 super("Test the Mapping and behavior of a ButtonGroup."); 75 } 76 77 84 public void setUp() throws Exception { 85 se = new SwingEngine(this); 86 container = se.render(MappingTest.DESCRIPTOR); 87 } 88 89 92 public void teardown() { 93 se = null; 94 container.removeAll(); 95 container = null; 96 } 97 98 101 public void testMapping() { 102 TestCase.assertTrue("IDMap's EntrySet needs to contain the ButtonGroup's ID", se.getIdMap().containsKey("radio")); 103 TestCase.assertNotNull("Private Field, whose names have a matching ids the the XML descriptor should be initializd by the SwingEngine.", radio); 104 TestCase.assertNotNull("Public Fields, whose names have matching ids the the XML descriptor should be initializd by the SwingEngine.", am); 105 TestCase.assertNotNull("Public Fields, whose names have matching ids the the XML descriptor should be initializd by the SwingEngine.", fm); 106 } 107 108 111 public void testXOR() { 112 am.setSelected(true); 113 TestCase.assertTrue(am.isSelected()); 114 TestCase.assertFalse("Only one RadioButton in the group should be flagged selected.", fm.isSelected()); 115 fm.setSelected(true); 116 TestCase.assertFalse("Only one RadioButton in the group should be flagged selected.", am.isSelected()); 117 TestCase.assertTrue(fm.isSelected()); 118 } 119 120 123 public void testStructure() { 124 Enumeration e = radio.getElements(); 125 while (e.hasMoreElements()) { 126 Object obj = e.nextElement(); 127 TestCase.assertTrue (am.equals(obj) ^ fm.equals(obj)); 128 } 129 TestCase.assertEquals("There should be two buttons in this group",radio.getButtonCount(),2); 130 } 131 } 132 | Popular Tags |