Package java.beans

Examples of java.beans.EventHandler


    /**
     * The test checks event handler accessors
     */
    public void testAccessors() {
        InvocationObject invocationObject = new InvocationObject();
        EventHandler handler = new EventHandler(invocationObject, "someText",
                "source.text", "actionPerformed");
        assertEquals(invocationObject, handler.getTarget());
        assertEquals("someText", handler.getAction());
        assertEquals("source.text", handler.getEventPropertyName());
        assertEquals("actionPerformed", handler.getListenerMethodName());
    }
View Full Code Here


     * The test checks the method invoke() with null listener value
     */
    public void testNullListenerMethodName() throws Exception {
        InvocationObject invocationObject = new InvocationObject();

        EventHandler handler = new EventHandler(invocationObject, "someText",
                "source.text", null);

        Object proxy = EventHandler.create(ActionListener.class,
                invocationObject, "someText", "source.text");

        Method m = ActionListener.class.getMethod("actionPerformed",
                new Class[] { ActionEvent.class });
        handler.invoke(proxy, m, new Object[] { new ActionEvent(this, 0, "") });

        assertEquals(invocationObject.getSomeText(), getText());
    }
View Full Code Here

     * The test checks the method invoke()
     */
    public void testInvoke() throws Exception {
        InvocationObject invocationObject = new InvocationObject();

        EventHandler handler = new EventHandler(invocationObject, "someText",
                "source.text", "actionPerformed");

        Object proxy = EventHandler.create(ActionListener.class,
                invocationObject, "someText", "source.text");

        Method m = ActionListener.class.getMethod("actionPerformed",
                new Class[] { ActionEvent.class });
        handler.invoke(proxy, m, new Object[] { new ActionEvent(this, 0, "") });

        assertEquals(invocationObject, handler.getTarget());
        assertEquals(invocationObject.getSomeText(), getText());
    }
View Full Code Here

     * The test checks the method invoke() with null property name
     */
    public void testInvokeWithNullPropertyName() throws Exception {
        InvocationObject invocationObject = new InvocationObject();

        EventHandler handler = new EventHandler(invocationObject,
                "doSomething", null, null);

        Object proxy = EventHandler.create(SampleListener.class,
                invocationObject, "doSomething");

        Method m = SampleListener.class.getMethod("fireSampleEvent",
                new Class[] { SampleEvent.class });
        handler.invoke(proxy, m, new Object[] { new SampleEvent("") });

        assertEquals(invocationObject, handler.getTarget());
        assertEquals("doSomething", getMethodName());

        // Regression test for HARMONY-4033
        m = FredListener.class.getMethod("fireFredEvent",
                new Class[] { FredEvent.class });
View Full Code Here

    public void testEventHandler() {
        MockTarget target = new MockTarget();
        String action = "text";
        String eventPropertyName = "source.label";
        String listenerMethodName = "propertyChange";
        EventHandler handler = new EventHandler(target, action,
                eventPropertyName, listenerMethodName);
        assertSame(target, handler.getTarget());
        assertSame(action, handler.getAction());
        assertSame(eventPropertyName, handler.getEventPropertyName());
        assertSame(listenerMethodName, handler.getListenerMethodName());
    }
View Full Code Here

    public void testEventHandler_TargetNull() {
        String action = "text";
        String eventPropertyName = "source.label";
        String listenerMethodName = "propertyChange";
        try {
            EventHandler handler = new EventHandler(null, action,
                    eventPropertyName, listenerMethodName);
            fail("should throw NPE");
        } catch (NullPointerException e) {

        }
View Full Code Here

    public void testEventHandler_ActionNull() {
        MockTarget target = new MockTarget();
        String eventPropertyName = "source.label";
        String listenerMethodName = "propertyChange";
        try {
            EventHandler handler = new EventHandler(target, null,
                    eventPropertyName, listenerMethodName);
            fail("should throw NPE");
        } catch (NullPointerException e) {

        }
        EventHandler handler = new EventHandler(target, "action",
                eventPropertyName, listenerMethodName);
        assertSame(target, handler.getTarget());
        assertEquals("action", handler.getAction());
        assertSame(eventPropertyName, handler.getEventPropertyName());
        assertSame(listenerMethodName, handler.getListenerMethodName());
    }
View Full Code Here

     */
    public void testEventHandler_EventPropertyNull() {
        MockTarget target = new MockTarget();
        String action = "text";
        String listenerMethodName = "propertyChange";
        EventHandler handler = new EventHandler(target, action, null,
                listenerMethodName);
        assertSame(target, handler.getTarget());
        assertSame(action, handler.getAction());
        assertNull(handler.getEventPropertyName());
        assertSame(listenerMethodName, handler.getListenerMethodName());
    }
View Full Code Here

     */
    public void testEventHandler_MethodNull() {
        MockTarget target = new MockTarget();
        String action = "text";
        String eventPropertyName = "source.label";
        EventHandler handler = new EventHandler(target, action,
                eventPropertyName, null);
        assertSame(target, handler.getTarget());
        assertSame(action, handler.getAction());
        assertSame(eventPropertyName, handler.getEventPropertyName());
        assertNull(handler.getListenerMethodName());
    }
View Full Code Here

        PropertyChangeListener proxy = EventHandler.create(
                PropertyChangeListener.class, target, "setCalled");

        String action = "text";
        String eventPropertyName = "source.label";
        EventHandler handler = new EventHandler(target, action,
                eventPropertyName, null);
        Method listenerMethod = PropertyChangeListener.class.getMethod(
                "propertyChange", new Class[] { PropertyChangeEvent.class });
        PropertyChangeEvent event = new PropertyChangeEvent(button, "label",
                "1", "5");
        handler.invoke(proxy, listenerMethod, new Object[] { event });
        assertEquals(button.getLabel(), target.getText());
        Method equalsMethod = Object.class.getMethod("equals",
                new Class[] { Object.class });
        assertEquals(Boolean.FALSE, handler.invoke(proxy, equalsMethod,
                new String[] { "mock" }));
        // Test null method with non-proxy Object.
        handler = new EventHandler(new Object(), "a", "a", "a");
        try {
            handler.invoke(new Object(), null, new Object[] {});
            fail("should throw NPE.");
        } catch (NullPointerException e) {
            // expected;
        }
    }
View Full Code Here

TOP

Related Classes of java.beans.EventHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.