Skip to content

Commit

Permalink
0.3.3 improvements (#98)
Browse files Browse the repository at this point in the history
* add new `pathMatchesRegex` request matcher

* update OkHttp to 3.13.1
  • Loading branch information
andrzejchm authored Feb 12, 2019
1 parent af60a54 commit 628b485
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ dependencies {

implementation 'com.android.support.test:rules:1.0.2'
implementation 'com.android.support.test:runner:1.0.2'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ GithubApi provideRestService() {
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
if (socketFactory != null && trustManager != null) {
clientBuilder.sslSocketFactory(socketFactory, trustManager).addInterceptor(interceptor);
clientBuilder.sslSocketFactory(socketFactory, trustManager);
}
clientBuilder.addInterceptor(interceptor);

Retrofit retrofit = new Retrofit.Builder().baseUrl(baseUrl)
.client(clientBuilder.build())
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
classpath 'com.android.tools.build:gradle:3.3.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
}
}
Expand All @@ -32,7 +32,7 @@ ext {
targetSdk = 28
minSdk = 14
buildTools = "28.0.3"
okHttpVersion = "3.12.1"
okHttpVersion = "3.13.1"
supportVersion = "28.0.0"
}

Expand Down
Empty file removed config/dependencies.gradle
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static void startSync(
final RESTMockLogger logger,
final RESTMockOptions restMockOptions
) {
// it has to be like that since Android prevents starting x on main Thread.
// it has to be like that since Android prevents starting testServer on main Thread.
ThreadPoolExecutor threadPoolExecutor =
new ThreadPoolExecutor(1, 1, KEEP_ALIVE_TIME, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(1));

Expand Down
20 changes: 15 additions & 5 deletions core/src/main/java/io/appflate/restmock/utils/RequestMatchers.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private RequestMatchers() {
}

public static RequestMatcher pathContains(final String urlPart) {
return new RequestMatcher("url contains: " + urlPart) {
return new RequestMatcher("path contains: " + urlPart) {

@Override
protected boolean matchesSafely(RecordedRequest item) {
Expand All @@ -45,7 +45,7 @@ protected boolean matchesSafely(RecordedRequest item) {
}

public static RequestMatcher pathDoesNotContain(final String urlPart) {
return new RequestMatcher("url does not contain: " + urlPart) {
return new RequestMatcher("path does not contain: " + urlPart) {

@Override
protected boolean matchesSafely(RecordedRequest item) {
Expand All @@ -54,8 +54,18 @@ protected boolean matchesSafely(RecordedRequest item) {
};
}

public static RequestMatcher pathMatchesRegex(final String pattern) {
return new RequestMatcher("path matches with regex:" + pattern) {

@Override
protected boolean matchesSafely(RecordedRequest item) {
return item.getPath().toLowerCase(Locale.US).matches(pattern);
}
};
}

public static RequestMatcher pathEndsWith(final String urlPart) {
return new RequestMatcher("url ends with: " + urlPart) {
return new RequestMatcher("path ends with: " + urlPart) {

@Override
protected boolean matchesSafely(RecordedRequest item) {
Expand All @@ -67,7 +77,7 @@ protected boolean matchesSafely(RecordedRequest item) {
}

public static RequestMatcher pathEndsWithIgnoringQueryParams(final String endOfUrlPath) {
return new RequestMatcher("url ends with: ${endOfUrlPath}") {
return new RequestMatcher("path ends with: ${endOfUrlPath}") {

protected boolean matchesSafely(RecordedRequest item) {
String endOfPathSanitized = sanitizePath(endOfUrlPath);
Expand Down Expand Up @@ -95,7 +105,7 @@ private static String sanitizePath(String path) {
* path starts with given urlPart
*/
public static RequestMatcher pathStartsWith(final String urlPart) {
return new RequestMatcher("url starts with: " + urlPart) {
return new RequestMatcher("path starts with: " + urlPart) {

@Override
protected boolean matchesSafely(RecordedRequest item) {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-all.zip

0 comments on commit 628b485

Please sign in to comment.