Skip to content

Commit 9b4efc5

Browse files
authored
Merge pull request #34 from BentoBoxWorld/add-junit5-tests
Add JUnit 5 test suite (97 tests)
2 parents d94d419 + d7a4baf commit 9b4efc5

16 files changed

Lines changed: 2138 additions & 2 deletions

CLAUDE.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
ControlPanel is a BentoBox addon for Minecraft (Paper) that provides customizable GUI menus for players to execute common commands. It supports multiple gamemodes (AcidIsland, BSkyBlock, CaveBlock, SkyGrid, AOneBlock) and 13 localizations.
8+
9+
## Build Commands
10+
11+
```bash
12+
# Build the project
13+
mvn clean package
14+
15+
# Run tests
16+
mvn clean test
17+
18+
# Run tests and SonarCloud analysis (as CI does)
19+
mvn -B verify
20+
21+
# Run a single test class
22+
mvn test -Dtest=UtilsTest
23+
24+
# Build without tests
25+
mvn clean package -DskipTests
26+
```
27+
28+
**Requires Java 21.** The output JAR is placed in `target/`.
29+
30+
## Testing
31+
32+
Tests use **JUnit 5 + Mockito 5 + MockBukkit**. All integration tests extend `CommonTestSetup` which provides pre-configured mocks for BentoBox, Bukkit, Player, World, Island, and other framework objects.
33+
34+
Key test infrastructure in `src/test/java/world/bentobox/controlpanel/`:
35+
- `CommonTestSetup.java` — abstract base class with `@BeforeEach`/`@AfterEach` lifecycle, static mocks for `Bukkit` and `Util`
36+
- `WhiteBox.java` — reflection utility for setting private static fields (e.g., BentoBox singleton)
37+
- `TestWorldSettings.java` — stub `WorldSettings` implementation for tests
38+
39+
For tests requiring database access, mock `DatabaseSetup` statically and use `WhiteBox.setInternalState(Database.class, "databaseSetup", dbSetup)` to inject the mock handler.
40+
41+
## Architecture
42+
43+
This is a **BentoBox Addon** — it extends BentoBox's `Addon` class and follows its lifecycle (`onLoad``onEnable``onReload``onDisable`).
44+
45+
**Entry point:** `ControlPanelAddon.java` — registers commands, loads settings, initializes the manager.
46+
47+
**Key flow:**
48+
1. `ControlPanelAddon` hooks `PlayerCommand` and `AdminCommand` into each registered BentoBox gamemode's command tree
49+
2. `ControlPanelManager` loads/saves `ControlPanelObject` data from YAML files and caches them per-world
50+
3. `ControlPanelGenerator` builds the GUI using BentoBox's `PanelBuilder` API, resolving button actions, permissions, and placeholders (`[player]`, `[server]`, `[label]`)
51+
52+
**Data model:** `ControlPanelObject` (implements `DataObject`) represents a single control panel with its button layout. The manager parses the YAML template (`controlPanelTemplate.yml`) into these objects.
53+
54+
**Configuration:** `Settings.java` uses BentoBox's `@StoreAt`/`@ConfigEntry` annotations for YAML-backed config. The `config.yml` controls which gamemodes the addon is disabled for.
55+
56+
**Localization:** 13 locale YAML files in `src/main/resources/locales/`. Translation key constants are centralized in `Constants.java`.
57+
58+
**Optional integration:** `ItemsAdderParse.java` provides soft-dependency support for the ItemsAdder plugin's custom items.
59+
60+
## CI
61+
62+
GitHub Actions on push to `develop` and PRs: builds with Maven + runs SonarCloud analysis (project: `BentoBoxWorld_ControlPanel`).

pom.xml

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@
6969
<sonar.projectKey>BentoBoxWorld_ControlPanel</sonar.projectKey>
7070
<sonar.organization>bentobox-world</sonar.organization>
7171
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
72+
<!-- Test dependency versions -->
73+
<junit.version>5.10.2</junit.version>
74+
<mockito.version>5.11.0</mockito.version>
7275
</properties>
7376

7477
<profiles>
@@ -104,6 +107,14 @@
104107

105108
<!-- Repositories contains links from were dependencies will be searched -->
106109
<repositories>
110+
<!-- jitpack first so MockBukkit snapshots resolve without hitting other repos -->
111+
<repository>
112+
<id>jitpack.io</id>
113+
<url>https://jitpack.io</url>
114+
<snapshots>
115+
<enabled>true</enabled>
116+
</snapshots>
117+
</repository>
107118
<repository>
108119
<id>papermc</id>
109120
<url>https://repo.papermc.io/repository/maven-public/</url>
@@ -128,6 +139,36 @@
128139

129140
<!-- Your addon must contain Paper and BentoBox APIs dependencies. -->
130141
<dependencies>
142+
<dependency>
143+
<groupId>com.github.MockBukkit</groupId>
144+
<artifactId>MockBukkit</artifactId>
145+
<version>v1.21-SNAPSHOT</version>
146+
<scope>test</scope>
147+
</dependency>
148+
<dependency>
149+
<groupId>org.junit.jupiter</groupId>
150+
<artifactId>junit-jupiter-api</artifactId>
151+
<version>${junit.version}</version>
152+
<scope>test</scope>
153+
</dependency>
154+
<dependency>
155+
<groupId>org.junit.jupiter</groupId>
156+
<artifactId>junit-jupiter-engine</artifactId>
157+
<version>${junit.version}</version>
158+
<scope>test</scope>
159+
</dependency>
160+
<dependency>
161+
<groupId>org.mockito</groupId>
162+
<artifactId>mockito-junit-jupiter</artifactId>
163+
<version>${mockito.version}</version>
164+
<scope>test</scope>
165+
</dependency>
166+
<dependency>
167+
<groupId>org.mockito</groupId>
168+
<artifactId>mockito-core</artifactId>
169+
<version>${mockito.version}</version>
170+
<scope>test</scope>
171+
</dependency>
131172
<dependency>
132173
<groupId>io.papermc.paper</groupId>
133174
<artifactId>paper-api</artifactId>
@@ -221,11 +262,12 @@
221262
<plugin>
222263
<groupId>org.apache.maven.plugins</groupId>
223264
<artifactId>maven-surefire-plugin</artifactId>
224-
<version>3.1.2</version>
265+
<version>3.5.4</version>
225266
<!--suppress MavenModelInspection -->
226267
<configuration>
227268
<argLine>
228269
${argLine}
270+
-XX:+EnableDynamicAgentLoading
229271
--add-opens java.base/java.lang=ALL-UNNAMED
230272
--add-opens java.base/java.math=ALL-UNNAMED
231273
--add-opens java.base/java.io=ALL-UNNAMED
@@ -307,7 +349,7 @@
307349
<plugin>
308350
<groupId>org.jacoco</groupId>
309351
<artifactId>jacoco-maven-plugin</artifactId>
310-
<version>0.8.10</version>
352+
<version>0.8.13</version>
311353
<configuration>
312354
<append>true</append>
313355
<excludes>

0 commit comments

Comments
 (0)