Skip to content

Commit 1862d9e

Browse files
Implement test for ResourceType (#519)
* Implement test for ResourceType * Add the sunfire plugin * Improve the test code * Fix double slash
1 parent 7c1a067 commit 1862d9e

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

hypixel-api-core/pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@
2222
<artifactId>gson</artifactId>
2323
<version>2.8.6</version>
2424
</dependency>
25+
<dependency>
26+
<groupId>org.junit.jupiter</groupId>
27+
<artifactId>junit-jupiter</artifactId>
28+
<version>5.8.2</version>
29+
<scope>test</scope>
30+
</dependency>
31+
<dependency>
32+
<groupId>com.konghq</groupId>
33+
<artifactId>unirest-java</artifactId>
34+
<version>3.11.11</version>
35+
<scope>test</scope>
36+
</dependency>
2537
</dependencies>
2638

2739
</project>

hypixel-api-core/src/main/java/net/hypixel/api/HypixelAPI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import java.util.concurrent.CompletableFuture;
1818

1919
public class HypixelAPI {
20-
private static final String BASE_URL = "https://api.hypixel.net/";
20+
static final String BASE_URL = "https://api.hypixel.net/";
2121

2222
private final HypixelHttpClient httpClient;
2323

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package net.hypixel.api;
2+
3+
import kong.unirest.HttpResponse;
4+
import kong.unirest.JsonNode;
5+
import kong.unirest.Unirest;
6+
import net.hypixel.api.util.ResourceType;
7+
import org.junit.jupiter.api.Assertions;
8+
import org.junit.jupiter.params.ParameterizedTest;
9+
import org.junit.jupiter.params.provider.Arguments;
10+
import org.junit.jupiter.params.provider.MethodSource;
11+
12+
import java.util.stream.Stream;
13+
14+
public class TestResources {
15+
16+
static Stream<Arguments> getResourceTypes() {
17+
return Stream.of(ResourceType.values())
18+
.map(Arguments::of);
19+
}
20+
21+
@ParameterizedTest
22+
@MethodSource("getResourceTypes")
23+
void testResource(ResourceType resourceType) {
24+
String url = String.format("%sresources/%s", HypixelAPI.BASE_URL, resourceType.getPath());
25+
HttpResponse<JsonNode> response = Unirest.get(url).asJson();
26+
Assertions.assertEquals(200, response.getStatus(), String.format("Got an invalid status code for %s", resourceType));
27+
}
28+
29+
}

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@
5858
<linksource>true</linksource>
5959
</configuration>
6060
</plugin>
61+
<plugin>
62+
<groupId>org.apache.maven.plugins</groupId>
63+
<artifactId>maven-surefire-plugin</artifactId>
64+
<version>2.22.2</version>
65+
</plugin>
6166
</plugins>
6267
</build>
6368

0 commit comments

Comments
 (0)