-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide versions of all registration methods with explicit event clas…
…s parameters. Add test variants for explicit-class handlers.
- Loading branch information
Showing
9 changed files
with
220 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...s-test/src/test/java/net/minecraftforge/eventbus/test/general/ClassLambdaHandlerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package net.minecraftforge.eventbus.test.general; | ||
|
||
import net.minecraftforge.eventbus.api.*; | ||
import net.minecraftforge.eventbus.test.ITestHandler; | ||
|
||
import java.util.function.Consumer; | ||
import java.util.function.Function; | ||
import java.util.function.Supplier; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public abstract class ClassLambdaHandlerTest implements ITestHandler { | ||
boolean hit; | ||
|
||
@Override | ||
public void before(Consumer<Class<?>> validator, Supplier<BusBuilder> builder) { | ||
validator.accept(SubEvent.class); | ||
validator.accept(CancellableEvent.class); | ||
hit = false; | ||
} | ||
|
||
public void consumeEvent(Event e) { hit = true; } | ||
public void consumeSubEvent(SubEvent e) { hit = true; } | ||
|
||
public static class Basic extends ClassLambdaHandlerTest | ||
{ | ||
@Override | ||
public void test(Consumer<Class<?>> validator, Supplier<BusBuilder> builder) { | ||
final IEventBus iEventBus = builder.get().build(); | ||
// Inline | ||
iEventBus.addListener(Event.class, (e)-> hit = true); | ||
iEventBus.post(new Event()); | ||
assertTrue(hit, "Inline Lambda was not called"); | ||
hit = false; | ||
// Method reference | ||
iEventBus.addListener(Event.class, this::consumeEvent); | ||
iEventBus.post(new Event()); | ||
assertTrue(hit, "Method reference was not called"); | ||
hit = false; | ||
} | ||
} | ||
|
||
public static class SubClassEvent extends ClassLambdaHandlerTest | ||
{ | ||
@Override | ||
public void test(Consumer<Class<?>> validator, Supplier<BusBuilder> builder) { | ||
final IEventBus iEventBus = builder.get().build(); | ||
// Inline | ||
iEventBus.addListener(SubEvent.class, (e) -> hit = true); | ||
iEventBus.post(new SubEvent()); | ||
assertTrue(hit, "Inline was not called"); | ||
hit = false; | ||
iEventBus.post(new Event()); | ||
assertTrue(!hit, "Inline was called on root event"); | ||
// Method Reference | ||
iEventBus.addListener(SubEvent.class, this::consumeSubEvent); | ||
iEventBus.post(new SubEvent()); | ||
assertTrue(hit, "Method reference was not called"); | ||
hit = false; | ||
iEventBus.post(new Event()); | ||
assertTrue(!hit, "Method reference was called on root event"); | ||
} | ||
} | ||
|
||
public static class SubEvent extends Event {} | ||
|
||
@Cancelable | ||
public static class CancellableEvent extends Event {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
.../src/main/java/net/minecraftforge/eventbus/benchmarks/compiled/SubscriberClassLambda.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package net.minecraftforge.eventbus.benchmarks.compiled; | ||
|
||
import net.minecraftforge.eventbus.api.IEventBus; | ||
|
||
public class SubscriberClassLambda | ||
{ | ||
|
||
public static void register(IEventBus bus) | ||
{ | ||
bus.addListener(CancelableEvent.class, SubscriberClassLambda::onCancelableEvent); | ||
bus.addListener(ResultEvent.class, SubscriberClassLambda::onResultEvent); | ||
bus.addListener(EventWithData.class, SubscriberClassLambda::onSimpleEvent); | ||
} | ||
|
||
public static void onCancelableEvent(CancelableEvent event) | ||
{ | ||
|
||
} | ||
|
||
public static void onResultEvent(ResultEvent event) | ||
{ | ||
|
||
} | ||
|
||
public static void onSimpleEvent(EventWithData event) | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters