1919import static com .github .tomakehurst .wiremock .client .WireMock .stubFor ;
2020import static com .github .tomakehurst .wiremock .client .WireMock .urlPathEqualTo ;
2121import static com .github .tomakehurst .wiremock .client .WireMock .verify ;
22- import static org .junit .Assert .*;
22+ import static com .github .tomakehurst .wiremock .core .WireMockConfiguration .wireMockConfig ;
23+ import static org .junit .Assert .assertEquals ;
24+ import static org .junit .Assert .assertFalse ;
25+ import static org .junit .Assert .fail ;
2326
2427import com .github .tomakehurst .wiremock .junit .WireMockRule ;
2528import com .google .common .io .Resources ;
3134import java .io .IOException ;
3235import java .nio .file .Files ;
3336import java .nio .file .Paths ;
37+ import java .util .Iterator ;
3438import java .util .concurrent .CountDownLatch ;
3539import java .util .concurrent .ExecutorService ;
3640import java .util .concurrent .Executors ;
4246public class PagerTest {
4347
4448 private ApiClient client ;
49+ private static final String LIST_PAGE0_FILE_PATH =
50+ Resources .getResource ("namespace-list-pager0.json" ).getPath ();
4551 private static final String LIST_PAGE1_FILE_PATH =
4652 Resources .getResource ("namespace-list-pager1.json" ).getPath ();
4753 private static final String LIST_PAGE2_FILE_PATH =
@@ -50,12 +56,41 @@ public class PagerTest {
5056 Resources .getResource ("status-400.json" ).getPath ();
5157 private static final String STATUS_BAD_TOKEN_FILE_PATH =
5258 Resources .getResource ("bad-token-status.json" ).getPath ();
53- private static final int PORT = 8087 ;
54- @ Rule public WireMockRule wireMockRule = new WireMockRule (PORT );
59+ @ Rule public WireMockRule wireMockRule = new WireMockRule (wireMockConfig ().dynamicPort ());
5560
5661 @ Before
5762 public void setup () throws IOException {
58- client = new ClientBuilder ().setBasePath ("http://localhost:" + PORT ).build ();
63+ client = new ClientBuilder ().setBasePath ("http://localhost:" + wireMockRule .port ()).build ();
64+ }
65+
66+ @ Test
67+ public void testIteratorForEmptyList () throws IOException {
68+ String namespaceListPage0Str = new String (Files .readAllBytes (Paths .get (LIST_PAGE0_FILE_PATH )));
69+ CoreV1Api api = new CoreV1Api (client );
70+
71+ stubFor (
72+ get (urlPathEqualTo ("/api/v1/namespaces" ))
73+ .willReturn (
74+ aResponse ()
75+ .withStatus (200 )
76+ .withHeader ("Content-Type" , "application/json" )
77+ .withBody (namespaceListPage0Str )));
78+
79+ Pager <V1Namespace , V1NamespaceList > pager =
80+ new Pager <V1Namespace , V1NamespaceList >(
81+ (Pager .PagerParams param ) -> {
82+ try {
83+ return api .listNamespaceCall (
84+ null , null , null , null , null , null , null , null , null , null );
85+ } catch (Exception e ) {
86+ throw new RuntimeException (e );
87+ }
88+ },
89+ client ,
90+ 1 ,
91+ V1NamespaceList .class );
92+ Iterator <V1Namespace > it = pager .iterator ();
93+ assertFalse ("Iterator should be empty." , it .hasNext ());
5994 }
6095
6196 @ Test
0 commit comments