Skip to content

Commit

Permalink
Implement test for ResourceType (#519)
Browse files Browse the repository at this point in the history
* Implement test for ResourceType

* Add the sunfire plugin

* Improve the test code

* Fix double slash
  • Loading branch information
ConnorLinfoot authored Mar 2, 2022
1 parent 7c1a067 commit 1862d9e
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
12 changes: 12 additions & 0 deletions hypixel-api-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.konghq</groupId>
<artifactId>unirest-java</artifactId>
<version>3.11.11</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import java.util.concurrent.CompletableFuture;

public class HypixelAPI {
private static final String BASE_URL = "https://api.hypixel.net/";
static final String BASE_URL = "https://api.hypixel.net/";

private final HypixelHttpClient httpClient;

Expand Down
29 changes: 29 additions & 0 deletions hypixel-api-core/src/test/java/net/hypixel/api/TestResources.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package net.hypixel.api;

import kong.unirest.HttpResponse;
import kong.unirest.JsonNode;
import kong.unirest.Unirest;
import net.hypixel.api.util.ResourceType;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import java.util.stream.Stream;

public class TestResources {

static Stream<Arguments> getResourceTypes() {
return Stream.of(ResourceType.values())
.map(Arguments::of);
}

@ParameterizedTest
@MethodSource("getResourceTypes")
void testResource(ResourceType resourceType) {
String url = String.format("%sresources/%s", HypixelAPI.BASE_URL, resourceType.getPath());
HttpResponse<JsonNode> response = Unirest.get(url).asJson();
Assertions.assertEquals(200, response.getStatus(), String.format("Got an invalid status code for %s", resourceType));
}

}
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@
<linksource>true</linksource>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>

Expand Down

0 comments on commit 1862d9e

Please sign in to comment.