-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathBillingRequestsChooseCurrencyCodeSampleTest.java
More file actions
53 lines (48 loc) · 1.87 KB
/
Copy pathBillingRequestsChooseCurrencyCodeSampleTest.java
File metadata and controls
53 lines (48 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.gocardless.code_samples;
// Code Sample Test
// This test verifies that a documentation code sample is syntactically valid
// and can execute against a mocked API without errors.
//
// IMPORTANT: This test does NOT verify business logic - it only verifies that
// the code sample compiles and executes without syntax errors.
import com.gocardless.GoCardlessClient;
import com.gocardless.resources.*;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class BillingRequestsChooseCurrencyCodeSampleTest {
private static final String ACCESS_TOKEN = "SECRET_TOKEN";
private GoCardlessClient client;
private MockWebServer server;
@Before
public void setUp() throws Exception {
server = new MockWebServer();
server.start();
client = GoCardlessClient.newBuilder(ACCESS_TOKEN)
.withBaseUrl(String.format("http://localhost:%d", server.getPort())).build();
}
@After
public void tearDown() throws Exception {
server.shutdown();
}
@Test
public void testChooseCurrencyCodeSample() throws Exception {
// Mock response - enqueue multiple times to handle code samples with multiple API calls
String responseBody = "{ \"billing_requests\": {} }";
for (int i = 0; i < 5; i++) {
server.enqueue(new MockResponse().setBody(responseBody).setResponseCode(200));
}
// Suppress stdout from code samples
PrintStream originalOut = System.out;
System.setOut(new PrintStream(new ByteArrayOutputStream()));
try {
client.billingRequests().chooseCurrency("BR123").withCurrency("GBP").execute();
} finally {
System.setOut(originalOut);
}
}
}