Skip to content

Commit 4032e55

Browse files
Implement tests via GitHub actions (#602)
1 parent 11fc458 commit 4032e55

File tree

5 files changed

+89
-14
lines changed

5 files changed

+89
-14
lines changed

.github/workflows/maven.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Maven Package
1+
name: Maven Verify
22

33
on:
44
push:
@@ -10,11 +10,13 @@ jobs:
1010
build:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v2
13+
- uses: actions/checkout@v4
1414
- name: Set up JDK 8
15-
uses: actions/setup-java@v2
15+
uses: actions/setup-java@v4
1616
with:
1717
java-version: '8'
1818
distribution: 'adopt'
1919
- name: Build with Maven
20-
run: mvn -B package --file pom.xml
20+
run: mvn -B verify --file pom.xml
21+
env:
22+
HYPIXEL_API_KEY: ${{ secrets.HYPIXEL_API_KEY }}

hypixel-api-example/pom.xml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
<target>1.8</target>
2626
</configuration>
2727
</plugin>
28+
<plugin>
29+
<groupId>org.apache.maven.plugins</groupId>
30+
<artifactId>maven-surefire-plugin</artifactId>
31+
<version>2.22.2</version>
32+
</plugin>
2833
</plugins>
2934
</build>
3035

@@ -35,14 +40,10 @@
3540
<version>4.3</version>
3641
</dependency>
3742
<dependency>
38-
<groupId>com.konghq</groupId>
39-
<artifactId>unirest-java</artifactId>
40-
<version>3.14.4</version>
41-
</dependency>
42-
<dependency>
43-
<groupId>org.apache.httpcomponents</groupId>
44-
<artifactId>httpclient</artifactId>
45-
<version>4.5.14</version>
43+
<groupId>org.junit.jupiter</groupId>
44+
<artifactId>junit-jupiter</artifactId>
45+
<version>5.9.3</version>
46+
<scope>test</scope>
4647
</dependency>
4748
</dependencies>
4849

hypixel-api-example/src/main/java/net/hypixel/api/example/ExampleUtil.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,19 @@
99

1010
public class ExampleUtil {
1111

12+
private static String getApiKey() {
13+
String apiKey = System.getenv("HYPIXEL_API_KEY");
14+
if (apiKey != null) {
15+
return apiKey;
16+
}
17+
18+
return System.getProperty("apiKey", "64bd424e-ccb0-42ed-8b66-6e42a135afb4"); // arbitrary key, replace with your own to test or use the property
19+
}
20+
1221
public static final HypixelAPI API;
1322

1423
static {
15-
String key = System.getProperty("apiKey", "64bd424e-ccb0-42ed-8b66-6e42a135afb4"); // arbitrary key, replace with your own to test or use the property
16-
API = new HypixelAPI(new ApacheHttpClient(UUID.fromString(key)));
24+
API = new HypixelAPI(new ApacheHttpClient(UUID.fromString(getApiKey())));
1725
}
1826

1927
public static final UUID HYPIXEL = UUID.fromString("f7c77d99-9f15-4a66-a87d-c4a51ef30d19");
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package net.hypixel.api.example;
2+
3+
import net.hypixel.api.reply.*;
4+
import org.junit.jupiter.api.Assertions;
5+
import org.junit.jupiter.api.Test;
6+
7+
import java.util.concurrent.ExecutionException;
8+
import java.util.concurrent.TimeUnit;
9+
import java.util.concurrent.TimeoutException;
10+
11+
public class TestAuthenticatedEndpoints {
12+
13+
@Test
14+
void boosters() throws ExecutionException, InterruptedException, TimeoutException {
15+
BoostersReply response = ExampleUtil.API.getBoosters().get(5, TimeUnit.SECONDS);
16+
17+
Assertions.assertTrue(response.isSuccess());
18+
}
19+
20+
@Test
21+
void leaderboards() throws ExecutionException, InterruptedException, TimeoutException {
22+
LeaderboardsReply response = ExampleUtil.API.getLeaderboards().get(5, TimeUnit.SECONDS);
23+
24+
Assertions.assertTrue(response.isSuccess());
25+
}
26+
27+
@Test
28+
void punishmentStats() throws ExecutionException, InterruptedException, TimeoutException {
29+
PunishmentStatsReply response = ExampleUtil.API.getPunishmentStats().get(5, TimeUnit.SECONDS);
30+
31+
Assertions.assertTrue(response.isSuccess());
32+
}
33+
34+
@Test
35+
void player() throws ExecutionException, InterruptedException, TimeoutException {
36+
PlayerReply response = ExampleUtil.API.getPlayerByUuid(ExampleUtil.HYPIXEL).get(5, TimeUnit.SECONDS);
37+
38+
Assertions.assertTrue(response.isSuccess());
39+
Assertions.assertNotNull(response.getPlayer());
40+
Assertions.assertNotNull(response.getPlayer().getName());
41+
Assertions.assertNotNull(response.getPlayer().getUuid());
42+
}
43+
44+
@Test
45+
void guild() throws ExecutionException, InterruptedException, TimeoutException {
46+
GuildReply response = ExampleUtil.API.getGuildByPlayer(ExampleUtil.HYPIXEL).get(5, TimeUnit.SECONDS);
47+
48+
Assertions.assertTrue(response.isSuccess());
49+
Assertions.assertNotNull(response.getGuild());
50+
Assertions.assertNotNull(response.getGuild().getName());
51+
Assertions.assertNotNull(response.getGuild().getId());
52+
}
53+
54+
@Test
55+
void counts() throws ExecutionException, InterruptedException, TimeoutException {
56+
CountsReply response = ExampleUtil.API.getCounts().get(5, TimeUnit.SECONDS);
57+
58+
Assertions.assertTrue(response.isSuccess());
59+
Assertions.assertTrue(response.getPlayerCount() >= 0);
60+
Assertions.assertFalse(response.getGames().isEmpty());
61+
}
62+
63+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
junit.jupiter.execution.parallel.enabled=true

0 commit comments

Comments
 (0)