Skip to content

Commit 81f066e

Browse files
stainless-botstainless-app[bot]
authored andcommitted
chore(tests): add integration test for pagination (#156)
1 parent a10af78 commit 81f066e

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

  • lithic-java-example/src/main/java/com/lithic/example

lithic-java-example/src/main/java/com/lithic/example/Main.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import com.lithic.api.models.*;
66
import java.time.OffsetDateTime;
77
import java.time.ZoneOffset;
8+
import java.util.HashMap;
9+
import java.util.Iterator;
10+
import java.util.Map;
811
import java.util.stream.Stream;
912

1013
public class Main {
@@ -14,6 +17,14 @@ public class Main {
1417
LithicOkHttpClient.builder().sandbox().apiKey(SANDBOX_API_KEY).build();
1518

1619
public static void main(String[] args) {
20+
if (System.getenv("INTEGRATION_TEST").equals("true")) {
21+
Main.paginationIntegration();
22+
} else {
23+
Main.example();
24+
}
25+
}
26+
27+
public static void example() {
1728
System.out.println("Creating card");
1829
ShippingAddress address = ShippingAddress.builder()
1930
.firstName("Jane")
@@ -85,4 +96,40 @@ public static Account createAccount() {
8596
.accountToken(accountToken)
8697
.build());
8798
}
99+
100+
public static void paginationIntegration() {
101+
TransactionListPage page =
102+
client.transactions().list(TransactionListParams.builder().build());
103+
104+
if (!page.hasNextPage()) {
105+
throw new AssertionError("Expected multiple pages to be present");
106+
}
107+
108+
Iterator<Transaction> iterator = page.autoPager().iterator();
109+
Map<String, Integer> tokens = new HashMap<>();
110+
111+
while (iterator.hasNext()) {
112+
Transaction transaction = iterator.next();
113+
114+
tokens.put(transaction.token(), tokens.getOrDefault(transaction.token(), 0) + 1);
115+
}
116+
117+
Map<String, Integer> duplicates = new HashMap<>();
118+
for (Map.Entry<String, Integer> entry : tokens.entrySet()) {
119+
if (entry.getValue() > 1) {
120+
duplicates.put(entry.getKey(), entry.getValue());
121+
}
122+
}
123+
124+
if (!duplicates.isEmpty()) {
125+
System.out.println(duplicates);
126+
throw new RuntimeException("Found " + duplicates.size() + " duplicate entries!");
127+
}
128+
129+
if (tokens.size() < 100) {
130+
throw new AssertionError("Expected at least 100 entries to be present but got " + tokens.size());
131+
}
132+
133+
System.out.println("Success!");
134+
}
88135
}

0 commit comments

Comments
 (0)