Skip to content

Commit c6405f0

Browse files
committed
Add CommandExecutionTests (Java and Kotlin and DSL)
Addresses todo in CommandAPI@62d5ea5 on `dev/command-build-rewrite` Made `MockPlatform` respect `forceNative` parameter of `getSenderForCommand` (Copied from 9cf533d and partially from 24692f8) Expand testing framework to work for all sender types
1 parent 82dc0ce commit c6405f0

File tree

18 files changed

+2063
-119
lines changed

18 files changed

+2063
-119
lines changed

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-kotlin-test/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<maven.compiler.source>16</maven.compiler.source>
1717
<maven.compiler.target>16</maven.compiler.target>
1818
<kotlin.compiler.incremental>true</kotlin.compiler.incremental>
19-
<junit-jupiter.version>5.4.2</junit-jupiter.version>
19+
<junit-jupiter.version>5.8.2</junit-jupiter.version>
2020
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
2121
</properties>
2222

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-kotlin-test/src/test/kotlin/dev/jorel/commandapi/test/CommandAPIServerMock.kt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package dev.jorel.commandapi.test
22

33
import be.seeseemelk.mockbukkit.ServerMock
4+
import be.seeseemelk.mockbukkit.entity.PlayerMock
45
import com.mojang.brigadier.context.StringRange
56
import com.mojang.brigadier.exceptions.CommandSyntaxException
67
import com.mojang.brigadier.suggestion.Suggestions
78
import dev.jorel.commandapi.Brigadier
89
import org.bukkit.Keyed
910
import org.bukkit.Registry
1011
import org.bukkit.command.CommandSender
12+
import org.bukkit.entity.Player
1113
import org.bukkit.scoreboard.Criteria
1214
import org.junit.jupiter.api.Assertions
1315
import java.util.concurrent.ExecutionException
@@ -68,6 +70,27 @@ class CommandAPIServerMock : ServerMock() {
6870
return suggestionsAsStrings
6971
}
7072

73+
/**
74+
* Creates a new Bukkit [Player]. Unlike [PlayerMock], this uses Mockito to mock the CraftPlayer class,
75+
* which allows the returned object to pass through VanillaCommandWrapper#getListener without error.
76+
*
77+
* @return A new [Player].
78+
*/
79+
fun setupMockedCraftPlayer(): Player {
80+
return setupMockedCraftPlayer("defaultName")
81+
}
82+
83+
/**
84+
* Creates a new Bukkit [Player]. Unlike [PlayerMock], this uses Mockito to mock the CraftPlayer class,
85+
* which allows the returned object to pass through VanillaCommandWrapper#getListener without error.
86+
*
87+
* @param name The name for the player
88+
* @return A new [Player].
89+
*/
90+
fun setupMockedCraftPlayer(name: String?): Player {
91+
return MockPlatform.getInstance<Any>().setupMockedCraftPlayer(name)
92+
}
93+
7194
override fun isTickingWorlds(): Boolean {
7295
TODO("Not yet implemented")
7396
}

0 commit comments

Comments
 (0)