- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Showing
8 changed files
with
99 additions
and
11 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
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
15 changes: 15 additions & 0 deletions
15
litecommands-bukkit/test/dev/rollczi/litecommands/bukkit/argument/BukkitTestSpec.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,15 @@ | ||
package dev.rollczi.litecommands.bukkit.argument; | ||
|
||
import dev.rollczi.litecommands.invocation.Invocation; | ||
import dev.rollczi.litecommands.unit.TestUtil; | ||
import org.bukkit.command.CommandSender; | ||
import org.mockito.Mockito; | ||
|
||
public class BukkitTestSpec { | ||
|
||
protected static Invocation<CommandSender> invocation(String command, String... args) { | ||
CommandSender sender = Mockito.mock(CommandSender.class); | ||
return TestUtil.invocation(sender, command, args); | ||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
litecommands-bukkit/test/dev/rollczi/litecommands/bukkit/argument/LocationArgumentTest.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,54 @@ | ||
package dev.rollczi.litecommands.bukkit.argument; | ||
|
||
import dev.rollczi.litecommands.argument.Argument; | ||
import dev.rollczi.litecommands.argument.ArgumentKey; | ||
import dev.rollczi.litecommands.argument.parser.ParserRegistryImpl; | ||
import dev.rollczi.litecommands.argument.resolver.optional.OptionalArgumentResolver; | ||
import dev.rollczi.litecommands.input.raw.RawInput; | ||
import dev.rollczi.litecommands.invocation.Invocation; | ||
import dev.rollczi.litecommands.message.MessageRegistry; | ||
import dev.rollczi.litecommands.reflect.type.TypeRange; | ||
import dev.rollczi.litecommands.reflect.type.TypeToken; | ||
import dev.rollczi.litecommands.requirement.RequirementResult; | ||
import java.util.Optional; | ||
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; | ||
import org.bukkit.Location; | ||
import org.bukkit.command.CommandSender; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class LocationArgumentTest extends BukkitTestSpec { | ||
|
||
|
||
public static final Argument<Optional<Location>> ARGUMENT = Argument.of("location", new TypeToken<Optional<Location>>() {}); | ||
private ParserRegistryImpl<CommandSender> parsers = new ParserRegistryImpl<>(); | ||
|
||
@BeforeEach | ||
void before() { | ||
parsers.registerParser(Location.class, ArgumentKey.DEFAULT, new LocationArgument(new MessageRegistry<>())); | ||
parsers.registerParser(TypeRange.same(Optional.class), ArgumentKey.DEFAULT, new OptionalArgumentResolver<>()); | ||
} | ||
|
||
@Test | ||
void test() { | ||
Invocation<CommandSender> invocation = invocation("test", "pos1"); | ||
RequirementResult<Optional<Location>> result = parsers.parse(invocation, ARGUMENT, RawInput.of("1", "2", "3")) | ||
.await(); | ||
|
||
assertTrue(result.isSuccessful()); | ||
assertThat(result.getSuccess()) | ||
.hasValue(new Location(null, 1, 2, 3)); | ||
} | ||
|
||
@Test | ||
void testFail() { | ||
Invocation<CommandSender> invocation = invocation("test", "pos1"); | ||
RequirementResult<Optional<Location>> result = parsers.parse(invocation, ARGUMENT, RawInput.of("pos1")) | ||
.await(); | ||
|
||
assertTrue(result.isFailed()); | ||
} | ||
|
||
|
||
} |
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