mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add event
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package org.dromara.hutool.core.lang.event;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class SimpleEventPublisherTest {
|
||||
|
||||
@Test
|
||||
void registerTest() {
|
||||
final SimpleEventPublisher publisher = SimpleEventPublisher.of();
|
||||
publisher.register(event -> Assertions.assertEquals("test", ((TestEvent)event).getName()));
|
||||
|
||||
publisher.publish(new TestEvent("test"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void sourceEventTest() {
|
||||
final SimpleEventPublisher publisher = SimpleEventPublisher.of();
|
||||
publisher.register(event -> Assertions.assertEquals("test", ((SourceEvent)event).getSource()));
|
||||
|
||||
publisher.publish(new SourceEvent("test"));
|
||||
}
|
||||
|
||||
private static class TestEvent implements Event {
|
||||
private final String name;
|
||||
|
||||
public TestEvent(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user