Created
January 21, 2021 17:40
-
-
Save nakov/f0e268e773ba4a76c376de05c5639b46 to your computer and use it in GitHub Desktop.
GitHub API testing with Java + Maven + JUnit + UniRest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.mashape.unirest.http.JsonNode; | |
import com.mashape.unirest.http.Unirest; | |
import com.mashape.unirest.http.exceptions.UnirestException; | |
import junit.framework.*; | |
import org.json.JSONObject; | |
public class JUnitTest extends TestCase { | |
protected void setUp(){ | |
} | |
public void testGitHubAPI() throws UnirestException { | |
Unirest.setTimeouts(0, 0); | |
var request = | |
Unirest.get("https://api.github.com/repos/testnakov/test-nakov-repo/issues"); | |
var response = request.asJson(); | |
assertEquals(200, response.getStatus()); | |
JsonNode json = response.getBody(); | |
var resultArr = json.getArray(); | |
var item0 = (JSONObject) resultArr.get(0); | |
long id = item0.getLong("id"); | |
assertTrue(id > 0); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<properties> | |
<maven.compiler.target>14</maven.compiler.target> | |
<maven.compiler.source>14</maven.compiler.source> | |
</properties> | |
<groupId>org.example</groupId> | |
<artifactId>JUNit-Manev-example</artifactId> | |
<version>1.0-SNAPSHOT</version> | |
<dependencies> | |
<dependency> | |
<groupId>junit</groupId> | |
<artifactId>junit</artifactId> | |
<version>4.13.1</version> | |
</dependency> | |
<dependency> | |
<groupId>com.mashape.unirest</groupId> | |
<artifactId>unirest-java</artifactId> | |
<version>1.4.9</version> | |
</dependency> | |
</dependencies> | |
</project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment