1 29 30 package nextapp.echo2.app.test; 31 32 import nextapp.echo2.app.Alignment; 33 import nextapp.echo2.app.Extent; 34 import nextapp.echo2.app.IllegalChildException; 35 import nextapp.echo2.app.Label; 36 import nextapp.echo2.app.TextField; 37 import nextapp.echo2.app.text.StringDocument; 38 import junit.framework.TestCase; 39 40 44 public class TextFieldTest extends TestCase { 45 46 49 public void testEmptyConstructor() { 50 TextField textField = new TextField(); 51 assertNotNull(textField.getDocument()); 52 assertEquals(StringDocument.class, textField.getDocument().getClass()); 53 } 54 55 58 public void testIllegalChildren() { 59 TextField textField = new TextField(); 60 boolean exceptionThrown = false; 61 try { 62 textField.add(new Label("you can't add children to this component, right?")); 63 } catch (IllegalChildException ex) { 64 exceptionThrown = true; 65 } 66 assertTrue(exceptionThrown); 67 } 68 69 72 public void testInput() { 73 TextField textField = new TextField(); 74 textField.processInput(TextField.TEXT_CHANGED_PROPERTY, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); 75 assertEquals("ABCDEFGHIJKLMNOPQRSTUVWXYZ", textField.getDocument().getText()); 76 } 77 78 81 public void testPrimaryConstructor() { 82 TextField textField = new TextField(new StringDocument(), "text", 30); 83 assertEquals("text", textField.getDocument().getText()); 84 assertEquals(new Extent(30, Extent.EX), textField.getWidth()); 85 } 86 87 90 public void testMaxLengthTrim() { 91 TextField textField = new TextField(); 92 textField.setMaximumLength(5); 93 textField.setText("abcdefghijkl"); 94 assertEquals("abcde", textField.getText()); 95 } 96 97 100 public void testProperties() { 101 TextField textField = new TextField(); 102 textField.setAlignment(new Alignment(Alignment.LEADING, Alignment.BOTTOM)); 103 assertEquals(new Alignment(Alignment.LEADING, Alignment.BOTTOM), textField.getAlignment()); 104 textField.setBorder(TestConstants.BORDER_THICK_ORANGE); 105 assertEquals(TestConstants.BORDER_THICK_ORANGE, textField.getBorder()); 106 textField.setHeight(TestConstants.EXTENT_30_PX); 107 assertEquals(TestConstants.EXTENT_30_PX, textField.getHeight()); 108 textField.setInsets(TestConstants.INSETS_1234); 109 assertEquals(TestConstants.INSETS_1234, textField.getInsets()); 110 textField.setWidth(TestConstants.EXTENT_100_PX); 111 assertEquals(TestConstants.EXTENT_100_PX, textField.getWidth()); 112 textField.setBackgroundImage(TestConstants.BACKGROUND_IMAGE); 113 114 assertEquals(TestConstants.BACKGROUND_IMAGE, textField.getBackgroundImage()); 115 assertEquals(-1, textField.getMaximumLength()); 116 textField.setMaximumLength(20); 117 assertEquals(20, textField.getMaximumLength()); 118 textField.setMaximumLength(-1); 119 assertEquals(-1, textField.getMaximumLength()); 120 } 121 } 122 | Popular Tags |