Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement tests via GitHub actions #602

Merged
merged 13 commits into from
Mar 5, 2024
10 changes: 6 additions & 4 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Maven Package
name: Maven Verify

on:
push:
Expand All @@ -10,11 +10,13 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up JDK 8
uses: actions/setup-java@v2
uses: actions/setup-java@v4
with:
java-version: '8'
distribution: 'adopt'
- name: Build with Maven
run: mvn -B package --file pom.xml
run: mvn -B verify --file pom.xml
env:
HYPIXEL_API_KEY: ${{ secrets.HYPIXEL_API_KEY }}
17 changes: 9 additions & 8 deletions hypixel-api-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>

Expand All @@ -35,14 +40,10 @@
<version>4.3</version>
</dependency>
<dependency>
<groupId>com.konghq</groupId>
<artifactId>unirest-java</artifactId>
<version>3.14.4</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.14</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.9.3</version>
<scope>test</scope>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@

public class ExampleUtil {

private static String getApiKey() {
String apiKey = System.getenv("HYPIXEL_API_KEY");
if (apiKey != null) {
return apiKey;
}

return System.getProperty("apiKey", "64bd424e-ccb0-42ed-8b66-6e42a135afb4"); // arbitrary key, replace with your own to test or use the property
}

public static final HypixelAPI API;

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

public static final UUID HYPIXEL = UUID.fromString("f7c77d99-9f15-4a66-a87d-c4a51ef30d19");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package net.hypixel.api.example;

import net.hypixel.api.reply.*;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class TestAuthenticatedEndpoints {

@Test
void boosters() throws ExecutionException, InterruptedException, TimeoutException {
BoostersReply response = ExampleUtil.API.getBoosters().get(5, TimeUnit.SECONDS);

Assertions.assertTrue(response.isSuccess());
}

@Test
void leaderboards() throws ExecutionException, InterruptedException, TimeoutException {
LeaderboardsReply response = ExampleUtil.API.getLeaderboards().get(5, TimeUnit.SECONDS);

Assertions.assertTrue(response.isSuccess());
}

@Test
void punishmentStats() throws ExecutionException, InterruptedException, TimeoutException {
PunishmentStatsReply response = ExampleUtil.API.getPunishmentStats().get(5, TimeUnit.SECONDS);

Assertions.assertTrue(response.isSuccess());
}

@Test
void player() throws ExecutionException, InterruptedException, TimeoutException {
PlayerReply response = ExampleUtil.API.getPlayerByUuid(ExampleUtil.HYPIXEL).get(5, TimeUnit.SECONDS);

Assertions.assertTrue(response.isSuccess());
Assertions.assertNotNull(response.getPlayer());
Assertions.assertNotNull(response.getPlayer().getName());
Assertions.assertNotNull(response.getPlayer().getUuid());
}

@Test
void guild() throws ExecutionException, InterruptedException, TimeoutException {
GuildReply response = ExampleUtil.API.getGuildByPlayer(ExampleUtil.HYPIXEL).get(5, TimeUnit.SECONDS);

Assertions.assertTrue(response.isSuccess());
Assertions.assertNotNull(response.getGuild());
Assertions.assertNotNull(response.getGuild().getName());
Assertions.assertNotNull(response.getGuild().getId());
}

@Test
void counts() throws ExecutionException, InterruptedException, TimeoutException {
CountsReply response = ExampleUtil.API.getCounts().get(5, TimeUnit.SECONDS);

Assertions.assertTrue(response.isSuccess());
Assertions.assertTrue(response.getPlayerCount() >= 0);
Assertions.assertFalse(response.getGames().isEmpty());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
junit.jupiter.execution.parallel.enabled=true