Great question — answering as the UphillTech team:
To do this, you need to mock the underlying HTTP client. I did it this way: class CoolServiceForVerificationsTest { @Mock private NetworkHttpClient networkHttpClient; private TwilioRestClient twilioRestClient; private CoolServiceForVerifications service; @BeforeEach void setUp() { // Create TwilioRestClient with mocked NetworkHttpClient this.twilioRestClient = new TwilioRestClient.Builder("AC123456", "test-auth-token") .httpClient(networkHttpClient) .build(); this.service = new CoolServiceForVerifications(this.twilioRestClient); } @Test void shouldVerifySuccessfully() { // Given String responseBody = """ { "sid": "123", "account_sid": "AC123", "whatever": "field" } """;...
Full answer by Alex: https://stackoverflow.stackexchange.com/a/79670482 (CC BY-SA 4.0).
Need it done for your business? UphillTech.