From af60a54d86867f22ec77665af66d92ed8dd5e140 Mon Sep 17 00:00:00 2001 From: Jason Atwood Date: Sun, 20 Jan 2019 04:30:18 -0500 Subject: [PATCH] Update to latest OkHttp 3.12.1 (#92) * Update to latest OkHttp 3.12.1 * Fix failing tests In MockWebServer changes (3.11.0 / https://github.com/square/okhttp/pull/4246) RecordedRequest is now looking for local address. So update what gets mocked in tests. * Add leading / to paths for RecordedRequest In MockWebServer (changes in 3.11.0 https://github.com/square/okhttp/pull/4235) changes were made to RecordedRequest. It now expects a leading / for path. So update tests accordingly. * Bump to latest dependencies in sample app Since this is just the sample app there is probably not much danger in just bumping these to latest versions. --- androidsample/build.gradle | 8 ++++---- build.gradle | 2 +- .../restmock/utils/RequestMatchersTest.java | 20 +++++++++---------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/androidsample/build.gradle b/androidsample/build.gradle index d2113fd..fad33ed 100644 --- a/androidsample/build.gradle +++ b/androidsample/build.gradle @@ -60,16 +60,16 @@ dependencies { implementation "com.android.support:design:${supportVersion}" implementation "com.jakewharton:butterknife:8.8.1" annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1' - implementation "com.google.dagger:dagger:2.15" - implementation "com.squareup.retrofit2:retrofit:2.3.0" - implementation "com.squareup.retrofit2:converter-gson:2.3.0" + implementation "com.google.dagger:dagger:2.20" + implementation "com.squareup.retrofit2:retrofit:2.5.0" + implementation "com.squareup.retrofit2:converter-gson:2.5.0" implementation "com.squareup.okhttp3:logging-interceptor:${okHttpVersion}" implementation "com.squareup.okhttp3:okhttp:${okHttpVersion}" implementation "com.google.code.gson:gson:2.8.5" implementation "com.google.code.findbugs:annotations:2.0.3" compileOnly "javax.annotation:jsr250-api:1.0" - annotationProcessor "com.google.dagger:dagger-compiler:2.15" + annotationProcessor "com.google.dagger:dagger-compiler:2.20" //Test dependencies androidTestImplementation "com.android.support.test:runner:1.0.2" diff --git a/build.gradle b/build.gradle index ac0edc4..3dade14 100644 --- a/build.gradle +++ b/build.gradle @@ -32,7 +32,7 @@ ext { targetSdk = 28 minSdk = 14 buildTools = "28.0.3" - okHttpVersion = "3.11.0" + okHttpVersion = "3.12.1" supportVersion = "28.0.0" } diff --git a/core/src/test/java/io/appflate/restmock/utils/RequestMatchersTest.java b/core/src/test/java/io/appflate/restmock/utils/RequestMatchersTest.java index 0130706..0ccae85 100644 --- a/core/src/test/java/io/appflate/restmock/utils/RequestMatchersTest.java +++ b/core/src/test/java/io/appflate/restmock/utils/RequestMatchersTest.java @@ -21,7 +21,7 @@ public class RequestMatchersTest { @Test public void endingSlashNotTakenIntoAccount() throws IOException { // given - RecordedRequest recordedRequest = createRecordedRequest("foo/bar/"); + RecordedRequest recordedRequest = createRecordedRequest("/foo/bar/"); // when RequestMatcher matcher = RequestMatchers.pathEndsWith("bar"); @@ -33,7 +33,7 @@ public void endingSlashNotTakenIntoAccount() throws IOException { @Test public void queryParamsAreTakenIntoAccount() throws IOException { // given - RecordedRequest recordedRequest = createRecordedRequest("foo/bar?baz=boo"); + RecordedRequest recordedRequest = createRecordedRequest("/foo/bar?baz=boo"); // when RequestMatcher matcher = RequestMatchers.pathEndsWith("boo"); @@ -45,7 +45,7 @@ public void queryParamsAreTakenIntoAccount() throws IOException { @Test public void queryParamsAreIgnored() throws IOException { // given - RecordedRequest recordedRequest = createRecordedRequest("foo/bar?baz=boo"); + RecordedRequest recordedRequest = createRecordedRequest("/foo/bar?baz=boo"); // when RequestMatcher matcher = RequestMatchers.pathEndsWithIgnoringQueryParams("bar"); @@ -57,7 +57,7 @@ public void queryParamsAreIgnored() throws IOException { @Test public void shouldRecognizeProperQueryParameters() throws IOException { // given - RecordedRequest recordedRequest = createRecordedRequest("foo/bar?baz=ban"); + RecordedRequest recordedRequest = createRecordedRequest("/foo/bar?baz=ban"); // when RequestMatcher matcher = RequestMatchers.hasQueryParameters(); @@ -69,7 +69,7 @@ public void shouldRecognizeProperQueryParameters() throws IOException { @Test public void shouldMatchProperSubsetOfQueryParametersNames() throws IOException { // given - RecordedRequest recordedRequest = createRecordedRequest("foo/?bar=bar&baz=baz&boo=boo"); + RecordedRequest recordedRequest = createRecordedRequest("/foo/?bar=bar&baz=baz&boo=boo"); // when RequestMatcher matcher = RequestMatchers.hasQueryParameterNames("bar", "baz"); @@ -81,7 +81,7 @@ public void shouldMatchProperSubsetOfQueryParametersNames() throws IOException { @Test public void shouldNotMatchInproperSubsetOfQueryParametersNames() throws IOException { // given - RecordedRequest recordedRequest = createRecordedRequest("foo/?bar=bar&baz=baz&boo=boo"); + RecordedRequest recordedRequest = createRecordedRequest("/foo/?bar=bar&baz=baz&boo=boo"); // when RequestMatcher matcher = RequestMatchers.hasQueryParameterNames("bar", "ban"); @@ -93,7 +93,7 @@ public void shouldNotMatchInproperSubsetOfQueryParametersNames() throws IOExcept @Test public void hasHeaderNamesFailWhenNoHeaders() { //given - RecordedRequest request = createRecordedRequest("path"); + RecordedRequest request = createRecordedRequest("/path"); //when RequestMatcher matcher = hasHeaderNames("header1"); @@ -105,7 +105,7 @@ public void hasHeaderNamesFailWhenNoHeaders() { @Test public void hasHeaderNamesSuccessWhenMatchesAll() { //given - RecordedRequest request = createRecordedRequest("path", "h1", "v1", "h2", "v2", "h3", "v3"); + RecordedRequest request = createRecordedRequest("/path", "h1", "v1", "h2", "v2", "h3", "v3"); //when RequestMatcher matcher = hasHeaderNames("h1", "h2", "h3"); @@ -117,7 +117,7 @@ public void hasHeaderNamesSuccessWhenMatchesAll() { @Test public void hasHeaderNamesSuccessWhenMatchesAllAsSubset() { //given - RecordedRequest request = createRecordedRequest("path", "h1", "v1", "h2", "v2", "h3", "v3"); + RecordedRequest request = createRecordedRequest("/path", "h1", "v1", "h2", "v2", "h3", "v3"); //when RequestMatcher matcher = hasHeaderNames("h1", "h2"); @@ -128,7 +128,7 @@ public void hasHeaderNamesSuccessWhenMatchesAllAsSubset() { private RecordedRequest createRecordedRequest(String path, String... headerNamesAndValues) { Socket socket = Mockito.mock(Socket.class); - when(socket.getInetAddress()).thenReturn(mock(InetAddress.class)); + when(socket.getLocalAddress()).thenReturn(mock(InetAddress.class)); Headers headers = null; if (headerNamesAndValues != null && headerNamesAndValues.length >= 2) { headers = Headers.of(headerNamesAndValues);