Test sender conversion for players
Also refactored stuff I deprecated
This commit is contained in:
parent
a39539ea6e
commit
7996426d63
3 changed files with 61 additions and 19 deletions
|
@ -8,6 +8,7 @@ import buttondevteam.lib.chat.ICommand2MC
|
||||||
import buttondevteam.lib.player.ChromaGamerBase
|
import buttondevteam.lib.player.ChromaGamerBase
|
||||||
import buttondevteam.lib.player.TBMCPlayer
|
import buttondevteam.lib.player.TBMCPlayer
|
||||||
import org.bukkit.OfflinePlayer
|
import org.bukkit.OfflinePlayer
|
||||||
|
import org.bukkit.entity.Player
|
||||||
|
|
||||||
abstract class Command2MCCommands {
|
abstract class Command2MCCommands {
|
||||||
@CommandClass(helpText = ["Test command", "Used for testing"])
|
@CommandClass(helpText = ["Test command", "Used for testing"])
|
||||||
|
@ -117,6 +118,11 @@ abstract class Command2MCCommands {
|
||||||
fun def(sender: OfflinePlayer, testInt: Int?, testLong: Long?, testDouble: Double?, testDouble2: Double) {
|
fun def(sender: OfflinePlayer, testInt: Int?, testLong: Long?, testDouble: Double?, testDouble2: Double) {
|
||||||
testCommandReceived = "$testInt $testLong $testDouble $testDouble2 ${sender.name}"
|
testCommandReceived = "$testInt $testLong $testDouble $testDouble2 ${sender.name}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Command2.Subcommand
|
||||||
|
fun fail(sender: Player) {
|
||||||
|
testCommandReceived = sender.name
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@CommandClass
|
@CommandClass
|
||||||
|
@ -132,6 +138,16 @@ abstract class Command2MCCommands {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@CommandClass
|
||||||
|
object TestSenderConversionCommand : ICommand2MC(), ITestCommand2MC {
|
||||||
|
override var testCommandReceived: String? = null
|
||||||
|
|
||||||
|
@Command2.Subcommand
|
||||||
|
fun def(sender: Player) {
|
||||||
|
testCommandReceived = sender.name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
interface ITestCommand2MC {
|
interface ITestCommand2MC {
|
||||||
var testCommandReceived: String?
|
var testCommandReceived: String?
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import buttondevteam.lib.chat.commands.CommandUtils.coreExecutable
|
||||||
import buttondevteam.lib.chat.test.Command2MCCommands.*
|
import buttondevteam.lib.chat.test.Command2MCCommands.*
|
||||||
import buttondevteam.lib.player.ChromaGamerBase
|
import buttondevteam.lib.player.ChromaGamerBase
|
||||||
import buttondevteam.lib.player.TBMCPlayer
|
import buttondevteam.lib.player.TBMCPlayer
|
||||||
|
import buttondevteam.lib.player.TBMCPlayerBase
|
||||||
import org.junit.jupiter.api.MethodOrderer
|
import org.junit.jupiter.api.MethodOrderer
|
||||||
import org.junit.jupiter.api.Order
|
import org.junit.jupiter.api.Order
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
@ -55,14 +56,13 @@ class Command2MCTest {
|
||||||
assertEquals(Command2MCSender::class.java, coreExecutable?.data?.senderType, "The sender's type doesn't seem to be stored correctly")
|
assertEquals(Command2MCSender::class.java, coreExecutable?.data?.senderType, "The sender's type doesn't seem to be stored correctly")
|
||||||
|
|
||||||
NoArgTestCommand.register()
|
NoArgTestCommand.register()
|
||||||
val errCmd = ErroringTestCommand
|
ErroringTestCommand.registerAssertFail("No sender parameter for method '${ErroringTestCommand::class.java.getMethod("def")}'")
|
||||||
assertEquals("No sender parameter for method '${errCmd::class.java.getMethod("def")}'", assertFails { errCmd.register() }.message)
|
|
||||||
MultiArgTestCommand.register()
|
MultiArgTestCommand.register()
|
||||||
|
|
||||||
TestNoMainCommand1.register()
|
TestNoMainCommand1.register()
|
||||||
TestNoMainCommand2.register()
|
TestNoMainCommand2.register()
|
||||||
TestParamsCommand.register()
|
TestParamsCommand.register()
|
||||||
assertEquals("There are no subcommands defined in the command class TestEmptyCommand!", assertFails { TestEmptyCommand.register() }.message)
|
TestEmptyCommand.registerAssertFail("There are no subcommands defined in the command class TestEmptyCommand!")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -90,7 +90,8 @@ class Command2MCTest {
|
||||||
"/test errortest\n" +
|
"/test errortest\n" +
|
||||||
"/test playerfail\n" +
|
"/test playerfail\n" +
|
||||||
"/test plugin\n" +
|
"/test plugin\n" +
|
||||||
"/testparams", ButtonPlugin.command2MC.getCommandList(sender).joinToString("\n")
|
"/testparams\n" +
|
||||||
|
"/testparams fail", ButtonPlugin.command2MC.getCommandList(sender).joinToString("\n")
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,6 +110,15 @@ class Command2MCTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(5)
|
@Order(5)
|
||||||
|
fun testSenderConversion() {
|
||||||
|
TestSenderConversionCommand.register()
|
||||||
|
val sender = createPlayer()
|
||||||
|
sender.assertCommand("/test something", TestCommand, "something")
|
||||||
|
sender.assertCommand("/testsenderconversion", TestSenderConversionCommand, "Player2")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(6)
|
||||||
fun testHasPermission() {
|
fun testHasPermission() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,6 +128,12 @@ class Command2MCTest {
|
||||||
return TestCommand2MCSender(user)
|
return TestCommand2MCSender(user)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun createPlayer(): TestCommand2MCSender {
|
||||||
|
val player = MockBukkit.getMock().addPlayer()
|
||||||
|
val user = TBMCPlayerBase.getPlayer(player.uniqueId, TBMCPlayer::class.java)
|
||||||
|
return TestCommand2MCSender(user)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests parameter conversion, help text and errors.
|
* Tests parameter conversion, help text and errors.
|
||||||
*/
|
*/
|
||||||
|
@ -127,13 +143,16 @@ class Command2MCTest {
|
||||||
sender.assertCrashingCommand("/test playerfail TestPlayer") { it.cause?.message == "No suitable converter found for class buttondevteam.lib.player.TBMCPlayer param1" }
|
sender.assertCrashingCommand("/test playerfail TestPlayer") { it.cause?.message == "No suitable converter found for class buttondevteam.lib.player.TBMCPlayer param1" }
|
||||||
sender.assertCommandUserError("/test plugin asd", "§cError: §cNo Chroma plugin found by that name.")
|
sender.assertCommandUserError("/test plugin asd", "§cError: §cNo Chroma plugin found by that name.")
|
||||||
sender.assertCrashingCommand("/test errortest") { it.cause?.cause?.message === "Hmm" }
|
sender.assertCrashingCommand("/test errortest") { it.cause?.cause?.message === "Hmm" }
|
||||||
assertEquals(
|
sender.assertCommandReceiveMessage(
|
||||||
"Test command\n" +
|
"/test",
|
||||||
"Used for testing\n" +
|
"""
|
||||||
"§6---- Subcommands ----\n" +
|
Test command
|
||||||
"/test errortest\n" +
|
Used for testing
|
||||||
"/test playerfail\n" +
|
§6---- Subcommands ----
|
||||||
"/test plugin", sender.runCommandWithReceive("/test")
|
/test errortest
|
||||||
|
/test playerfail
|
||||||
|
/test plugin
|
||||||
|
""".trimIndent()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,8 +183,9 @@ class Command2MCTest {
|
||||||
*/
|
*/
|
||||||
private fun testTestParamsCommand(sender: TestCommand2MCSender) {
|
private fun testTestParamsCommand(sender: TestCommand2MCSender) {
|
||||||
sender.assertCommand("/testparams 12 34 56 78", TestParamsCommand, "12 34 56.0 78.0 Player0")
|
sender.assertCommand("/testparams 12 34 56 78", TestParamsCommand, "12 34 56.0 78.0 Player0")
|
||||||
assertEquals("§cExpected integer at position 11: ...estparams <--[HERE]", sender.runCommandWithReceive("/testparams asd 34 56 78"))
|
sender.assertCommandReceiveMessage("/testparams asd 34 56 78", "§cExpected integer at position 11: ...estparams <--[HERE]\n§6---- Subcommands ----\n/testparams fail")
|
||||||
// TODO: Change test when usage help is added
|
// TODO: Change test when usage help is added
|
||||||
|
sender.assertCommandUserError("/testparams fail", "§cYou need to be a player to use this command.")
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -174,10 +194,12 @@ class Command2MCTest {
|
||||||
private fun testSomeCommand(sender: TestCommand2MCSender) {
|
private fun testSomeCommand(sender: TestCommand2MCSender) {
|
||||||
sender.assertCommand("/some test cmd", TestNoMainCommand1, "TestPlayer")
|
sender.assertCommand("/some test cmd", TestNoMainCommand1, "TestPlayer")
|
||||||
sender.assertCommand("/some another cmd", TestNoMainCommand2, "TestPlayer")
|
sender.assertCommand("/some another cmd", TestNoMainCommand2, "TestPlayer")
|
||||||
assertEquals(
|
sender.assertCommandReceiveMessage(
|
||||||
"§6---- Subcommands ----\n" +
|
"/some", """
|
||||||
"/some another cmd\n" +
|
§6---- Subcommands ----
|
||||||
"/some test cmd", sender.runCommandWithReceive("/some")
|
/some another cmd
|
||||||
|
/some test cmd
|
||||||
|
""".trimIndent()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,6 +207,13 @@ class Command2MCTest {
|
||||||
MainPlugin.instance.registerCommand(this)
|
MainPlugin.instance.registerCommand(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempts to register a command, expecting the given error (exception) message.
|
||||||
|
*/
|
||||||
|
private fun ICommand2MC.registerAssertFail(expected: String) {
|
||||||
|
assertEquals(expected, assertFails { this.register() }.message)
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private var initialized = false
|
private var initialized = false
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
package buttondevteam.lib.chat.test
|
|
||||||
|
|
||||||
class TestConvertedUser(val name: String)
|
|
Loading…
Reference in a new issue