示例#1
0
  /** Test to ensure that progress messages are correctly propagated. */
  public void testDeterminteProgress() {
    MessageSourceSupport source = new MessageSourceSupport(this);
    ProgressEvent evt = null;

    // Add listeners.
    for (int i = 0; i < plisteners.length; i++) {
      source.addProgressListener(plisteners[i]);
    }

    // This is a determinate progress operation
    source.fireProgressStarted(0, 100);
    for (int i = 0; i < plisteners.length; i++) {
      evt = plisteners[i].getLastEvent();
      assertFalse(evt.isIndeterminate());
      assertTrue(plisteners[i].begin);
      assertFalse(plisteners[i].end);
    }

    source.fireProgressIncremented(50);
    for (int i = 0; i < plisteners.length; i++) {
      evt = plisteners[i].getLastEvent();
      assertFalse(evt.isIndeterminate());
      assertFalse(plisteners[i].begin);
      assertFalse(plisteners[i].end);
    }

    source.fireProgressEnded();
    for (int i = 0; i < plisteners.length; i++) {
      evt = plisteners[i].getLastEvent();
      assertTrue(evt.isIndeterminate());
      assertFalse(plisteners[i].begin);
      assertTrue(plisteners[i].end);
    }
  }
示例#2
0
  /** Tests the exception passing mechanism. */
  public void testExceptions() {
    MessageSourceSupport source = new MessageSourceSupport(this);
    for (int i = 0; i < listeners.length; i++) {
      source.addMessageListener(listeners[i]);
    }

    Exception ex = new Exception("This is a message");
    MessageEvent evt = null;

    source.fireException(ex);
    for (int i = 0; i < listeners.length; i++) {
      evt = listeners[i].getLastEvent();
      assertNotNull(evt);
      // The event message should be the exception message.
      assertEquals(ex.getMessage(), evt.getMessage());
      // By default, exceptions should be Level.SEVERE
      assertEquals(Level.SEVERE, evt.getLevel());
    }
  }
示例#3
0
  /** Test to ensure that messages are dispatched correctly. */
  public void testMessageDispatch() {
    MessageSourceSupport source = new MessageSourceSupport(this);
    for (int i = 0; i < listeners.length; i++) {
      source.addMessageListener(listeners[i]);
    }

    // Test data.
    String message = "This is a simple message";
    Level level = Level.INFO;
    long when = System.currentTimeMillis();
    MessageEvent evt = null;

    // Simple test to ensure that all listeners get the same event.
    source.fireMessage(message);
    for (int i = 0; i < listeners.length; i++) {
      evt = listeners[i].getLastEvent();
      assertNotNull(evt);
      assertEquals(message, evt.getMessage());
    }

    source.fireMessage(message, level);
    for (int i = 0; i < listeners.length; i++) {
      evt = listeners[i].getLastEvent();
      assertNotNull(evt);
      assertEquals(message, evt.getMessage());
      assertEquals(level, evt.getLevel());
    }

    source.fireMessage(message, level, when);
    for (int i = 0; i < listeners.length; i++) {
      evt = listeners[i].getLastEvent();
      assertNotNull(evt);
      assertEquals(message, evt.getMessage());
      assertEquals(level, evt.getLevel());
      assertEquals(when, evt.getWhen());
    }

    evt = new MessageEvent(this, message, level, when);
    source.fireMessage(evt);
    for (int i = 0; i < listeners.length; i++) {
      assertEquals(evt, listeners[i].getLastEvent());
    }
  }