Skip to content

Commit cebef61

Browse files
committed
Added tests
1 parent 4ea3175 commit cebef61

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

pom.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,18 @@
6565
<version>3.9.0</version>
6666
<scope>compile</scope>
6767
</dependency>
68+
<dependency>
69+
<groupId>org.junit.jupiter</groupId>
70+
<artifactId>junit-jupiter-api</artifactId>
71+
<version>5.2.0</version>
72+
<scope>test</scope>
73+
</dependency>
6874
</dependencies>
6975

7076
<build>
7177
<defaultGoal>clean package</defaultGoal>
7278
<directory>target</directory>
7379
<outputDirectory>target/classes</outputDirectory>
74-
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
7580

7681
<finalName>${project.name}-${project.version}</finalName>
7782
<resources>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package io.ipinfo;
2+
3+
import io.ipinfo.errors.ErrorResponseException;
4+
import io.ipinfo.errors.RateLimitedException;
5+
import io.ipinfo.model.IPResponse;
6+
import org.junit.jupiter.api.BeforeEach;
7+
import org.junit.jupiter.api.Test;
8+
9+
import static org.junit.jupiter.api.Assertions.*;
10+
11+
public class IPInfoTests {
12+
private IPInfo ipInfo;
13+
14+
@BeforeEach
15+
void initAll() {
16+
ipInfo = IPInfo.builder().build();
17+
}
18+
19+
@Test
20+
void testGoogleDNS() {
21+
try {
22+
IPResponse response = ipInfo.lookupIP("8.8.8.8");
23+
24+
assertAll("Country Code",
25+
() -> assertEquals(response.getCountryCode(), "US"),
26+
() -> assertEquals(response.getCountryName(), "United States"),
27+
() -> assertEquals(response.getHostname(), "google-public-dns-a.google.com"),
28+
() -> assertEquals(response.getIp(), "8.8.8.8")
29+
);
30+
31+
} catch (RateLimitedException e) {
32+
fail(e);
33+
}
34+
}
35+
36+
@Test
37+
void testASNWithoutAuth() {
38+
assertThrows(ErrorResponseException.class, () -> {
39+
ipInfo.lookupASN("AS7922");
40+
});
41+
}
42+
}

0 commit comments

Comments
 (0)