java.util.EventObject

Here are the examples of the java api class java.util.EventObject taken from open source projects.

1. IsEventFromTest#testCanTestForSpecificEventClasses()

Project: JavaHamcrest
File: IsEventFromTest.java
public void testCanTestForSpecificEventClasses() {
    Object o = new Object();
    DerivedEvent goodEv = new DerivedEvent(o);
    DerivedEvent wrongSource = new DerivedEvent("wrong source");
    EventObject wrongType = new EventObject(o);
    EventObject wrongSourceAndType = new EventObject(new Object());
    Matcher<EventObject> isEventMatcher = IsEventFrom.eventFrom(DerivedEvent.class, o);
    assertThat(goodEv, isEventMatcher);
    assertMismatchDescription("source was \"wrong source\"", isEventMatcher, wrongSource);
    assertMismatchDescription("item type was java.util.EventObject", isEventMatcher, wrongType);
    assertMismatchDescription("item type was java.util.EventObject", isEventMatcher, wrongSourceAndType);
}

2. EventObjectTest#testSerializationNullsOutSource()

Project: j2objc
File: EventObjectTest.java
public void testSerializationNullsOutSource() {
    String s = "aced0005737200156a6176612e7574696c2e4576656e744f626a6563744" + "c8d094e186d7da80200007870";
    Object source = new Object();
    EventObject eventObject = new EventObject(source);
    new SerializationTester<EventObject>(eventObject, s) {

        @Override
        protected boolean equals(EventObject a, EventObject b) {
            return a.getSource() == null || b.getSource() == null || a.getSource() == b.getSource();
        }
    }.test();
}

3. IsEventFromTest#testEvaluatesToTrueIfArgumentIsAnEventObjectFiredByASpecifiedSource()

Project: JavaHamcrest
File: IsEventFromTest.java
public void testEvaluatesToTrueIfArgumentIsAnEventObjectFiredByASpecifiedSource() {
    Object o = "Source";
    EventObject ev = new EventObject(o);
    EventObject ev2 = new EventObject("source 2");
    Matcher<EventObject> isEventMatcher = eventFrom(o);
    assertThat(ev, isEventMatcher);
    assertMismatchDescription("source was \"source 2\"", isEventMatcher, ev2);
}

4. EventObjectTest#setUp()

Project: j2objc
File: EventObjectTest.java
/**
	 * Sets up the fixture, for example, open a network connection. This method
	 * is called before a test is executed.
	 */
protected void setUp() {
    myObject = new Object();
    myEventObject = new EventObject(myObject);
}

5. EventNotifierExchangeSentTest#testExchangeWireTap()

Project: camel
File: EventNotifierExchangeSentTest.java
public void testExchangeWireTap() throws Exception {
    getMockEndpoint("mock:result").expectedMessageCount(1);
    template.sendBody("direct:tap", "Hello World");
    assertMockEndpointsSatisfied();
    // give it time to complete
    Thread.sleep(200);
    assertEquals(6, events.size());
    // we should find log:foo which we tapped
    // which runs async so they can be in random order
    boolean found = false;
    boolean found2 = false;
    for (EventObject event : events) {
        if (event instanceof ExchangeSendingEvent) {
            ExchangeSendingEvent sending = (ExchangeSendingEvent) event;
            String uri = sending.getEndpoint().getEndpointUri();
            if ("log://foo".equals(uri)) {
                found = true;
            }
        } else if (event instanceof ExchangeSentEvent) {
            ExchangeSentEvent sent = (ExchangeSentEvent) event;
            String uri = sent.getEndpoint().getEndpointUri();
            if ("log://foo".equals(uri)) {
                found2 = true;
            }
        }
    }
    assertTrue("We should find log:foo being wire tapped", found);
    assertTrue("We should find log:foo being wire tapped", found2);
}

6. EventNotifierExchangeSentParallelTest#testExchangeSentRecipient()

Project: camel
File: EventNotifierExchangeSentParallelTest.java
public void testExchangeSentRecipient() throws Exception {
    getMockEndpoint("mock:result").expectedMessageCount(1);
    template.sendBodyAndHeader("direct:foo", "Hello World", "foo", "direct:cool,direct:start");
    // wait for the message to be fully done using oneExchangeDone
    assertMockEndpointsSatisfied();
    assertTrue(oneExchangeDone.matchesMockWaitTime());
    // stop Camel to let all the events complete
    context.stop();
    assertTrue("Should be 11 or more, was: " + events.size(), events.size() >= 11);
    // we run parallel so just assert we got 6 sending and 6 sent events
    int sent = 0;
    int sending = 0;
    for (EventObject event : events) {
        if (event instanceof ExchangeSendingEvent) {
            sending++;
        } else {
            sent++;
        }
    }
    assertTrue("There should be 5 or more, was " + sending, sending >= 5);
    assertTrue("There should be 5 or more, was " + sent, sent >= 5);
}