Package tangowidget.util.listenerimpl

Examples of tangowidget.util.listenerimpl.DeviceListenerImpl


        final DeviceStateButtonCometeV2 widget = new DeviceStateButtonCometeV2.Builder(m_deviceName).jframe(jf1)
                .build();
        Sleeper.SECONDS.sleep(1);

        final DeviceListenerImpl listenerSpy = new DeviceListenerImpl();
        widget.addDeviceListener(listenerSpy);

        // test all are notified
        assertTrue("stateChange(String) is not notify",
                listenerSpy.isLaterNotified("stateChange(String)", 2000));

        assertTrue("stateChange(int) is not notify",
                listenerSpy.isLaterNotified("stateChange(int)", 2000));

        assertTrue("statusChange is not notify", listenerSpy.isLaterNotified("statusChange", 2000));
        assertTrue("colorChange is not notify", listenerSpy.isLaterNotified("colorChange", 2000));

        // check listener is notify only one time.
        Sleeper.SECONDS.sleep(2);
        assertThat(listenerSpy.getNotifyCount()).isEqualTo(4);

        // test all are notified with good value
        assertEquals("stateChange(String) return the wrong value", "ON",
                (String) listenerSpy.getNotification("stateChange(String)"));
        assertEquals("stateChange(int) return the wrong value", Integer.valueOf(0),
                listenerSpy.getNotification("stateChange(int)"));
        assertEquals("statusChange return the wrong value", "the device is ON",
                (String) listenerSpy.getNotification("statusChange"));
        assertEquals("colorChange return the wrong value", ColorDeviceState.ON.getColor(),
                listenerSpy.getNotification("colorChange"));

        // test change device value and check if notification value is updated
        switchStateOnDevice(10, m_deviceProxy);

        // test all are notified with good value
        assertEquals("stateChange(String) return the wrong value", "RUNNING",
                (String) listenerSpy.getNotification("stateChange(String)"));
        assertEquals("stateChange(int) return the wrong value", Integer.valueOf(10),
                listenerSpy.getNotification("stateChange(int)"));
        assertEquals("statusChange return the wrong value", "the device is RUNNING",
                (String) listenerSpy.getNotification("statusChange"));
        assertEquals("colorChange return the wrong value", ColorDeviceState.RUNNING.getColor(),
                listenerSpy.getNotification("colorChange"));

        // test listener is not notify after remove
        widget.removeDeviceListener(listenerSpy);
        listenerSpy.reset();

        switchStateOnDevice(0, m_deviceProxy);

        Sleeper.SECONDS.sleep(3);
        assertEquals("Listener should not be called", 0, listenerSpy.getNotifyCount());

        // clean
        widget.stop();
        jf1.dispose();
    }
View Full Code Here

TOP

Related Classes of tangowidget.util.listenerimpl.DeviceListenerImpl

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.