-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix generated event handlers for events on interfaces.
- Loading branch information
Showing
2 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
...us-test/src/test/java/net/minecraftforge/eventbus/test/general/InterfaceEventHandler.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,53 @@ | ||
/* | ||
* Copyright (c) Forge Development LLC | ||
* SPDX-License-Identifier: LGPL-2.1-only | ||
*/ | ||
|
||
package net.minecraftforge.eventbus.test.general; | ||
|
||
import java.util.function.Consumer; | ||
import java.util.function.Supplier; | ||
|
||
import net.minecraftforge.eventbus.api.BusBuilder; | ||
import net.minecraftforge.eventbus.api.Event; | ||
import net.minecraftforge.eventbus.api.IEventBus; | ||
import net.minecraftforge.eventbus.api.SubscribeEvent; | ||
import net.minecraftforge.eventbus.test.ITestHandler; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
public class InterfaceEventHandler implements ITestHandler { | ||
private static boolean hit = false; | ||
|
||
public InterfaceEventHandler(boolean hasTransformer) { | ||
} | ||
|
||
@Override | ||
public void test(Consumer<Class<?>> validator, Supplier<BusBuilder> builder) { | ||
var bus = builder.get().build(); | ||
assertDoesNotThrow(() -> bus.register(STATIC.class)); | ||
testCall(bus, true, "STATIC"); | ||
assertDoesNotThrow(() -> bus.register(new INSTANCE() {})); | ||
testCall(bus, true, "STATIC"); | ||
} | ||
|
||
private void testCall(IEventBus bus, boolean expected, String name) { | ||
hit = false; | ||
bus.post(new Event()); | ||
assertEquals(expected, hit, name + " did not behave correctly"); | ||
} | ||
|
||
public interface STATIC { | ||
@SubscribeEvent | ||
static void handler(Event e) { | ||
hit = true; | ||
} | ||
} | ||
|
||
public interface INSTANCE { | ||
@SubscribeEvent | ||
default void handler(Event e) { | ||
hit = true; | ||
} | ||
} | ||
} |
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