1
2
3
4
5 package com.jcabi.github;
6
7 import com.jcabi.http.request.FakeRequest;
8 import java.io.IOException;
9 import org.hamcrest.MatcherAssert;
10 import org.hamcrest.Matchers;
11 import org.junit.jupiter.api.Assertions;
12 import org.junit.jupiter.api.Test;
13 import org.mockito.Mockito;
14
15
16
17
18
19 final class RtLimitTest {
20
21 @Test
22 void describeAsJson() throws IOException {
23 final JsonReadable limit = new RtLimit(
24 Mockito.mock(GitHub.class),
25 new FakeRequest().withBody(RtLimitTest.body()),
26 "core"
27 );
28 MatcherAssert.assertThat(
29 "Values are not equal",
30 limit.json().toString(),
31 Matchers.equalTo(
32 "{\"limit\":5000,\"remaining\":4999,\"reset\":1372700873}"
33 )
34 );
35 }
36
37 @Test
38 void throwsWhenResourceIsAbsent() {
39 final JsonReadable limit = new RtLimit(
40 Mockito.mock(GitHub.class),
41 new FakeRequest().withBody(RtLimitTest.body()),
42 "absent"
43 );
44 Assertions.assertThrows(
45 IllegalStateException.class,
46 limit::json,
47 "Should throw when resource is absent"
48 );
49 }
50
51
52
53
54
55 private static String body() {
56 return new StringBuilder(100)
57 .append("{\"resources\":{\"core\":{\"limit\":5000, ")
58 .append("\"remaining\":4999, \"reset\":1372700873}, ")
59 .append("\"search\":{\"limit\":20, \"remaining\":18, ")
60 .append("\"reset\":1372697452}}, \"rate\":{\"limit\":5000, ")
61 .append("\"remaining\":4999, \"reset\":1372700873}}")
62 .toString();
63 }
64 }