-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed super methods causing problems
- Loading branch information
Showing
3 changed files
with
133 additions
and
0 deletions.
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
45 changes: 45 additions & 0 deletions
45
src/test/java/net/lenni0451/lambdaevents/OverriddenPrivateSuperTest.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,45 @@ | ||
package net.lenni0451.lambdaevents; | ||
|
||
import net.lenni0451.lambdaevents.generator.ReflectionGenerator; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class OverriddenPrivateSuperTest { | ||
|
||
private int calledSuper; | ||
private int calledExtending; | ||
|
||
@BeforeEach | ||
public void reset() { | ||
this.calledSuper = 0; | ||
this.calledExtending = 0; | ||
} | ||
|
||
@Test | ||
void overriddenPrivateHandler() { | ||
LambdaManager manager = LambdaManager.basic(new ReflectionGenerator()); | ||
manager.registerSuper(new OverriddenHandler()); | ||
manager.call("Test"); | ||
|
||
assertEquals(this.calledSuper, 1); | ||
assertEquals(this.calledExtending, 1); | ||
} | ||
|
||
|
||
public class BaseClass { | ||
@EventHandler | ||
private void onEvent(final String s) { | ||
OverriddenPrivateSuperTest.this.calledSuper++; | ||
} | ||
} | ||
|
||
public class OverriddenHandler extends BaseClass { | ||
@EventHandler | ||
private void onEvent(final String s) { | ||
OverriddenPrivateSuperTest.this.calledExtending++; | ||
} | ||
} | ||
|
||
} |
74 changes: 74 additions & 0 deletions
74
src/test/java/net/lenni0451/lambdaevents/OverriddenSuperRegisterTest.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,74 @@ | ||
package net.lenni0451.lambdaevents; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import static net.lenni0451.lambdaevents.TestManager.DATA_SOURCE; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class OverriddenSuperRegisterTest { | ||
|
||
private int calledSuper; | ||
private int calledExtending; | ||
|
||
@BeforeEach | ||
public void reset() { | ||
this.calledSuper = 0; | ||
this.calledExtending = 0; | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource(DATA_SOURCE) | ||
void overriddenHandler(final LambdaManager manager) { | ||
manager.registerSuper(new OverriddenHandler()); | ||
manager.call("Test"); | ||
|
||
assertEquals(this.calledSuper, 0); //should be 1 if it was possible to call the actual super method | ||
assertEquals(this.calledExtending, 1); //would be 2 if the super method wasn't filtered out | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource(DATA_SOURCE) | ||
void overriddenMethod(final LambdaManager manager) { | ||
manager.registerSuper(new OverriddenMethod()); | ||
manager.call("Test"); | ||
|
||
assertEquals(this.calledSuper, 0); | ||
assertEquals(this.calledExtending, 1); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource(DATA_SOURCE) | ||
void overriddenMethodWithoutSuper(final LambdaManager manager) { | ||
manager.register(new OverriddenMethod()); | ||
manager.call("Test"); | ||
|
||
assertEquals(this.calledSuper, 0); | ||
assertEquals(this.calledExtending, 0); | ||
} | ||
|
||
|
||
public class BaseClass { | ||
@EventHandler | ||
public void onEvent(final String s) { | ||
OverriddenSuperRegisterTest.this.calledSuper++; | ||
} | ||
} | ||
|
||
public class OverriddenHandler extends BaseClass { | ||
@Override | ||
@EventHandler | ||
public void onEvent(final String s) { | ||
OverriddenSuperRegisterTest.this.calledExtending++; | ||
} | ||
} | ||
|
||
public class OverriddenMethod extends BaseClass { | ||
@Override | ||
public void onEvent(final String s) { | ||
OverriddenSuperRegisterTest.this.calledExtending++; | ||
} | ||
} | ||
|
||
} |