8000 Release 0.4.3 by andrzejchm · Pull Request #112 · andrzejchm/RESTMock · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Release 0.4.3 #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Add the dependency

```groovy
dependencies {
androidTestCompile 'com.github.andrzejchm.RESTMock:android:${LATEST_VERSION}'
androidTestImplementation 'com.github.andrzejchm.RESTMock:android:${LATEST_VERSION}' // see "Releases" tab for latest version
}
```

Expand Down
28 changes: 15 additions & 13 deletions androidsample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ android {
versionCode 1
versionName "1.0"
testInstrumentationRunner "io.appflate.restmock.androidsample.CustomTestRunner"

testInstrumentationRunnerArguments = ["notPackage": "org.bouncycastle.pqc.crypto.qtesla"]
}
buildTypes {
release {
Expand All @@ -49,7 +51,7 @@ android {
configurations.all {
resolutionStrategy {
force "androidx.annotation:annotation:1.0.2"
force "com.squareup.okhttp3:okhttp:${okHttpVersion}"
force "com.squareup.okhttp3:okhttp:$okHttpVersion"
}
}

Expand All @@ -58,27 +60,27 @@ dependencies {
implementation "androidx.appcompat:appcompat:1.1.0"
implementation "com.google.android.material:material:1.1.0"
//noinspection AnnotationProcessorOnCompilePath
implementation "com.jakewharton:butterknife:${butterKnifeVersion}"
annotationProcessor "com.jakewharton:butterknife-compiler:${butterKnifeVersion}"
implementation "com.google.dagger:dagger:${daggerVersion}"
annotationProcessor "com.google.dagger:dagger-compiler:${daggerVersion}"
implementation "com.jakewharton:butterknife:$butterKnifeVersion"
annotationProcessor "com.jakewharton:butterknife-compiler:$butterKnifeVersion"
implementation "com.google.dagger:dagger:$daggerVersion"
annotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion"
implementation "com.squareup.retrofit2:retrofit:2.7.2"
implementation "com.squareup.retrofit2:converter-gson:2.7.2"
implementation "com.squareup.okhttp3:logging-interceptor:${okHttpVersion}"
implementation "com.squareup.okhttp3:okhttp:${okHttpVersion}"
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"

//Test dependencies
androidTestImplementation "androidx.test:rules:${androidXTestVersion}"
androidTestImplementation "androidx.test:runner:${androidXTestVersion}"
androidTestImplementation "androidx.test:rules:$androidXTestVersion"
androidTestImplementation "androidx.test:runner:$androidXTestVersion"

androidTestImplementation "androidx.test.espresso:espresso-core:${espressoVersion}"
androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVersion"

//this dependency tends to break things for most users. Im adding it to check whether the app compiles correctly
androidTestImplementation("androidx.test.espresso:espresso-contrib:${espressoVersion}")
androidTestImplementation("androidx.test.espresso:espresso-contrib:$espressoVersion")
androidTestImplementation "androidx.annotation:annotation:1.1.0"

//the most important, RESTMock! :)
Expand All @@ -87,8 +89,8 @@ dependencies {
testImplementation "androidx.appcompat:appcompat:1.1.0"
testImplementation "com.google.android.material:material:1.1.0"
testImplementation "junit:junit:4.13"
testImplementation "androidx.test.espresso:espresso-core:${espressoVersion}"
testImplementation("androidx.test.espresso:espresso-contrib:${espressoVersion}")
testImplementation "androidx.test.espresso:espresso-core:$espressoVersion"
testImplementation("androidx.test.espresso:espresso-contrib:$espressoVersion")
testImplementation project(":android")
testImplementation(project(":core"))
}
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.1'
classpath 'com.android.tools.build:gradle:3.6.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
}
}

ext {
libraryVersion = "0.4.2"
libraryVersion = "0.4.3"
compileSdk = 29
targetSdk = 29
minSdk = 21
buildTools = "29.0.2"
okHttpVersion = "4.4.1"
okHttpVersion = "4.6.0"
butterKnifeVersion = "10.2.1"
espressoVersion = "3.1.0"
androidXTestVersion = "1.2.0"
Expand Down
80 changes: 41 additions & 39 deletions core/src/test/java/io/appflate/restmock/RequestVerifierTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,27 @@

package io.appflate.restmock;

import io.appflate.restmock.exceptions.RequestInvocationCountMismatchException;
import io.appflate.restmock.exceptions.RequestInvocationCountNotEnoughException;
import io.appflate.restmock.exceptions.RequestNotInvokedException;
import io.appflate.restmock.utils.RequestMatchers;
import io.appflate.restmock.utils.TestUtils;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import okhttp3.mockwebserver.RecordedRequest;
import org.hamcrest.Matcher;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.Objects;

import io.appflate.restmock.exceptions.RequestInvocationCountMismatchException;
import io.appflate.restmock.exceptions.RequestInvocationCountNotEnoughException;
import io.appflate.restmock.exceptions.RequestNotInvokedException;
import io.appflate.restmock.utils.RequestMatchers;
import io.appflate.restmock.utils.TestUtils;
import okhttp3.mockwebserver.RecordedRequest;

import static io.appflate.restmock.RequestsVerifier.verifyDELETE;
import static io.appflate.restmock.RequestsVerifier.verifyGET;
import static io.appflate.restmock.RequestsVerifier.verifyPOST;
Expand All @@ -54,14 +57,13 @@ public class RequestVerifierTest {
private static final String path = "sample";
private static final Matcher<RecordedRequest> INVOKED_MATCHER = pathEndsWith(path);
private static final Matcher<RecordedRequest> NOT_INVOKED_MATCHER = pathEndsWith("else");
static RESTMockFileParser fileParser;

private final boolean useHttps;

@Parameterized.Parameters(name = "useHttps={0}")
public static Collection<Object> data() {
return Arrays.asList(new Object[] {
true, false
return Arrays.asList(new Object[]{
true, false
});
}

Expand All @@ -71,7 +73,7 @@ public RequestVerifierTest(boolean useHttps) {

@Before
public void setup() {
fileParser = mock(RESTMockFileParser.class);
RESTMockFileParser fileParser = mock(RESTMockFileParser.class);
RESTMockServerStarter.startSync(fileParser, new RESTMockOptions.Builder().useHttps(useHttps).build());
RESTMockServer.dispatcher = spy(RESTMockServer.dispatcher);
}
Expand Down Expand Up @@ -130,9 +132,9 @@ public void takesLastNumOfElementsWhenHistoryNotEmpty() throws Exception {

List<RecordedRequest> recordedRequests = RequestsVerifier.takeLast(3);
assertEquals(3, recordedRequests.size());
assertEquals("POST", recordedRequests.get(0).getMethod().toUpperCase(Locale.US));
assertEquals("DELETE", recordedRequests.get(1).getMethod().toUpperCase(Locale.US));
assertEquals("HEAD", recordedRequests.get(2).getMethod().toUpperCase(Locale.US));
assertEquals("POST", Objects.requireNonNull(recordedRequests.get(0).getMethod()).toUpperCase(Locale.US));
assertEquals("DELETE", Objects.requireNonNull(recordedRequests.get(1).getMethod()).toUpperCase(Locale.US));
assertEquals("HEAD", Objects.requireNonNull(recordedRequests.get(2).getMethod()).toUpperCase(Locale.US));
}

@Test
Expand All @@ -145,10 +147,10 @@ public void takeLastNumOfElementsExceedsHistorySizeTakesWholeHistory() throws Ex

List<RecordedRequest> recordedRequests = RequestsVerifier.takeLast(10);
assertEquals(4, recordedRequests.size());
assertEquals("GET", recordedRequests.get(0).getMethod().toUpperCase(Locale.US));
assertEquals("POST", recordedRequests.get(1).getMethod().toUpperCase(Locale.US));
assertEquals("DELETE", recordedRequests.get(2).getMethod().toUpperCase(Locale.US));
assertEquals("HEAD", recordedRequests.get(3).getMethod().toUpperCase(Locale.US));
assertEquals("GET", Objects.requireNonNull(recordedRequests.get(0).getMethod()).toUpperCase(Locale.US));
assertEquals("POST", Objects.requireNonNull(recordedRequests.get(1).getMethod()).toUpperCase(Locale.US));
assertEquals("DELETE", Objects.requireNonNull(recordedRequests.get(2).getMethod()).toUpperCase(Locale.US));
assertEquals("HEAD", Objects.requireNonNull(recordedRequests.get(3).getMethod()).toUpperCase(Locale.US));
}

@Test(expected = IllegalArgumentException.class)
Expand All @@ -172,9 +174,9 @@ public void takesFirstNumOfElementsWhenHistoryNotEmpty() throws Exception {

List<RecordedRequest> recordedRequests = RequestsVerifier.takeFirst(3);
assertEquals(3, recordedRequests.size());
assertEquals("GET", recordedRequests.get(0).getMethod().toUpperCase(Locale.US));
assertEquals("POST", recordedRequests.get(1).getMethod().toUpperCase(Locale.US));
assertEquals("DELETE", recordedRequests.get(2).getMethod().toUpperCase(Locale.US));
assertEquals("GET", Objects.requireNonNull(recordedRequests.get(0).getMethod()).toUpperCase(Locale.US));
assertEquals("POST", Objects.requireNonNull(recordedRequests.get(1).getMethod()).toUpperCase(Locale.US));
assertEquals("DELETE", Objects.requireNonNull(recordedRequests.get(2).getMethod()).toUpperCase(Locale.US));
}

@Test
Expand All @@ -187,10 +189,10 @@ public void takeFirstNumOfElementsExceedsHistorySizeTakesAllHistory() throws Exc

List<RecordedRequest> recordedRequests = RequestsVerifier.takeFirst(10);
assertEquals(4, recordedRequests.size());
assertEquals("GET", recordedRequests.get(0).getMethod().toUpperCase(Locale.US));
assertEquals("POST", recordedRequests.get(1).getMethod().toUpperCase(Locale.US));
assertEquals("DELETE", recordedRequests.get(2).getMethod().toUpperCase(Locale.US));
assertEquals("HEAD", recordedRequests.get(3).getMethod().toUpperCase(Locale.US));
assertEquals("GET", Objects.requireNonNull(recordedRequests.get(0).getMethod()).toUpperCase(Locale.US));
assertEquals("POST", Objects.requireNonNull(recordedRequests.get(1).getMethod()).toUpperCase(Locale.US));
assertEquals("DELETE", Objects.requireNonNull(recordedRequests.get(2).getMethod()).toUpperCase(Locale.US));
assertEquals("HEAD", Objects.requireNonNull(recordedRequests.get(3).getMethod()).toUpperCase(Locale.US));
}

@Test
Expand All @@ -203,9 +205,9 @@ public void takesSubsetOfRequests() throws Exception {

List<RecordedRequest> recordedRequests = RequestsVerifier.take(1, 4);
assertEquals(3, recordedRequests.size());
assertEquals("POST", recordedRequests.get(0).getMethod().toUpperCase(Locale.US));
assertEquals("DELETE", recordedRequests.get(1).getMethod().toUpperCase(Locale.US));
assertEquals("HEAD", recordedRequests.get(2).getMethod().toUpperCase(Locale.US));
assertEquals("POST", Objects.requireNonNull(recordedRequests.get(0).getMethod()).toUpperCase(Locale.US));
assertEquals("DELETE", Objects.requireNonNull(recordedRequests.get(1).getMethod()).toUpperCase(Locale.US));
assertEquals("HEAD", Objects.requireNonNull(recordedRequests.get(2).getMethod()).toUpperCase(Locale.US));
}

@Test(expected = IllegalArgumentException.class)
Expand All @@ -230,9 +232,9 @@ public void takeMatchingFindsAllRelevantRequests() throws Exception {
TestUtils.get(path);
List<RecordedRequest> recordedRequests = RequestsVerifier.takeAllMatching(RequestMatchers.isGET());
assertEquals(3, recordedRequests.size());
assertEquals("GET", recordedRequests.get(0).getMethod().toUpperCase(Locale.US));
assertEquals("GET", recordedRequests.get(1).getMethod().toUpperCase(Locale.US));
assertEquals("GET", recordedRequests.get(2).getMethod().toUpperCase(Locale.US));
assertEquals("GET", Objects.requireNonNull(recordedRequests.get(0).getMethod()).toUpperCase(Locale.US));
assertEquals("GET", Objects.requireNonNull(recordedRequests.get(1).getMethod()).toUpperCase(Locale.US));
assertEquals("GET", Objects.requireNonNull(recordedRequests.get(2).getMethod()).toUpperCase(Locale.US));
}

@Test(expected = IllegalArgumentException.class)
Expand All @@ -247,13 +249,13 @@ public void takeFirstNumOfElementsWithInvalidCountThrowsException() throws Excep
}

@Test
public void takeSingleFirstWhenNoHistoryIsNull() throws Exception {
public void takeSingleFirstWhenNoHistoryIsNull() {
RESTMockServer.whenRequested(pathEndsWith(path)).thenReturnString("a single call");
assertNull(RequestsVerifier.takeFirst());
}

@Test
public void takeSingleLastWhenNoHistoryIsNull() throws Exception {
public void takeSingleLastWhenNoHistoryIsNull() {
RESTMockServer.whenRequested(pathEndsWith(path)).thenReturnString("a single call");
assertNull(RequestsVerifier.takeLast());
}
Expand All @@ -275,7 +277,7 @@ public void testReset() throws Exception {
}

@Test(expected = RequestNotInvokedException.class)
public void testInvoked_NotInvokedException() throws Exception {
public void testInvoked_NotInvokedException() {
verifyRequest(NOT_INVOKED_MATCHER).invoked();
}

Expand All @@ -298,7 +300,7 @@ public void testAtLeast_InvocationCountMismatchException() throws Exception {
}

@Test(expected = RequestNotInvokedException.class)
public void testExactly_NotInvokedException() throws Exception {
public void testExactly_NotInvokedException() {
verifyRequest(NOT_INVOKED_MATCHER).exactly(3);
}

Expand Down
Loading
0