@Test public void testSetImagePosition() { WButton button = new WButton(); button.setLocked(true); setActiveContext(createUIContext()); button.setImagePosition(ImagePosition.EAST); button.setLocked(true); Assert.assertEquals("Uic 1 image position should be returned for uic 1", ImagePosition.EAST, button.getImagePosition()); Assert. assertFalse("Button should not be in default state for uic1", button. isDefaultState()); resetContext(); Assert.assertNull("Default image position should be null", button.getImagePosition()); }
@Test public void testSetImageUrl() { WButton button = new WButton(); button.setLocked(true); String imageUrl = "http://127.0.0.1/image.jpg"; setActiveContext(createUIContext()); button.setImageUrl(imageUrl); button.setLocked(true); Assert.assertEquals("Uic 1 image url should be returned for uic 1", imageUrl, button. getImageUrl()); Assert. assertFalse("Button should not be in default state for uic1", button. isDefaultState()); resetContext(); Assert.assertNull("Default image url should be null", button.getImageUrl()); }
@Test public void testPopupTrigger() { WButton button = new WButton("Test"); button.setLocked(true); setActiveContext(createUIContext()); Assert.assertFalse("Should not be a popup trigger by default", button.isPopupTrigger()); button.setPopupTrigger(true); Assert.assertTrue("Button should be a popup trigger", button.isPopupTrigger()); resetContext(); Assert.assertFalse("Default popup trigger status should not have changed", button. isPopupTrigger()); }
@Test public void testSetActionCommand() { String text = "WButton_Test.text"; String sharedValue = "WButton_Test.sharedValue"; String value = "WButton_Test.value"; UIContext uic1 = new UIContextImpl(); WButton button = new WButton(text); button.setLocked(true); Assert.assertEquals("Default action command should be button text", text, button. getActionCommand()); button.setActionCommand(sharedValue); Assert.assertEquals("Incorrect shared action command returned", sharedValue, button. getActionCommand()); setActiveContext(uic1); button.setActionCommand(value); Assert.assertEquals("Uic 1 action command should be returned for uic 1", value, button. getActionCommand()); Assert. assertFalse("Button should not be in default state for uic1", button. isDefaultState()); resetContext(); Assert.assertEquals("Incorrect shared action command returned", sharedValue, button. getActionCommand()); }
@Test public void testSetPressed() { WButton button = new WButton("Test"); button.setLocked(true); setActiveContext(createUIContext()); button.setPressed(true, new MockRequest()); Assert.assertTrue("Button should be pressed", button.isPressed()); Assert.assertFalse("Button should not be in default state", button.isDefaultState()); button.setPressed(false, new MockRequest()); Assert.assertFalse("Button should be pressed", button.isPressed()); button.setDisabled(true); button.setPressed(true, new MockRequest()); Assert.assertTrue("Button should be disabled", button.isDisabled()); Assert.assertFalse("Button should be pressed when disabled", button.isPressed()); }
@Test public void testSetActionObject() { Serializable actionObject = "testSetActionObject.actionObject1"; WButton button = new WButton(); button.setLocked(true); setActiveContext(createUIContext()); button.setActionObject(actionObject); Assert.assertSame("Incorrect action object", actionObject, button.getActionObject()); resetContext(); Assert.assertNull("Action object should be null by default", button.getActionObject()); }
@Test public void testActionSetPressed() { WButton button = new WButton("Test"); button.setLocked(true); UIContext uic = createUIContext(); setActiveContext(uic); uic.setUI(button); TestAction testAction = new TestAction(); testAction.reset(); button.setAction(testAction); button.setPressed(true, new MockRequest()); Assert.assertEquals("Button was not pressed", true, button.isPressed()); }