-
-
Notifications
You must be signed in to change notification settings - Fork 379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tests for effects #6204
Merged
Merged
Add tests for effects #6204
Changes from 8 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b1b2d9c
Add tests for EffActionBar
Pikachu920 8bde3b5
Fix order of operations issue in EffApplyBoneMeal
Pikachu920 a057190
Add tests for EffApplyBoneMeal
Pikachu920 c1ab9c4
Add tests for EffDoIf
Pikachu920 62e52ad
Add tests for EffSwingHand
Pikachu920 8286a4e
Replace static imports
Pikachu920 38204ec
Add tests for EffFeed
Pikachu920 6448b8a
Fix EffSwingHandTest on unsupported versions
Pikachu920 c5cd680
Add tests for EffMakeFly
Pikachu920 7cbe21c
Add tests for EffPvP
Pikachu920 fc4a38b
Remove double whitespace
Pikachu920 4f6d1f8
Add tests for EffOp
Pikachu920 e9c1e3a
Merge branch 'dev/feature' of https://github.com/SkriptLang/Skript in…
Pikachu920 944f27f
Merge branch 'dev/feature' into feature/effect-tests-1
sovdeeth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
97 changes: 97 additions & 0 deletions
97
src/test/java/org/skriptlang/skript/test/tests/syntaxes/effects/EffActionBarTest.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,97 @@ | ||
/** | ||
* This file is part of Skript. | ||
* | ||
* Skript is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Skript is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Skript. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* Copyright Peter Güttinger, SkriptLang team and contributors | ||
*/ | ||
package org.skriptlang.skript.test.tests.syntaxes.effects; | ||
|
||
|
||
import ch.njol.skript.lang.Effect; | ||
import ch.njol.skript.lang.TriggerItem; | ||
import ch.njol.skript.lang.util.ContextlessEvent; | ||
import ch.njol.skript.test.runner.SkriptJUnitTest; | ||
import ch.njol.skript.variables.Variables; | ||
import net.md_5.bungee.api.ChatMessageType; | ||
import net.md_5.bungee.api.chat.BaseComponent; | ||
import net.md_5.bungee.api.chat.TextComponent; | ||
import org.bukkit.entity.Player; | ||
import org.easymock.EasyMock; | ||
import org.easymock.IArgumentMatcher; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
|
||
@SuppressWarnings("deprecation") | ||
public class EffActionBarTest extends SkriptJUnitTest { | ||
|
||
private Player testPlayer; | ||
private Player.Spigot testSpigotPlayer; | ||
private Effect actionBarEffect; | ||
|
||
@Before | ||
public void setup() { | ||
testPlayer = EasyMock.niceMock(Player.class); | ||
testSpigotPlayer = EasyMock.niceMock(Player.Spigot.class); | ||
actionBarEffect = Effect.parse("send actionbar {_content} to {_player}", null); | ||
} | ||
|
||
@Test | ||
public void test() { | ||
if (actionBarEffect == null) | ||
Assert.fail("Effect is null"); | ||
|
||
String expectedActionBarContent = "hello world"; | ||
|
||
EasyMock.expect(testPlayer.spigot()).andAnswer(() -> testSpigotPlayer); | ||
|
||
testSpigotPlayer.sendMessage( | ||
EasyMock.eq(ChatMessageType.ACTION_BAR), | ||
(BaseComponent[]) componentMatcher(expectedActionBarContent) | ||
); | ||
|
||
EasyMock.expectLastCall(); | ||
|
||
EasyMock.replay(testPlayer, testSpigotPlayer); | ||
|
||
ContextlessEvent event = ContextlessEvent.get(); | ||
Variables.setVariable("content", expectedActionBarContent, event, true); | ||
Variables.setVariable("player", testPlayer, event, true); | ||
TriggerItem.walk(actionBarEffect, event); | ||
|
||
EasyMock.verify(testPlayer, testSpigotPlayer); | ||
} | ||
|
||
private <T> T componentMatcher(String expectedContent) { | ||
EasyMock.reportMatcher(new IArgumentMatcher() { | ||
@Override | ||
public boolean matches(Object argument) { | ||
if (argument instanceof TextComponent) { | ||
return ((TextComponent) argument).getText().equals(expectedContent); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public void appendTo(StringBuffer buffer) { | ||
buffer.append("[component matcher]"); | ||
} | ||
}); | ||
|
||
return null; | ||
} | ||
|
||
} |
96 changes: 96 additions & 0 deletions
96
src/test/java/org/skriptlang/skript/test/tests/syntaxes/effects/EffApplyBoneMealTest.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,96 @@ | ||
/** | ||
* This file is part of Skript. | ||
* | ||
* Skript is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Skript is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Skript. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* Copyright Peter Güttinger, SkriptLang team and contributors | ||
*/ | ||
package org.skriptlang.skript.test.tests.syntaxes.effects; | ||
|
||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.effects.EffApplyBoneMeal; | ||
import ch.njol.skript.lang.Effect; | ||
import ch.njol.skript.lang.SyntaxElementInfo; | ||
import ch.njol.skript.lang.TriggerItem; | ||
import ch.njol.skript.lang.util.ContextlessEvent; | ||
import ch.njol.skript.test.runner.SkriptJUnitTest; | ||
import ch.njol.skript.variables.Variables; | ||
import org.bukkit.block.Block; | ||
import org.easymock.EasyMock; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.lang.reflect.InvocationHandler; | ||
import java.lang.reflect.Proxy; | ||
|
||
public class EffApplyBoneMealTest { | ||
|
||
private Block stubTestBlock; | ||
private Effect applyBonemealEffect; | ||
private Effect applyMultipleBonemealEffect; | ||
|
||
@Before | ||
public void setup() { | ||
stubTestBlock = EasyMock.niceMock(Block.class); | ||
applyBonemealEffect = Effect.parse("apply bonemeal to {_block}", null); | ||
applyMultipleBonemealEffect = Effect.parse("apply {_times} bonemeal to {_block}", null); | ||
} | ||
|
||
@Test | ||
public void test() { | ||
boolean bonemealEffectRegistered = Skript.getEffects().stream() | ||
.map(SyntaxElementInfo::getElementClass) | ||
.anyMatch(EffApplyBoneMeal.class::equals); | ||
if (!bonemealEffectRegistered) | ||
return; | ||
if (applyBonemealEffect == null) | ||
Assert.fail("Effect is null"); | ||
if (applyMultipleBonemealEffect == null) | ||
Assert.fail("Multiple effect is null"); | ||
|
||
int countOfBonemealToApply = 5; | ||
ContextlessEvent event = ContextlessEvent.get(); | ||
Variables.setVariable("block", getMockBlock(), event, true); | ||
Variables.setVariable("times", countOfBonemealToApply, event, true); | ||
|
||
EasyMock.expect(stubTestBlock.applyBoneMeal(EasyMock.notNull())).andReturn(true).times(1); | ||
EasyMock.replay(stubTestBlock); | ||
TriggerItem.walk(applyBonemealEffect, event); | ||
EasyMock.verify(stubTestBlock); | ||
|
||
EasyMock.resetToNice(stubTestBlock); | ||
EasyMock.expect(stubTestBlock.applyBoneMeal(EasyMock.notNull())).andReturn(true).times(2); | ||
EasyMock.replay(stubTestBlock); | ||
TriggerItem.walk(applyMultipleBonemealEffect, event); | ||
EasyMock.verify(stubTestBlock); | ||
} | ||
|
||
private Block getMockBlock() { | ||
Block realBlock = SkriptJUnitTest.getBlock(); | ||
|
||
// we need to intercept applyBoneMeal calls so that easymock can detect them | ||
// but we need to pass the other calls to a real block so that a real blockdata, | ||
// material, location, etc are available | ||
InvocationHandler handler = (proxy, method, args) -> { | ||
if (method.getName().equals("applyBoneMeal")) { | ||
return method.invoke(stubTestBlock, args); | ||
} | ||
return method.invoke(realBlock, args); | ||
}; | ||
|
||
return (Block) Proxy.newProxyInstance(getClass().getClassLoader(), new Class<?>[] { Block.class }, handler); | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
src/test/java/org/skriptlang/skript/test/tests/syntaxes/effects/EffFeedTest.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,84 @@ | ||
/** | ||
* This file is part of Skript. | ||
* | ||
* Skript is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Skript is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Skript. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* Copyright Peter Güttinger, SkriptLang team and contributors | ||
*/ | ||
package org.skriptlang.skript.test.tests.syntaxes.effects; | ||
|
||
import ch.njol.skript.lang.Effect; | ||
import ch.njol.skript.lang.TriggerItem; | ||
import ch.njol.skript.lang.util.ContextlessEvent; | ||
import ch.njol.skript.test.runner.SkriptJUnitTest; | ||
import ch.njol.skript.variables.Variables; | ||
import org.bukkit.entity.Player; | ||
import org.easymock.EasyMock; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.lang.reflect.InvocationHandler; | ||
import java.lang.reflect.Proxy; | ||
|
||
public class EffFeedTest extends SkriptJUnitTest { | ||
|
||
private Player easyMockPlayer; | ||
private Effect feedFullyEffect; | ||
private Effect feedPartiallyEffect; | ||
|
||
@Before | ||
public void setup() { | ||
easyMockPlayer = EasyMock.niceMock(Player.class); | ||
feedFullyEffect = Effect.parse("feed {_player}", null); | ||
feedPartiallyEffect = Effect.parse("feed {_player} by {_amount} beef", null); | ||
} | ||
|
||
@Test | ||
public void test() { | ||
if (feedFullyEffect == null) | ||
Assert.fail("Fully effect is null"); | ||
if (feedPartiallyEffect == null) | ||
Assert.fail("Partially effect is null"); | ||
|
||
int amountToFeed = 1; | ||
int maxFoodLevel = 20; | ||
ContextlessEvent event = ContextlessEvent.get(); | ||
Variables.setVariable("player", getMockPlayer(), event, true); | ||
Variables.setVariable("amount", amountToFeed, event, true); | ||
|
||
easyMockPlayer.setFoodLevel(EasyMock.eq(maxFoodLevel)); | ||
EasyMock.expectLastCall(); | ||
EasyMock.replay(easyMockPlayer); | ||
TriggerItem.walk(feedFullyEffect, event); | ||
EasyMock.verify(easyMockPlayer); | ||
|
||
EasyMock.resetToNice(easyMockPlayer); | ||
easyMockPlayer.setFoodLevel(EasyMock.eq(amountToFeed)); | ||
EasyMock.expectLastCall(); | ||
EasyMock.replay(easyMockPlayer); | ||
TriggerItem.walk(feedPartiallyEffect, event); | ||
EasyMock.verify(easyMockPlayer); | ||
} | ||
|
||
private Player getMockPlayer() { | ||
InvocationHandler handler = (proxy, method, args) -> { | ||
if (method.getName().equals("getFoodLevel")) | ||
return 0; | ||
return method.invoke(easyMockPlayer, args); | ||
}; | ||
return (Player) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { Player.class }, handler); | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems like 5.2.0 has a bug. on v5.0.1, the action bar test passes. however, when running this exact same code in v5.2.0, the action bar test encounters the exception described in easymock/easymock#356. that issue was apparently fixed in 5.2.0 but i wonder if it wasn't a complete fix. it could definitely be user error too though. i will probably followup on that issue and see what the maintainers think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
easymock/easymock#356 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#515