Skip to content

Commit

Permalink
Create commandapi-bukkit-test-toolkit
Browse files Browse the repository at this point in the history
Create `automated-tests-shaded` example project to test using the test toolkit

Resolves #356

Alternative idea to current work on `dev/public-test-suite`

Attempts to allow developers to test their commands independently of any version or nms stuff. Currently, most of the methods throw an UnimplementedMethodException, but I have implemented enough to get the simple `PingPongCommandTests` file to work as a proof of concept.

TODO:
- Implement the methods required to test:
  - `commandapi-bukkit-plugin` based projects
  - Common arguments
  - Suggestions
- Write documentation
- Maybe add a module to more rigorously test the toolkit without cluttering the example project

I think if we can get a simple version working and published as a snapshot, users can try it out and identify methods that need to be implemented.
  • Loading branch information
willkroboth committed Jul 4, 2024
1 parent ee5907b commit 48992d1
Show file tree
Hide file tree
Showing 14 changed files with 1,008 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>dev.jorel</groupId>
<artifactId>commandapi-bukkit</artifactId>
<version>9.6.0-SNAPSHOT</version>
</parent>

<artifactId>commandapi-bukkit-test-toolkit</artifactId>

<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<repositories>
<repository>
<id>minecraft-libraries</id>
<name>Minecraft Libraries</name>
<url>https://libraries.minecraft.net</url>
</repository>
</repositories>

<dependencies>
<!-- Compatibility with Spigot API-->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.20.6-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

<!-- Compatibility with Adventure API -->
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-platform-bukkit</artifactId>
<version>4.2.0</version>
<scope>provided</scope>
</dependency>

<!-- Compatibility with CommandAPI Bukkit API -->
<dependency>
<groupId>dev.jorel</groupId>
<artifactId>commandapi-bukkit-core</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>

<!-- Compatibility with JUnit API -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.8.2</version>
<scope>provided</scope>
</dependency>

<!-- Pass Brigadier to our dependents -->
<dependency>
<groupId>com.mojang</groupId>
<artifactId>brigadier</artifactId>
<version>1.0.18</version>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<!-- Remove commandapi-core's VersionHandler in favor of ours -->
<filters>
<filter>
<artifact>dev.jorel:commandapi-core</artifact>
<excludes>
<exclude>dev/jorel/commandapi/CommandAPIVersionHandler**</exclude>
</excludes>
</filter>
</filters>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>LICENSE</resource>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package dev.jorel.commandapi;

import com.mojang.brigadier.exceptions.CommandSyntaxException;
import org.bukkit.command.CommandSender;

import static org.junit.jupiter.api.Assertions.fail;

public class CommandAPITestUtilities {
public static MockCommandAPIBukkit getCommandAPIPlatform() {
return MockCommandAPIBukkit.getInstance();
}

public static void dispatchCommand(CommandSender sender, String command) {
try {
dispatchThrowableCommand(sender, command);
} catch (CommandSyntaxException exception) {
fail(
"Expected command dispatch to succeed." +
" If you expected this to fail, use `dispatchFailableCommand` instead.",
exception
);
}
}

public static void dispatchThrowableCommand(CommandSender sender, String command) throws CommandSyntaxException {
getCommandAPIPlatform().getBrigadierDispatcher().execute(command, new MockCommandSource(sender));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package dev.jorel.commandapi;

public interface CommandAPIVersionHandler {
static CommandAPIPlatform<?, ?, ?> getPlatform() {
return new MockCommandAPIBukkit();
}
}
Loading

0 comments on commit 48992d1

Please sign in to comment.