Exemplo n.º 1
0
  /** Test of removeHandlerForEvent method, of class HexEventRegister. */
  @Test
  public void testRemoveHandlerForEvent() {
    Class type = HexEvent.class;

    final Value v = new Value();
    v.value = "fix";

    HexEventHandler handler =
        new HexEventHandler() {
          @Override
          public void handle(HexEvent event) throws Exception {
            v.value = "changed";
          }
        };

    String[] names = null;
    HexEventRegister instance = HexEventRegister.getInstance();

    instance.registerHandlerForEvent(type, handler, names);

    instance.triggerEvent(new HexEvent("one"));

    assertEquals(v.value, "changed");

    v.value = "fix";

    instance.removeHandlerForEvent(type, handler.getID());

    instance.triggerEvent(new HexEvent("one"));

    assertEquals(v.value, "fix");
  }
Exemplo n.º 2
0
  /** Test of registerHandlerForEvent method, of class HexEventRegister. */
  @Test
  public void testRegisterHandlerForEvent_3args() {
    System.out.println("registerHandlerForEvent");
    Class type = HexEvent.class;

    final Value v = new Value();
    v.value = "fix";

    HexEventHandler handler =
        new HexEventHandler() {
          @Override
          public void handle(HexEvent event) throws Exception {
            v.value = "changed";
          }
        };

    String[] names = null;
    HexEventRegister instance = HexEventRegister.getInstance();

    instance.registerHandlerForEvent(type, handler, names);

    instance.triggerEvent(new HexEvent("one"));

    assertEquals(v.value, "changed");

    final Value v2 = new Value();
    v2.value = "fix";

    HexEventHandler handler2 =
        new HexEventHandler() {
          @Override
          public void handle(HexEvent event) throws Exception {
            v2.value = "changed";
          }
        };

    instance.registerHandlerForEvent(type, handler2, new String[] {"two"});

    instance.triggerEvent(new HexEvent("one"));

    assertEquals(v2.value, "fix");

    instance.triggerEvent(new HexEvent("two"));

    assertEquals(v2.value, "changed");
  }