Skip to content

Commit 88bcd0e

Browse files
authored
Merge pull request #57 from ez-plugins/fix/improve-test-coverage
Improved test coverage
2 parents d0fb22c + 5004f56 commit 88bcd0e

42 files changed

Lines changed: 2694 additions & 84 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 2 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -5,66 +5,6 @@ on:
55
branches: [ main, master ]
66

77
jobs:
8-
unit-tests:
9-
runs-on: ubuntu-latest
10-
strategy:
11-
matrix:
12-
include:
13-
- paper-version: "1.21.11-R0.1-SNAPSHOT"
14-
mockbukkit-artifactId: "mockbukkit-v1.21"
15-
mockbukkit-version: "4.101.0"
16-
17-
steps:
18-
- name: Checkout
19-
uses: actions/checkout@v6
20-
21-
- name: Set up JDK 21
22-
uses: actions/setup-java@v5
23-
with:
24-
distribution: temurin
25-
java-version: '21'
26-
27-
- name: Cache Maven local repository
28-
uses: actions/cache@v5
29-
with:
30-
path: ~/.m2/repository
31-
key: ${{ runner.os }}-m2-${{ matrix.paper-version }}-${{ hashFiles('**/pom.xml') }}
32-
restore-keys: |
33-
${{ runner.os }}-m2-${{ matrix.paper-version }}-
34-
35-
- name: Run unit tests
36-
run: mvn -B -Dpaper.version=${{ matrix.paper-version }} -Dmockbukkit.artifactId=${{ matrix.mockbukkit-artifactId }} -Dmockbukkit.version=${{ matrix.mockbukkit-version }} test
37-
38-
feature-tests:
39-
runs-on: ubuntu-latest
40-
needs: unit-tests
41-
strategy:
42-
matrix:
43-
include:
44-
- paper-version: "1.21.11-R0.1-SNAPSHOT"
45-
mockbukkit-artifactId: "mockbukkit-v1.21"
46-
mockbukkit-version: "4.101.0"
47-
48-
steps:
49-
- name: Checkout
50-
uses: actions/checkout@v6
51-
52-
- name: Set up JDK 21
53-
uses: actions/setup-java@v5
54-
with:
55-
distribution: temurin
56-
java-version: '21'
57-
58-
- name: Cache Maven local repository
59-
uses: actions/cache@v5
60-
with:
61-
path: ~/.m2/repository
62-
key: ${{ runner.os }}-m2-feature-${{ matrix.paper-version }}-${{ hashFiles('**/pom.xml') }}
63-
restore-keys: |
64-
${{ runner.os }}-m2-feature-${{ matrix.paper-version }}-
65-
66-
- name: Run feature tests
67-
run: mvn -B -Dpaper.version=${{ matrix.paper-version }} -Dmockbukkit.artifactId=${{ matrix.mockbukkit-artifactId }} -Dmockbukkit.version=${{ matrix.mockbukkit-version }} -Pfeature-tests -Dtest=*FeatureTest test
688

699
# ─────────────────────────────────────────────────────────────────────────
7010
# Smoke tests — Paper & Folia (downloaded from api.papermc.io)
@@ -73,7 +13,7 @@ jobs:
7313
smoke-papermc:
7414
name: "Smoke · ${{ matrix.platform }} / MC ${{ matrix.mc-prefix }} / Java ${{ matrix.java }}"
7515
runs-on: ubuntu-latest
76-
needs: [unit-tests, feature-tests]
16+
needs: []
7717
strategy:
7818
fail-fast: false
7919
matrix:
@@ -205,7 +145,7 @@ jobs:
205145
smoke-spigot:
206146
name: "Smoke · spigot / MC ${{ matrix.mc-prefix }} / Java ${{ matrix.java }}"
207147
runs-on: ubuntu-latest
208-
needs: [unit-tests, feature-tests]
148+
needs: []
209149
strategy:
210150
fail-fast: false
211151
matrix:

