Skip to content

Commit aebf596

Browse files
committed
- Address feedback
1 parent afa8f6d commit aebf596

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

src/main/java/com/easypost/easyvcr/MatchRules.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,13 @@ public MatchRules byBaseUrl() {
5858
return this;
5959
}
6060

61+
/**
62+
* Extract the base URL from a URI.
63+
*
64+
* @param url The URI to extract the base URL from.
65+
* @return The base URL.
66+
*/
6167
private static String getBaseUrl(URI url) {
62-
6368
String baseUrl = url.getScheme() + "://" + url.getHost();
6469
if (url.getPort() != -1) {
6570
baseUrl += ":" + url.getPort();

src/main/java/com/easypost/easyvcr/clients/httpurlconnection/RecordableHttpURLConnection.java

+5
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ public RecordableHttpURLConnection(URL url, Cassette cassette, Mode mode)
144144
this(url, cassette, mode, new AdvancedSettings());
145145
}
146146

147+
/**
148+
* Throws an exception if a matching interaction has not been cached.
149+
*
150+
* @throws VCRException If the interaction has not been cached.
151+
*/
147152
private void cachedInteractionExistsOtherwiseError() throws VCRException {
148153
if (this.cachedInteraction == null) {
149154
throw new VCRException("No matching interaction found.");

src/main/java/com/easypost/easyvcr/clients/httpurlconnection/RecordableHttpsURLConnection.java

+5
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ public RecordableHttpsURLConnection(URL url, Cassette cassette, Mode mode)
149149
this(url, cassette, mode, new AdvancedSettings());
150150
}
151151

152+
/**
153+
* Throws an exception if a matching interaction has not been cached.
154+
*
155+
* @throws VCRException If the interaction has not been cached.
156+
*/
152157
private void cachedInteractionExistsOtherwiseError() throws VCRException {
153158
if (this.cachedInteraction == null) {
154159
throw new VCRException("No matching interaction found.");

src/test/java/HttpUrlConnectionTest.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -560,8 +560,17 @@ public void testCachedInteractionDoesNotExist() throws Exception {
560560
url + "1", cassette, Mode.Replay, advancedSettings);
561561
// make HTTP call (attempt replay from cassette)
562562
connection.connect();
563+
563564
// Attempt to pull data (e.g. body) from the response (via the input stream)
564565
// this throws a RuntimeException because of the way the exceptions are coalesced internally
565-
Assert.assertThrows(RuntimeException.class, connection::getInputStream);
566+
try {
567+
connection.getInputStream();
568+
// if we get here, the exception was not thrown as expected
569+
Assert.fail();
570+
} catch (Exception e) {
571+
Assert.assertTrue(e instanceof RuntimeException);
572+
Assert.assertTrue(e.getCause() instanceof VCRException);
573+
Assert.assertEquals(e.getCause().getMessage(), "No matching interaction found.");
574+
}
566575
}
567576
}

0 commit comments

Comments
 (0)