.github/workflows/tests.yml

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
name: Tests
2+
3+
on:
4+
pull_request:
5+
branches: [ main, master ]
6+
push:
7+
branches: [ main, master ]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
unit-tests-coverage:
14+
name: Unit Tests + Coverage
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
include:
19+
- paper-version: "1.21.11-R0.1-SNAPSHOT"
20+
mockbukkit-artifactId: "mockbukkit-v1.21"
21+
mockbukkit-version: "4.101.0"
22+
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v6
26+
27+
- name: Set up JDK 21
28+
uses: actions/setup-java@v5
29+
with:
30+
distribution: temurin
31+
java-version: '21'
32+
cache: maven
33+
34+
- name: Run unit tests with JaCoCo
35+
run: >
36+
mvn -B -ntp
37+
-Dpaper.version=${{ matrix.paper-version }}
38+
-Dmockbukkit.artifactId=${{ matrix.mockbukkit-artifactId }}
39+
-Dmockbukkit.version=${{ matrix.mockbukkit-version }}
40+
jacoco:prepare-agent test jacoco:report
41+
42+
- name: Upload coverage artifact
43+
uses: actions/upload-artifact@v7
44+
with:
45+
name: unit-coverage-report
46+
path: target/site/jacoco/jacoco.xml
47+
if-no-files-found: error
48+
retention-days: 7
49+
50+
- name: Upload unit coverage to Codecov
51+
uses: codecov/codecov-action@v5
52+
with:
53+
files: target/site/jacoco/jacoco.xml
54+
flags: unit-tests
55+
name: unit-tests
56+
fail_ci_if_error: false
57+
token: ${{ secrets.CODECOV_TOKEN }}
58+
59+
feature-tests-coverage:
60+
name: Feature Tests + Coverage
61+
runs-on: ubuntu-latest
62+
strategy:
63+
matrix:
64+
include:
65+
- paper-version: "1.21.11-R0.1-SNAPSHOT"
66+
mockbukkit-artifactId: "mockbukkit-v1.21"
67+
mockbukkit-version: "4.101.0"
68+
69+
steps:
70+
- name: Checkout
71+
uses: actions/checkout@v6
72+
73+
- name: Set up JDK 21
74+
uses: actions/setup-java@v5
75+
with:
76+
distribution: temurin
77+
java-version: '21'
78+
cache: maven
79+
80+
- name: Run feature tests with JaCoCo
81+
run: >
82+
mvn -B -ntp
83+
-Dpaper.version=${{ matrix.paper-version }}
84+
-Dmockbukkit.artifactId=${{ matrix.mockbukkit-artifactId }}
85+
-Dmockbukkit.version=${{ matrix.mockbukkit-version }}
86+
-Pfeature-tests -Dtest=*FeatureTest
87+
jacoco:prepare-agent test jacoco:report
88+
89+
- name: Upload coverage artifact
90+
uses: actions/upload-artifact@v7
91+
with:
92+
name: feature-coverage-report
93+
path: target/site/jacoco/jacoco.xml
94+
if-no-files-found: error
95+
retention-days: 7
96+
97+
- name: Upload feature coverage to Codecov
98+
uses: codecov/codecov-action@v5
99+
with:
100+
files: target/site/jacoco/jacoco.xml
101+
flags: feature-tests
102+
name: feature-tests
103+
fail_ci_if_error: false
104+
token: ${{ secrets.CODECOV_TOKEN }}

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ pom.xml.next
2929
*.iml
3030
*.ipr
3131
*.iws
32-
/.vscode/
32+
/.vscode/*
33+
!/.vscode/settings.json
34+
!/.vscode/tasks.json
35+
!/.vscode/extensions.json
3336
/out/
3437

3538
# Eclipse

.vscode/extensions.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"recommendations": [
3+
"ryanluker.vscode-coverage-gutters"
4+
]
5+
}

.vscode/settings.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"java.debug.settings.onBuildFailureProceed": true,
3+
"java.configuration.updateBuildConfiguration": "automatic",
4+
"coverage-gutters.coverageBaseDir": "${workspaceFolder}",
5+
"coverage-gutters.coverageFileNames": [
6+
"jacoco.xml"
7+
],
8+
"coverage-gutters.showLineCoverage": true,
9+
"coverage-gutters.showRulerCoverage": true,
10+
"coverage-gutters.showGutterCoverage": true
11+
}

.vscode/tasks.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "Tests: Unit Coverage (JaCoCo)",
6+
"type": "shell",
7+
"command": "mvn",
8+
"args": [
9+
"-B",
10+
"-ntp",
11+
"jacoco:prepare-agent",
12+
"test",
13+
"jacoco:report"
14+
],
15+
"group": "test",
16+
"problemMatcher": []
17+
},
18+
{
19+
"label": "Tests: Feature Coverage (JaCoCo)",
20+
"type": "shell",
21+
"command": "mvn",
22+
"args": [
23+
"-B",
24+
"-ntp",
25+
"-Pfeature-tests",
26+
"-Dtest=*FeatureTest",
27+
"jacoco:prepare-agent",
28+
"test",
29+
"jacoco:report"
30+
],
31+
"group": "test",
32+
"problemMatcher": []
33+
}
34+
]
35+
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# EzCountdown
2-
[![CI](https://github.com/ez-plugins/EzCountdown/actions/workflows/ci.yml/badge.svg)](https://github.com/ez-plugins/EzCountdown/actions/workflows/ci.yml) [![Release](https://img.shields.io/github/v/release/ez-plugins/EzCountdown)](https://github.com/ez-plugins/EzCountdown/releases) [![License](https://img.shields.io/github/license/ez-plugins/EzCountdown)](https://github.com/ez-plugins/EzCountdown/blob/main/LICENSE) [![Issues](https://img.shields.io/github/issues/ez-plugins/EzCountdown)](https://github.com/ez-plugins/EzCountdown/issues)
2+
[![CI](https://github.com/ez-plugins/EzCountdown/actions/workflows/ci.yml/badge.svg)](https://github.com/ez-plugins/EzCountdown/actions/workflows/ci.yml) [![Coverage](https://codecov.io/gh/ez-plugins/EzCountdown/branch/main/graph/badge.svg)](https://codecov.io/gh/ez-plugins/EzCountdown) [![Release](https://img.shields.io/github/v/release/ez-plugins/EzCountdown)](https://github.com/ez-plugins/EzCountdown/releases) [![License](https://img.shields.io/github/license/ez-plugins/EzCountdown)](https://github.com/ez-plugins/EzCountdown/blob/main/LICENSE) [![Issues](https://img.shields.io/github/issues/ez-plugins/EzCountdown)](https://github.com/ez-plugins/EzCountdown/issues)
33

44
EzCountdown provides configurable countdown timers for events, launches, and maintenance windows across your server.
55

pom.xml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,23 @@
175175
<version>3.0.0-M7</version>
176176
<configuration>
177177
<useModulePath>false</useModulePath>
178-
<argLine>-Dnet.bytebuddy.experimental=true</argLine>
178+
<argLine>${argLine} -Dnet.bytebuddy.experimental=true</argLine>
179+
<includes>
180+
<include>**/*Test.java</include>
181+
<include>**/*Tests.java</include>
182+
<include>**/*TestCase.java</include>
183+
<include>**/*UnitTest.java</include>
184+
</includes>
179185
<excludes>
180186
<exclude>**/*FeatureTest.java</exclude>
181187
</excludes>
182188
</configuration>
183189
</plugin>
190+
<plugin>
191+
<groupId>org.jacoco</groupId>
192+
<artifactId>jacoco-maven-plugin</artifactId>
193+
<version>0.8.12</version>
194+
</plugin>
184195
<plugin>
185196
<groupId>org.apache.maven.plugins</groupId>
186197
<artifactId>maven-resources-plugin</artifactId>
@@ -312,6 +323,7 @@
312323
<artifactId>maven-surefire-plugin</artifactId>
313324
<version>3.0.0-M7</version>
314325
<configuration>
326+
<argLine>${argLine} -Dnet.bytebuddy.experimental=true</argLine>
315327
<includes>
316328
<include>**/*FeatureTest.java</include>
317329
</includes>

src/main/java/com/skyblockexp/ezcountdown/listener/actions/EditEndSoundAction.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,14 @@ public ActionResult handle(InventoryClickEvent event, Player player, String cdNa
3939
registry.scheduler().runTask(() -> registry.gui().editorMenu().openEditor(player, cd));
4040
return;
4141
}
42-
try {
43-
Sound.valueOf(value.toUpperCase(Locale.ROOT));
42+
String normalized = value.toUpperCase(Locale.ROOT);
43+
boolean exists = java.util.Arrays.stream(Sound.values()).anyMatch(s -> s.name().equals(normalized));
44+
if (exists) {
4445
cd.setEndSound(value.toUpperCase(Locale.ROOT));
4546
manager.save();
4647
player.sendMessage(messageManager.message("gui.edit.saved", java.util.Map.of("name", cdName)));
4748
registry.scheduler().runTask(() -> registry.gui().editorMenu().openEditor(player, cd));
48-
} catch (IllegalArgumentException ex) {
49+
} else {
4950
player.sendMessage(org.bukkit.ChatColor.RED + "Invalid sound name: " + value);
5051
SoundEditorHelper.sendAvailableSounds(player);
5152
}

src/main/java/com/skyblockexp/ezcountdown/listener/actions/EditStartSoundAction.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,14 @@ public ActionResult handle(InventoryClickEvent event, Player player, String cdNa
3939
registry.scheduler().runTask(() -> registry.gui().editorMenu().openEditor(player, cd));
4040
return;
4141
}
42-
try {
43-
Sound.valueOf(value.toUpperCase(Locale.ROOT));
42+
String normalized = value.toUpperCase(Locale.ROOT);
43+
boolean exists = java.util.Arrays.stream(Sound.values()).anyMatch(s -> s.name().equals(normalized));
44+
if (exists) {
4445
cd.setStartSound(value.toUpperCase(Locale.ROOT));
4546
manager.save();
4647
player.sendMessage(messageManager.message("gui.edit.saved", java.util.Map.of("name", cdName)));
4748
registry.scheduler().runTask(() -> registry.gui().editorMenu().openEditor(player, cd));
48-
} catch (IllegalArgumentException ex) {
49+
} else {
4950
player.sendMessage(org.bukkit.ChatColor.RED + "Invalid sound name: " + value);
5051
SoundEditorHelper.sendAvailableSounds(player);
5152
}

0 commit comments

Comments
 (0)