diff --git a/README.md b/README.md
index 71163cf..3606149 100644
--- a/README.md
+++ b/README.md
@@ -69,7 +69,7 @@ The core API of this library is centered around the class `RequestMatcherRule`.
public class LocalTest {
@Rule
- public final RequestMatcherRule serverRule = new LocalTestRequestMatcherRule();
+ public final RequestMatcherRule serverRule = new LocalTestRequestMatcherRule.Builder().build();
@Before
public void setUp() {
@@ -128,13 +128,13 @@ Because of these differences, there are two implementations of `RequestMatcherRu
``` java
// Local Test
@Rule
-public final RequestMatcherRule server = new LocalTestRequestMatcherRule();
+public final RequestMatcherRule server = new LocalTestRequestMatcherRule.Builder().build();
// or
// Instrumented Test
@Rule
-public final RequestMatcherRule server = new InstrumentedTestRequestMatcherRule();
+public final RequestMatcherRule server = new InstrumentedTestRequestMatcherRule.Builder().build();
```
The difference is that when we run an InstrumentedTest, we must pass the instrumentation context (and *NOT* the target context).
diff --git a/requestmatcher/build.gradle b/requestmatcher/build.gradle
index 2b6ee01..5ef65e2 100644
--- a/requestmatcher/build.gradle
+++ b/requestmatcher/build.gradle
@@ -50,7 +50,7 @@ dependencies {
testCompile "com.squareup.okhttp3:mockwebserver:$okhttpVersion"
testCompile "com.squareup.okhttp3:okhttp:$okhttpVersion"
testCompile 'org.robolectric:robolectric:3.3.2'
- testCompile 'org.mockito:mockito-all:1.10.19'
+ testCompile 'org.mockito:mockito-core:2.19.0'
androidTestCompile "com.squareup.okhttp3:mockwebserver:$okhttpVersion"
androidTestCompile("com.jayway.jsonpath:json-path-assert:$jsonPathAssert") {
diff --git a/requestmatcher/src/androidTest/java/br/com/concretesolutions/requestmatcher/test/InstrumentedExceptionInStatementTest.java b/requestmatcher/src/androidTest/java/br/com/concretesolutions/requestmatcher/test/dispachers/map/InstrumentedExceptionInStatementTest.java
similarity index 60%
rename from requestmatcher/src/androidTest/java/br/com/concretesolutions/requestmatcher/test/InstrumentedExceptionInStatementTest.java
rename to requestmatcher/src/androidTest/java/br/com/concretesolutions/requestmatcher/test/dispachers/map/InstrumentedExceptionInStatementTest.java
index b4b6c3e..15d95fd 100644
--- a/requestmatcher/src/androidTest/java/br/com/concretesolutions/requestmatcher/test/InstrumentedExceptionInStatementTest.java
+++ b/requestmatcher/src/androidTest/java/br/com/concretesolutions/requestmatcher/test/dispachers/map/InstrumentedExceptionInStatementTest.java
@@ -1,4 +1,4 @@
-package br.com.concretesolutions.requestmatcher.test;
+package br.com.concretesolutions.requestmatcher.test.dispachers.map;
import android.support.test.runner.AndroidJUnit4;
@@ -8,10 +8,10 @@
import br.com.concretesolutions.requestmatcher.RequestMatcherRule;
@RunWith(AndroidJUnit4.class)
-public class InstrumentedExceptionInStatementTest extends ExceptionInStatementTest {
+public class InstrumentedExceptionInStatementTest extends MapExceptionInStatementTest {
@Override
protected RequestMatcherRule getRequestMatcherRule() {
- return new InstrumentedTestRequestMatcherRule();
+ return new InstrumentedTestRequestMatcherRule.Builder().build();
}
}
diff --git a/requestmatcher/src/androidTest/java/br/com/concretesolutions/requestmatcher/test/InstrumentedExceptionWitouhtEnqueuesTest.java b/requestmatcher/src/androidTest/java/br/com/concretesolutions/requestmatcher/test/dispachers/map/InstrumentedExceptionWithoutEnqueuesTest.java
similarity index 52%
rename from requestmatcher/src/androidTest/java/br/com/concretesolutions/requestmatcher/test/InstrumentedExceptionWitouhtEnqueuesTest.java
rename to requestmatcher/src/androidTest/java/br/com/concretesolutions/requestmatcher/test/dispachers/map/InstrumentedExceptionWithoutEnqueuesTest.java
index 89c4847..ffc31c9 100644
--- a/requestmatcher/src/androidTest/java/br/com/concretesolutions/requestmatcher/test/InstrumentedExceptionWitouhtEnqueuesTest.java
+++ b/requestmatcher/src/androidTest/java/br/com/concretesolutions/requestmatcher/test/dispachers/map/InstrumentedExceptionWithoutEnqueuesTest.java
@@ -1,18 +1,18 @@
-package br.com.concretesolutions.requestmatcher.test;
+package br.com.concretesolutions.requestmatcher.test.dispachers.map;
import android.support.test.runner.AndroidJUnit4;
import org.junit.runner.RunWith;
import br.com.concretesolutions.requestmatcher.InstrumentedTestRequestMatcherRule;
-import br.com.concretesolutions.requestmatcher.LocalTestRequestMatcherRule;
import br.com.concretesolutions.requestmatcher.RequestMatcherRule;
+import br.com.concretesolutions.requestmatcher.test.ExceptionWithoutEnqueuesTest;
@RunWith(AndroidJUnit4.class)
-public class InstrumentedExceptionWitouhtEnqueuesTest extends ExceptionWitouhtEnqueuesTest {
+public class InstrumentedExceptionWithoutEnqueuesTest extends ExceptionWithoutEnqueuesTest {
@Override
protected RequestMatcherRule getRequestMatcherRule() {
- return new InstrumentedTestRequestMatcherRule();
+ return new InstrumentedTestRequestMatcherRule.Builder().build();
}
}
diff --git a/requestmatcher/src/androidTest/java/br/com/concretesolutions/requestmatcher/test/InstrumentedRequestMatcherRuleTest.java b/requestmatcher/src/androidTest/java/br/com/concretesolutions/requestmatcher/test/dispachers/map/InstrumentedRequestMatcherRuleTest.java
similarity index 60%
rename from requestmatcher/src/androidTest/java/br/com/concretesolutions/requestmatcher/test/InstrumentedRequestMatcherRuleTest.java
rename to requestmatcher/src/androidTest/java/br/com/concretesolutions/requestmatcher/test/dispachers/map/InstrumentedRequestMatcherRuleTest.java
index 936f3f7..dcff697 100644
--- a/requestmatcher/src/androidTest/java/br/com/concretesolutions/requestmatcher/test/InstrumentedRequestMatcherRuleTest.java
+++ b/requestmatcher/src/androidTest/java/br/com/concretesolutions/requestmatcher/test/dispachers/map/InstrumentedRequestMatcherRuleTest.java
@@ -1,4 +1,4 @@
-package br.com.concretesolutions.requestmatcher.test;
+package br.com.concretesolutions.requestmatcher.test.dispachers.map;
import android.support.test.runner.AndroidJUnit4;
@@ -8,10 +8,10 @@
import br.com.concretesolutions.requestmatcher.RequestMatcherRule;
@RunWith(AndroidJUnit4.class)
-public class InstrumentedRequestMatcherRuleTest extends RequestMatcherRuleTest {
+public class InstrumentedRequestMatcherRuleTest extends MapRequestMatcherRuleTest {
@Override
protected RequestMatcherRule getRequestMatcherRule() {
- return new InstrumentedTestRequestMatcherRule();
+ return new InstrumentedTestRequestMatcherRule.Builder().build();
}
}
diff --git a/requestmatcher/src/androidTest/java/br/com/concretesolutions/requestmatcher/test/dispachers/queue/InstrumentedExceptionInStatementTest.java b/requestmatcher/src/androidTest/java/br/com/concretesolutions/requestmatcher/test/dispachers/queue/InstrumentedExceptionInStatementTest.java
new file mode 100644
index 0000000..e4bc72e
--- /dev/null
+++ b/requestmatcher/src/androidTest/java/br/com/concretesolutions/requestmatcher/test/dispachers/queue/InstrumentedExceptionInStatementTest.java
@@ -0,0 +1,20 @@
+package br.com.concretesolutions.requestmatcher.test.dispachers.queue;
+
+import android.support.test.runner.AndroidJUnit4;
+
+import org.junit.runner.RunWith;
+
+import br.com.concretesolutions.requestmatcher.InstrumentedTestRequestMatcherRule;
+import br.com.concretesolutions.requestmatcher.QueueMatcherDispatcher;
+import br.com.concretesolutions.requestmatcher.RequestMatcherRule;
+
+@RunWith(AndroidJUnit4.class)
+public class InstrumentedExceptionInStatementTest extends QueueExceptionInStatementTest {
+
+ @Override
+ protected RequestMatcherRule getRequestMatcherRule() {
+ return new InstrumentedTestRequestMatcherRule.Builder()
+ .setDispatcher(new QueueMatcherDispatcher())
+ .build();
+ }
+}
diff --git a/requestmatcher/src/androidTest/java/br/com/concretesolutions/requestmatcher/test/dispachers/queue/InstrumentedExceptionWithoutEnqueuesTest.java b/requestmatcher/src/androidTest/java/br/com/concretesolutions/requestmatcher/test/dispachers/queue/InstrumentedExceptionWithoutEnqueuesTest.java
new file mode 100644
index 0000000..8cb1cf7
--- /dev/null
+++ b/requestmatcher/src/androidTest/java/br/com/concretesolutions/requestmatcher/test/dispachers/queue/InstrumentedExceptionWithoutEnqueuesTest.java
@@ -0,0 +1,21 @@
+package br.com.concretesolutions.requestmatcher.test.dispachers.queue;
+
+import android.support.test.runner.AndroidJUnit4;
+
+import org.junit.runner.RunWith;
+
+import br.com.concretesolutions.requestmatcher.InstrumentedTestRequestMatcherRule;
+import br.com.concretesolutions.requestmatcher.QueueMatcherDispatcher;
+import br.com.concretesolutions.requestmatcher.RequestMatcherRule;
+import br.com.concretesolutions.requestmatcher.test.ExceptionWithoutEnqueuesTest;
+
+@RunWith(AndroidJUnit4.class)
+public class InstrumentedExceptionWithoutEnqueuesTest extends ExceptionWithoutEnqueuesTest {
+
+ @Override
+ protected RequestMatcherRule getRequestMatcherRule() {
+ return new InstrumentedTestRequestMatcherRule.Builder()
+ .setDispatcher(new QueueMatcherDispatcher())
+ .build();
+ }
+}
diff --git a/requestmatcher/src/androidTest/java/br/com/concretesolutions/requestmatcher/test/dispachers/queue/InstrumentedRequestMatcherRuleTest.java b/requestmatcher/src/androidTest/java/br/com/concretesolutions/requestmatcher/test/dispachers/queue/InstrumentedRequestMatcherRuleTest.java
new file mode 100644
index 0000000..90d2ad8
--- /dev/null
+++ b/requestmatcher/src/androidTest/java/br/com/concretesolutions/requestmatcher/test/dispachers/queue/InstrumentedRequestMatcherRuleTest.java
@@ -0,0 +1,20 @@
+package br.com.concretesolutions.requestmatcher.test.dispachers.queue;
+
+import android.support.test.runner.AndroidJUnit4;
+
+import org.junit.runner.RunWith;
+
+import br.com.concretesolutions.requestmatcher.InstrumentedTestRequestMatcherRule;
+import br.com.concretesolutions.requestmatcher.QueueMatcherDispatcher;
+import br.com.concretesolutions.requestmatcher.RequestMatcherRule;
+
+@RunWith(AndroidJUnit4.class)
+public class InstrumentedRequestMatcherRuleTest extends QueueRequestMatcherRuleTest {
+
+ @Override
+ protected RequestMatcherRule getRequestMatcherRule() {
+ return new InstrumentedTestRequestMatcherRule.Builder()
+ .setDispatcher(new QueueMatcherDispatcher())
+ .build();
+ }
+}
diff --git a/requestmatcher/src/main/java/br/com/concretesolutions/requestmatcher/InstrumentedTestRequestMatcherRule.java b/requestmatcher/src/main/java/br/com/concretesolutions/requestmatcher/InstrumentedTestRequestMatcherRule.java
index 1142e11..1657375 100644
--- a/requestmatcher/src/main/java/br/com/concretesolutions/requestmatcher/InstrumentedTestRequestMatcherRule.java
+++ b/requestmatcher/src/main/java/br/com/concretesolutions/requestmatcher/InstrumentedTestRequestMatcherRule.java
@@ -9,45 +9,56 @@
/**
* A {@link RequestMatcherRule} for tests that run on devices or emulators.
- *
+ *
* For reference: https://github.com/concretesolutions/requestmatcher/wiki/Local-or-Instrumented-tests
*/
public class InstrumentedTestRequestMatcherRule extends RequestMatcherRule {
- /**
- * Creates a rule with a new instance of {@link MockWebServer}. This will by default look for
- * fixtures in the "fixtures" folder.
- */
- public InstrumentedTestRequestMatcherRule() {}
-
- /**
- * Creates a rule with a new instance of {@link MockWebServer}.
- *
- * @param fixturesRootFolder The root folder to look for fixtures. Defaults to "fixtures"
- */
- public InstrumentedTestRequestMatcherRule(String fixturesRootFolder) {
- super(fixturesRootFolder);
- }
+ public static class Builder {
+ private MatcherDispatcher dispatcher = new MapMatcherDispatcher();
+ private MockWebServer server = new MockWebServer();
+ private String fixturesRootFolder = "fixtures";
+
+ /**
+ * Creates a rule with a new instance of {@link MockWebServer}. This will by default look for
+ * fixtures in the "fixtures" folder.
+ */
+ public Builder() {
+ }
+
+ public Builder setDispatcher(MatcherDispatcher dispatcher) {
+ this.dispatcher = dispatcher;
+ return this;
+ }
+
+ /**
+ * Creates a rule with the given instance of {@link MockWebServer}. This will by default look
+ * for fixtures in the "fixtures" folder.
+ *
+ * @param server The {@link MockWebServer} instance
+ */
+ public Builder setServer(MockWebServer server) {
+ this.server = server;
+ return this;
+ }
+
+ /**
+ * Creates a rule with a new instance of {@link MockWebServer}.
+ *
+ * @param fixturesRootFolder The root folder to look for fixtures. Defaults to "fixtures"
+ */
+ public Builder setFixturesRootFolder(String fixturesRootFolder) {
+ this.fixturesRootFolder = fixturesRootFolder;
+ return this;
+ }
- /**
- * Creates a rule with the given instance of {@link MockWebServer}. This will by default look
- * for fixtures in the "fixtures" folder.
- *
- * @param server The {@link MockWebServer} instance
- */
- public InstrumentedTestRequestMatcherRule(MockWebServer server) {
- super(server);
+ public RequestMatcherRule build() {
+ return new InstrumentedTestRequestMatcherRule(server, fixturesRootFolder, dispatcher);
+ }
}
- /**
- * Creates a rule with the given instance of {@link MockWebServer}. This will by default look
- * for fixtures in the "fixtures" folder.
- *
- * @param server The {@link MockWebServer} instance
- * @param fixturesRootFolder The root folder to look for fixtures. Defaults to "fixtures"
- */
- public InstrumentedTestRequestMatcherRule(MockWebServer server, String fixturesRootFolder) {
- super(server, fixturesRootFolder);
+ InstrumentedTestRequestMatcherRule(MockWebServer server, String fixturesRootFolder, MatcherDispatcher dispatcher) {
+ super(server, fixturesRootFolder, dispatcher);
}
@Override
diff --git a/requestmatcher/src/main/java/br/com/concretesolutions/requestmatcher/LocalTestRequestMatcherRule.java b/requestmatcher/src/main/java/br/com/concretesolutions/requestmatcher/LocalTestRequestMatcherRule.java
index 7c25499..ff7f9b4 100644
--- a/requestmatcher/src/main/java/br/com/concretesolutions/requestmatcher/LocalTestRequestMatcherRule.java
+++ b/requestmatcher/src/main/java/br/com/concretesolutions/requestmatcher/LocalTestRequestMatcherRule.java
@@ -7,49 +7,61 @@
/**
* A {@link RequestMatcherRule} for tests that run on the JVM (locally).
- *
+ *
* For reference: https://github.com/concretesolutions/requestmatcher/wiki/Local-or-Instrumented-tests
*/
public class LocalTestRequestMatcherRule extends RequestMatcherRule {
- /**
- * Creates a rule with a new instance of {@link MockWebServer}. This will by default look for
- * fixtures in the "fixtures" folder.
- */
- public LocalTestRequestMatcherRule() {}
-
- /**
- * Creates a rule with a new instance of {@link MockWebServer}.
- *
- * @param fixturesRootFolder The root folder to look for fixtures. Defaults to "fixtures"
- */
- public LocalTestRequestMatcherRule(String fixturesRootFolder) {
- super(fixturesRootFolder);
- }
-
- /**
- * Creates a rule with the given instance of {@link MockWebServer}. This will by default look
- * for fixtures in the "fixtures" folder.
- *
- * @param server The {@link MockWebServer} instance
- */
- public LocalTestRequestMatcherRule(MockWebServer server) {
- super(server);
- }
- /**
- * Creates a rule with the given instance of {@link MockWebServer}. This will by default look
- * for fixtures in the "fixtures" folder.
- *
- * @param server The {@link MockWebServer} instance
- * @param fixturesRootFolder The root folder to look for fixtures. Defaults to "fixtures"
- */
- public LocalTestRequestMatcherRule(MockWebServer server, String fixturesRootFolder) {
- super(server, fixturesRootFolder);
+ LocalTestRequestMatcherRule(MockWebServer server, String fixturesRootFolder, MatcherDispatcher dispatcher) {
+ super(server, fixturesRootFolder, dispatcher);
}
@Override
protected InputStream open(String path) throws IOException {
return LocalTestRequestMatcherRule.class.getClassLoader().getResourceAsStream(path);
}
-}
+
+ public static class Builder {
+ private MatcherDispatcher dispatcher = new MapMatcherDispatcher();
+ private MockWebServer server = new MockWebServer();
+ private String fixturesRootFolder = "fixtures";
+
+ /**
+ * Creates a rule with a new instance of {@link MockWebServer}. This will by default look for
+ * fixtures in the "fixtures" folder.
+ */
+ public Builder() {
+ }
+
+ public Builder setDispatcher(MatcherDispatcher dispatcher) {
+ this.dispatcher = dispatcher;
+ return this;
+ }
+
+ /**
+ * Creates a rule with the given instance of {@link MockWebServer}. This will by default look
+ * for fixtures in the "fixtures" folder.
+ *
+ * @param server The {@link MockWebServer} instance
+ */
+ public Builder setServer(MockWebServer server) {
+ this.server = server;
+ return this;
+ }
+
+ /**
+ * Creates a rule with a new instance of {@link MockWebServer}.
+ *
+ * @param fixturesRootFolder The root folder to look for fixtures. Defaults to "fixtures"
+ */
+ public Builder setFixturesRootFolder(String fixturesRootFolder) {
+ this.fixturesRootFolder = fixturesRootFolder;
+ return this;
+ }
+
+ public RequestMatcherRule build() {
+ return new LocalTestRequestMatcherRule(server, fixturesRootFolder, dispatcher);
+ }
+ }
+}
\ No newline at end of file
diff --git a/requestmatcher/src/main/java/br/com/concretesolutions/requestmatcher/MapMatcherDispatcher.java b/requestmatcher/src/main/java/br/com/concretesolutions/requestmatcher/MapMatcherDispatcher.java
new file mode 100644
index 0000000..78ffe00
--- /dev/null
+++ b/requestmatcher/src/main/java/br/com/concretesolutions/requestmatcher/MapMatcherDispatcher.java
@@ -0,0 +1,71 @@
+package br.com.concretesolutions.requestmatcher;
+
+import java.util.Collections;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.logging.Level;
+
+import br.com.concretesolutions.requestmatcher.exception.NoMatchersForRequestException;
+import br.com.concretesolutions.requestmatcher.exception.RequestAssertionException;
+import okhttp3.mockwebserver.MockResponse;
+import okhttp3.mockwebserver.RecordedRequest;
+import okhttp3.mockwebserver.SocketPolicy;
+
+public final class MapMatcherDispatcher extends MatcherDispatcher {
+
+ private final Set responseSet = Collections.newSetFromMap(
+ new ConcurrentHashMap()
+ );
+
+ private RequestAssertionException assertionError;
+
+ @Override
+ public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
+
+ final int currentOrder = order.incrementAndGet();
+
+ int matcherOrder = 0;
+ final NoMatchersForRequestException.Builder builder =
+ new NoMatchersForRequestException.Builder(request);
+
+ for (ResponseWithMatcher response : responseSet) {
+
+ final RequestMatchersGroup matcher = response.getMatcher();
+
+ if (matcher != null) {
+ try {
+ matcher.doAssert(request, currentOrder);
+ responseSet.remove(response);
+ return response.getResponse(); // return proper response
+ } catch (AssertionError assertionError) {
+ builder.appendAssertionError(++matcherOrder, assertionError, matcher);
+ // continue
+ } catch (Exception e) {
+ this.assertionError = new RequestAssertionException(DEFAULT_MESSAGE, e);
+ logger.log(Level.SEVERE, "Error while doing assert", e);
+ return response.getResponse(); // return response but keep exception
+ }
+ }
+ }
+
+ // noinspection ThrowableInstanceNeverThrown
+ this.assertionError = new RequestAssertionException(DEFAULT_MESSAGE, builder.build());
+ return new MockResponse().setSocketPolicy(SocketPolicy.DISCONNECT_AT_END);
+ }
+
+ @Override
+ public RequestAssertionException getAssertionException() {
+ return assertionError;
+ }
+
+ @Override
+ public int size() {
+ return responseSet.size();
+ }
+
+ @Override
+ public Set getResponses() {
+ return responseSet;
+ }
+
+}
diff --git a/requestmatcher/src/main/java/br/com/concretesolutions/requestmatcher/MatcherDispatcher.java b/requestmatcher/src/main/java/br/com/concretesolutions/requestmatcher/MatcherDispatcher.java
index 458d0fc..61fb89e 100644
--- a/requestmatcher/src/main/java/br/com/concretesolutions/requestmatcher/MatcherDispatcher.java
+++ b/requestmatcher/src/main/java/br/com/concretesolutions/requestmatcher/MatcherDispatcher.java
@@ -1,77 +1,20 @@
package br.com.concretesolutions.requestmatcher;
-import java.util.Collections;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
+import java.util.Collection;
import java.util.concurrent.atomic.AtomicInteger;
-import java.util.logging.Level;
import java.util.logging.Logger;
-import br.com.concretesolutions.requestmatcher.exception.NoMatchersForRequestException;
import br.com.concretesolutions.requestmatcher.exception.RequestAssertionException;
import okhttp3.mockwebserver.Dispatcher;
import okhttp3.mockwebserver.MockResponse;
-import okhttp3.mockwebserver.RecordedRequest;
-import okhttp3.mockwebserver.SocketPolicy;
-public final class MatcherDispatcher extends Dispatcher {
+public abstract class MatcherDispatcher extends Dispatcher {
- private static final Logger logger = Logger.getLogger(MatcherDispatcher.class.getName());
- private static final String ASSERT_HEADER = "REQUEST-ASSERT";
- private static final String DEFAULT_MESSAGE = "Unexpected exception during assertion.";
+ protected static final Logger logger = Logger.getLogger(MatcherDispatcher.class.getName());
+ protected static final String ASSERT_HEADER = "REQUEST-ASSERT";
+ protected static final String DEFAULT_MESSAGE = "Unexpected exception during assertion.";
- private final AtomicInteger order = new AtomicInteger();
- private final Set responseSet = Collections.newSetFromMap(
- new ConcurrentHashMap()
- );
-
- private RequestAssertionException assertionError;
-
- @Override
- public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
-
- final int currentOrder = order.incrementAndGet();
-
- int matcherOrder = 0;
- final NoMatchersForRequestException.Builder builder =
- new NoMatchersForRequestException.Builder(request);
-
- for (ResponseWithMatcher response : responseSet) {
-
- final RequestMatchersGroup matcher = response.getMatcher();
-
- if (matcher != null) {
- try {
- matcher.doAssert(request, currentOrder);
- responseSet.remove(response);
- return response.getResponse(); // return proper response
- } catch (AssertionError assertionError) {
- builder.appendAssertionError(++matcherOrder, assertionError, matcher);
- // continue
- } catch (Exception e) {
- this.assertionError = new RequestAssertionException(DEFAULT_MESSAGE, e);
- logger.log(Level.SEVERE, "Error while doing assert", e);
- return response.getResponse(); // return response but keep exception
- }
- }
- }
-
- // noinspection ThrowableInstanceNeverThrown
- this.assertionError = new RequestAssertionException(DEFAULT_MESSAGE, builder.build());
- return new MockResponse().setSocketPolicy(SocketPolicy.DISCONNECT_AT_END);
- }
-
- public RequestAssertionException getAssertionException() {
- return assertionError;
- }
-
- public int size() {
- return responseSet.size();
- }
-
- public Set getResponseSet() {
- return responseSet;
- }
+ protected final AtomicInteger order = new AtomicInteger();
public RequestMatchersGroup addFixture(MockResponse response) {
return addFixture(response, new RequestMatchersGroup());
@@ -79,10 +22,17 @@ public RequestMatchersGroup addFixture(MockResponse response) {
public T addFixture(MockResponse response, T requestMatcher) {
final String assertPath = response.hashCode() + "::" + System.identityHashCode(requestMatcher);
- responseSet.add(new ResponseWithMatcher(requestMatcher, response.setHeader(ASSERT_HEADER, assertPath)));
+ getResponses().add(new ResponseWithMatcher(requestMatcher, response.setHeader(MatcherDispatcher.ASSERT_HEADER, assertPath)));
return requestMatcher;
}
+
+ public abstract int size();
+
+ public abstract Collection getResponses();
+
+ public abstract RequestAssertionException getAssertionException();
+
public static class ResponseWithMatcher {
private final MockResponse response;
private final RequestMatchersGroup matcher;
diff --git a/requestmatcher/src/main/java/br/com/concretesolutions/requestmatcher/QueueMatcherDispatcher.java b/requestmatcher/src/main/java/br/com/concretesolutions/requestmatcher/QueueMatcherDispatcher.java
new file mode 100644
index 0000000..13531c3
--- /dev/null
+++ b/requestmatcher/src/main/java/br/com/concretesolutions/requestmatcher/QueueMatcherDispatcher.java
@@ -0,0 +1,68 @@
+package br.com.concretesolutions.requestmatcher;
+
+import java.util.Queue;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.logging.Level;
+
+import br.com.concretesolutions.requestmatcher.exception.NoMatchersForRequestException;
+import br.com.concretesolutions.requestmatcher.exception.RequestAssertionException;
+import okhttp3.mockwebserver.MockResponse;
+import okhttp3.mockwebserver.RecordedRequest;
+import okhttp3.mockwebserver.SocketPolicy;
+
+public final class QueueMatcherDispatcher extends MatcherDispatcher {
+
+ private final Queue responseSet = new ConcurrentLinkedQueue<>();
+
+ private RequestAssertionException assertionError;
+
+ @Override
+ public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
+
+ final int currentOrder = order.incrementAndGet();
+
+ int matcherOrder = 0;
+ final NoMatchersForRequestException.Builder builder =
+ new NoMatchersForRequestException.Builder(request);
+
+ final ResponseWithMatcher response = responseSet.remove();
+
+ if (response != null) {
+ final RequestMatchersGroup matcher = response.getMatcher();
+
+ if (matcher != null) {
+ try {
+ matcher.doAssert(request, currentOrder);
+ return response.getResponse(); // return proper response
+ } catch (AssertionError assertionError) {
+ builder.appendAssertionError(++matcherOrder, assertionError, matcher);
+ // continue
+ } catch (Exception e) {
+ this.assertionError = new RequestAssertionException(DEFAULT_MESSAGE, e);
+ logger.log(Level.SEVERE, "Error while doing assert", e);
+ return response.getResponse(); // return response but keep exception
+ }
+ }
+ }
+
+ // noinspection ThrowableInstanceNeverThrown
+ this.assertionError = new RequestAssertionException(DEFAULT_MESSAGE, builder.build());
+ return new MockResponse().setSocketPolicy(SocketPolicy.DISCONNECT_AT_END);
+ }
+
+ @Override
+ public RequestAssertionException getAssertionException() {
+ return assertionError;
+ }
+
+ @Override
+ public int size() {
+ return responseSet.size();
+ }
+
+ @Override
+ public Queue getResponses() {
+ return responseSet;
+ }
+
+}
diff --git a/requestmatcher/src/main/java/br/com/concretesolutions/requestmatcher/RequestMatcherRule.java b/requestmatcher/src/main/java/br/com/concretesolutions/requestmatcher/RequestMatcherRule.java
index ef0be8a..4afcb6a 100644
--- a/requestmatcher/src/main/java/br/com/concretesolutions/requestmatcher/RequestMatcherRule.java
+++ b/requestmatcher/src/main/java/br/com/concretesolutions/requestmatcher/RequestMatcherRule.java
@@ -43,28 +43,17 @@
*/
public abstract class RequestMatcherRule implements TestRule {
- private final MatcherDispatcher dispatcher = new MatcherDispatcher();
+ private final MatcherDispatcher dispatcher;
private final MockWebServer server;
private final String fixturesRootFolder;
private final Map defaultHeaders = new HashMap<>();
private boolean guessMimeType = true;
- RequestMatcherRule() {
- this(new MockWebServer());
- }
-
- RequestMatcherRule(String fixturesRootFolder) {
- this(new MockWebServer(), fixturesRootFolder);
- }
-
- RequestMatcherRule(MockWebServer server) {
- this(server, "fixtures");
- }
-
- RequestMatcherRule(MockWebServer server, String fixturesRootFolder) {
+ RequestMatcherRule(MockWebServer server, String fixturesRootFolder, MatcherDispatcher dispatcher) {
this.server = server;
this.fixturesRootFolder = fixturesRootFolder;
+ this.dispatcher = dispatcher;
}
// implemented by Unit and Instrumented dispatchers to find fixtures folder
@@ -286,7 +275,7 @@ private void after(Exception exception, boolean success) throws Exception {
if (dispatcher.size() != 0) {
try {
final StringBuilder errorHint = new StringBuilder(100);
- for (MatcherDispatcher.ResponseWithMatcher remainingResponse : dispatcher.getResponseSet()) {
+ for (MatcherDispatcher.ResponseWithMatcher remainingResponse : dispatcher.getResponses()) {
final String matcher = remainingResponse.getMatcher().toString();
final String response = remainingResponse.getResponse().toString();
@@ -301,6 +290,7 @@ private void after(Exception exception, boolean success) throws Exception {
throw new RequestAssertionException("Failed assertion.", e);
}
}
+
}
private Statement requestAssertionStatement(final Statement base) {
diff --git a/requestmatcher/src/test-common/java/br/com/concretesolutions/requestmatcher/test/ExceptionInStatementTest.java b/requestmatcher/src/test-common/java/br/com/concretesolutions/requestmatcher/test/ExceptionInStatementTest.java
index fc3580f..ebf9e17 100644
--- a/requestmatcher/src/test-common/java/br/com/concretesolutions/requestmatcher/test/ExceptionInStatementTest.java
+++ b/requestmatcher/src/test-common/java/br/com/concretesolutions/requestmatcher/test/ExceptionInStatementTest.java
@@ -11,7 +11,6 @@
import java.util.concurrent.TimeUnit;
import br.com.concretesolutions.requestmatcher.RequestMatcherRule;
-import br.com.concretesolutions.requestmatcher.RequestMatchersGroup;
import br.com.concretesolutions.requestmatcher.exception.RequestAssertionException;
import br.com.concretesolutions.requestmatcher.model.HttpMethod;
import okhttp3.MediaType;
@@ -19,24 +18,18 @@
import okhttp3.Request;
import okhttp3.RequestBody;
-import static org.hamcrest.Matchers.allOf;
-import static org.hamcrest.Matchers.any;
-import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.hasEntry;
-import static org.hamcrest.Matchers.is;
-
public abstract class ExceptionInStatementTest extends BaseTest {
- private final ExpectedException exceptionRule = ExpectedException.none();
- private final RequestMatcherRule server = getRequestMatcherRule();
+ protected final ExpectedException exceptionRule = ExpectedException.none();
+ protected final RequestMatcherRule server = getRequestMatcherRule();
@Rule
public TestRule chain = RuleChain
.outerRule(exceptionRule)
.around(server);
- private OkHttpClient client;
- private Request request;
+ protected OkHttpClient client;
+ protected Request request;
@Before
public void setUp() {
@@ -68,39 +61,4 @@ public void ensureAProgrammingExceptionInTestDoesNotShadowAssertion() throws IOE
// throws NullPointerException in statement!!!
nullRef.equals("");
}
-
- @Test
- public void ensureNoMatchersMessageIsReadable() throws IOException {
-
- exceptionRule.expect(RequestAssertionException.class);
- exceptionRule.expectMessage(
- allOf(
- containsString("method: is "),
- containsString("method: is "),
- containsString("method: is "),
- containsString("method: is "),
- containsString("request order: is <2>"),
- containsString(RequestMatchersGroup.ORDER_MSG),
- containsString(RequestMatchersGroup.METHOD_MSG),
- containsString(RequestMatchersGroup.QUERIES_MSG)
- ));
-
- server.addFixture(201, "body.json")
- .ifRequestMatches()
- .methodIs(HttpMethod.PATCH)
- .queriesMatches(is(hasEntry(is("key"), any(String.class))));
- server.addFixture(201, "body.json").ifRequestMatches().methodIs(HttpMethod.POST);
- server.addFixture(201, "body.json").ifRequestMatches().methodIs(HttpMethod.PUT);
- server.addFixture(201, "body.json").ifRequestMatches().methodIs(HttpMethod.DELETE);
- server.addFixture(201, "body.json").ifRequestMatches().methodIs(HttpMethod.GET);
- server.addFixture(201, "body.json").ifRequestMatches().methodIs(HttpMethod.PATCH).orderIs(2);
-
- this.request = new Request.Builder()
- .url(server.url("/head").toString())
- .patch(RequestBody.create(MediaType.parse("application/json"), "{\"property\": \"value\"}"))
- .build();
-
- // throws RequestAssertionException expected in after clause
- client.newCall(request).execute();
- }
}
diff --git a/requestmatcher/src/test-common/java/br/com/concretesolutions/requestmatcher/test/ExceptionWitouhtEnqueuesTest.java b/requestmatcher/src/test-common/java/br/com/concretesolutions/requestmatcher/test/ExceptionWithoutEnqueuesTest.java
similarity index 93%
rename from requestmatcher/src/test-common/java/br/com/concretesolutions/requestmatcher/test/ExceptionWitouhtEnqueuesTest.java
rename to requestmatcher/src/test-common/java/br/com/concretesolutions/requestmatcher/test/ExceptionWithoutEnqueuesTest.java
index c2866de..ac4208b 100644
--- a/requestmatcher/src/test-common/java/br/com/concretesolutions/requestmatcher/test/ExceptionWitouhtEnqueuesTest.java
+++ b/requestmatcher/src/test-common/java/br/com/concretesolutions/requestmatcher/test/ExceptionWithoutEnqueuesTest.java
@@ -10,7 +10,7 @@
import br.com.concretesolutions.requestmatcher.RequestMatcherRule;
-public abstract class ExceptionWitouhtEnqueuesTest extends BaseTest {
+public abstract class ExceptionWithoutEnqueuesTest extends BaseTest {
private final ExpectedException exceptionRule = ExpectedException.none();
private final RequestMatcherRule server = getRequestMatcherRule();
diff --git a/requestmatcher/src/test-common/java/br/com/concretesolutions/requestmatcher/test/RequestMatcherRuleTest.java b/requestmatcher/src/test-common/java/br/com/concretesolutions/requestmatcher/test/RequestMatcherRuleTest.java
index e4882f1..0ce8c9c 100644
--- a/requestmatcher/src/test-common/java/br/com/concretesolutions/requestmatcher/test/RequestMatcherRuleTest.java
+++ b/requestmatcher/src/test-common/java/br/com/concretesolutions/requestmatcher/test/RequestMatcherRuleTest.java
@@ -34,16 +34,16 @@
public abstract class RequestMatcherRuleTest extends BaseTest {
- private final ExpectedException exceptionRule = ExpectedException.none();
- private final RequestMatcherRule server = getRequestMatcherRule();
+ protected final ExpectedException exceptionRule = ExpectedException.none();
+ protected final RequestMatcherRule server = getRequestMatcherRule();
@Rule
public TestRule chain = RuleChain
.outerRule(exceptionRule)
.around(server);
- private OkHttpClient client;
- private Request request;
+ protected OkHttpClient client;
+ protected Request request;
@Before
public void setUp() {
@@ -53,44 +53,6 @@ public void setUp() {
.build();
}
- @Test
- public void canAssertRequestsOutOfOrder() throws IOException {
-
- server.addFixture(200, "body.json")
- .ifRequestMatches()
- .hasEmptyBody()
- .methodIs(HttpMethod.GET)
- .pathIs("/get");
-
- server.addFixture(200, "body.json")
- .ifRequestMatches()
- .pathIs("/post")
- .headersContain("key", "value")
- .methodIs(HttpMethod.POST)
- .bodyMatches(containsString("\"property\": \"value\""));
-
- this.request = new Request.Builder()
- .url(server.url("/post"))
- .header("key", "value")
- .post(RequestBody.create(MediaType.parse("application/json"), "{\"property\": \"value\"}"))
- .build();
-
- Response resp = client.newCall(request).execute();
-
- assertThat(resp.isSuccessful(), is(true));
- assertThat(resp.peekBody(1_000_000).source().readUtf8(), containsString("property\": \"value\""));
-
- this.request = new Request.Builder()
- .url(server.url("/get"))
- .get()
- .build();
-
- resp = client.newCall(request).execute();
-
- assertThat(resp.isSuccessful(), is(true));
- assertThat(resp.peekBody(1_000_000).source().readUtf8(), containsString("property\": \"value\""));
- }
-
@Test
public void failsIfExpectedNoBodyButOneWasProvided() throws IOException {
@@ -438,49 +400,6 @@ public void failsForUnknownJsonPath() throws IOException {
assertThat(resp.peekBody(1_000_000).source().readUtf8(), containsString("property\": \"value\""));
}
- @Test
- public void failsIfOrderIsDifferent() throws IOException {
-
- exceptionRule.expect(RequestAssertionException.class);
- exceptionRule.expectMessage(
- allOf(
- containsString("order: is <3>"),
- containsString(RequestMatchersGroup.ORDER_MSG)
- ));
-
- server.addFixture(200, "body.json")
- .ifRequestMatches()
- .hasEmptyBody()
- .orderIs(3) // will not math
- .methodIs(HttpMethod.GET)
- .pathIs("/get");
-
- server.addFixture(200, "body.json")
- .ifRequestMatches()
- .pathIs("/post")
- .headersContain("key", "value")
- .methodIs(HttpMethod.POST)
- .bodyMatches(containsString("\"property\": \"value\""));
-
- this.request = new Request.Builder()
- .url(server.url("/post"))
- .header("key", "value")
- .post(RequestBody.create(MediaType.parse("application/json"), "{\"property\": \"value\"}"))
- .build();
-
- final Response resp = client.newCall(request).execute();
-
- assertThat(resp.isSuccessful(), is(true));
- assertThat(resp.peekBody(1_000_000).source().readUtf8(), containsString("property\": \"value\""));
-
- this.request = new Request.Builder()
- .url(server.url("/get"))
- .get()
- .build();
-
- client.newCall(request).execute();
- }
-
@Test
public void canMatchHeaderOnlyByKey() throws IOException {
@@ -740,37 +659,6 @@ public void canAssertRequestBodyMultipleTimes() throws IOException {
client.newCall(request1).execute();
}
- @Test
- public void canKeepOrderOfFixtures() throws IOException {
- // prepare
- String path = "/same/path";
- Request request0 = new Request.Builder()
- .url(server.url(path))
- .get()
- .build();
- Request request1 = new Request.Builder()
- .url(server.url(path))
- .get()
- .build();
-
- server.addFixture(200, "body.json")
- .ifRequestMatches()
- .orderIs(2)
- .pathIs(path);
- server.addFixture(201, "body.json") // <- code = 201 must be the first one!
- .ifRequestMatches()
- .orderIs(1)
- .pathIs(path);
-
- // execute
- Response response0 = client.newCall(request0).execute();
- Response response1 = client.newCall(request1).execute();
-
- // verify
- assertThat(response0.code(), is(201));
- assertThat(response1.code(), is(200));
- }
-
@Test
public void informsAboutNotUsedFixture() throws IOException {
// prepare
diff --git a/requestmatcher/src/test-common/java/br/com/concretesolutions/requestmatcher/test/dispachers/map/MapExceptionInStatementTest.java b/requestmatcher/src/test-common/java/br/com/concretesolutions/requestmatcher/test/dispachers/map/MapExceptionInStatementTest.java
new file mode 100644
index 0000000..0a12406
--- /dev/null
+++ b/requestmatcher/src/test-common/java/br/com/concretesolutions/requestmatcher/test/dispachers/map/MapExceptionInStatementTest.java
@@ -0,0 +1,57 @@
+package br.com.concretesolutions.requestmatcher.test.dispachers.map;
+
+import org.junit.Test;
+
+import java.io.IOException;
+
+import br.com.concretesolutions.requestmatcher.RequestMatchersGroup;
+import br.com.concretesolutions.requestmatcher.exception.RequestAssertionException;
+import br.com.concretesolutions.requestmatcher.model.HttpMethod;
+import br.com.concretesolutions.requestmatcher.test.ExceptionInStatementTest;
+import okhttp3.MediaType;
+import okhttp3.Request;
+import okhttp3.RequestBody;
+
+import static org.hamcrest.Matchers.allOf;
+import static org.hamcrest.Matchers.any;
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.hasEntry;
+import static org.hamcrest.Matchers.is;
+
+public abstract class MapExceptionInStatementTest extends ExceptionInStatementTest {
+
+ @Test
+ public void ensureNoMatchersMessageIsReadable() throws IOException {
+
+ exceptionRule.expect(RequestAssertionException.class);
+ exceptionRule.expectMessage(
+ allOf(
+ containsString("method: is "),
+ containsString("method: is "),
+ containsString("method: is "),
+ containsString("method: is "),
+ containsString("request order: is <2>"),
+ containsString(RequestMatchersGroup.ORDER_MSG),
+ containsString(RequestMatchersGroup.METHOD_MSG),
+ containsString(RequestMatchersGroup.QUERIES_MSG)
+ ));
+
+ server.addFixture(201, "body.json")
+ .ifRequestMatches()
+ .methodIs(HttpMethod.PATCH)
+ .queriesMatches(is(hasEntry(is("key"), any(String.class))));
+ server.addFixture(201, "body.json").ifRequestMatches().methodIs(HttpMethod.POST);
+ server.addFixture(201, "body.json").ifRequestMatches().methodIs(HttpMethod.PUT);
+ server.addFixture(201, "body.json").ifRequestMatches().methodIs(HttpMethod.DELETE);
+ server.addFixture(201, "body.json").ifRequestMatches().methodIs(HttpMethod.GET);
+ server.addFixture(201, "body.json").ifRequestMatches().methodIs(HttpMethod.PATCH).orderIs(2);
+
+ this.request = new Request.Builder()
+ .url(server.url("/head").toString())
+ .patch(RequestBody.create(MediaType.parse("application/json"), "{\"property\": \"value\"}"))
+ .build();
+
+ // throws RequestAssertionException expected in after clause
+ client.newCall(request).execute();
+ }
+}
diff --git a/requestmatcher/src/test-common/java/br/com/concretesolutions/requestmatcher/test/dispachers/map/MapRequestMatcherRuleTest.java b/requestmatcher/src/test-common/java/br/com/concretesolutions/requestmatcher/test/dispachers/map/MapRequestMatcherRuleTest.java
new file mode 100644
index 0000000..4c20c2d
--- /dev/null
+++ b/requestmatcher/src/test-common/java/br/com/concretesolutions/requestmatcher/test/dispachers/map/MapRequestMatcherRuleTest.java
@@ -0,0 +1,135 @@
+package br.com.concretesolutions.requestmatcher.test.dispachers.map;
+
+import org.junit.Test;
+
+import java.io.IOException;
+
+import br.com.concretesolutions.requestmatcher.RequestMatchersGroup;
+import br.com.concretesolutions.requestmatcher.exception.RequestAssertionException;
+import br.com.concretesolutions.requestmatcher.model.HttpMethod;
+import br.com.concretesolutions.requestmatcher.test.RequestMatcherRuleTest;
+import okhttp3.MediaType;
+import okhttp3.Request;
+import okhttp3.RequestBody;
+import okhttp3.Response;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.allOf;
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.is;
+
+public abstract class MapRequestMatcherRuleTest extends RequestMatcherRuleTest {
+
+ @Test
+ public void canKeepOrderOfFixtures() throws IOException {
+ // prepare
+ String path = "/same/path";
+ Request request0 = new Request.Builder()
+ .url(server.url(path))
+ .get()
+ .build();
+ Request request1 = new Request.Builder()
+ .url(server.url(path))
+ .get()
+ .build();
+
+ server.addFixture(200, "body.json")
+ .ifRequestMatches()
+ .orderIs(2)
+ .pathIs(path);
+ server.addFixture(201, "body.json") // <- code = 201 must be the first one!
+ .ifRequestMatches()
+ .orderIs(1)
+ .pathIs(path);
+
+ // execute
+ Response response0 = client.newCall(request0).execute();
+ Response response1 = client.newCall(request1).execute();
+
+ // verify
+ assertThat(response0.code(), is(201));
+ assertThat(response1.code(), is(200));
+ }
+
+ @Test
+ public void failsIfOrderIsDifferent() throws IOException {
+
+ exceptionRule.expect(RequestAssertionException.class);
+ exceptionRule.expectMessage(
+ allOf(
+ containsString("order: is <3>"),
+ containsString(RequestMatchersGroup.ORDER_MSG)
+ ));
+
+ server.addFixture(200, "body.json")
+ .ifRequestMatches()
+ .hasEmptyBody()
+ .orderIs(3) // will not match
+ .methodIs(HttpMethod.GET)
+ .pathIs("/get");
+
+ server.addFixture(200, "body.json")
+ .ifRequestMatches()
+ .pathIs("/post")
+ .headersContain("key", "value")
+ .methodIs(HttpMethod.POST)
+ .bodyMatches(containsString("\"property\": \"value\""));
+
+ this.request = new Request.Builder()
+ .url(server.url("/post"))
+ .header("key", "value")
+ .post(RequestBody.create(MediaType.parse("application/json"), "{\"property\": \"value\"}"))
+ .build();
+
+ final Response resp = client.newCall(request).execute();
+
+ assertThat(resp.isSuccessful(), is(true));
+ assertThat(resp.peekBody(1_000_000).source().readUtf8(), containsString("property\": \"value\""));
+
+ this.request = new Request.Builder()
+ .url(server.url("/get"))
+ .get()
+ .build();
+
+ client.newCall(request).execute();
+ }
+
+ @Test
+ public void canAssertRequestsOutOfOrder() throws IOException {
+
+ server.addFixture(200, "body.json")
+ .ifRequestMatches()
+ .hasEmptyBody()
+ .methodIs(HttpMethod.GET)
+ .pathIs("/get");
+
+ server.addFixture(200, "body.json")
+ .ifRequestMatches()
+ .pathIs("/post")
+ .headersContain("key", "value")
+ .methodIs(HttpMethod.POST)
+ .bodyMatches(containsString("\"property\": \"value\""));
+
+ this.request = new Request.Builder()
+ .url(server.url("/post"))
+ .header("key", "value")
+ .post(RequestBody.create(MediaType.parse("application/json"), "{\"property\": \"value\"}"))
+ .build();
+
+ Response resp = client.newCall(request).execute();
+
+ assertThat(resp.isSuccessful(), is(true));
+ assertThat(resp.peekBody(1_000_000).source().readUtf8(), containsString("property\": \"value\""));
+
+ this.request = new Request.Builder()
+ .url(server.url("/get"))
+ .get()
+ .build();
+
+ resp = client.newCall(request).execute();
+
+ assertThat(resp.isSuccessful(), is(true));
+ assertThat(resp.peekBody(1_000_000).source().readUtf8(), containsString("property\": \"value\""));
+ }
+
+}
diff --git a/requestmatcher/src/test-common/java/br/com/concretesolutions/requestmatcher/test/dispachers/queue/QueueExceptionInStatementTest.java b/requestmatcher/src/test-common/java/br/com/concretesolutions/requestmatcher/test/dispachers/queue/QueueExceptionInStatementTest.java
new file mode 100644
index 0000000..7248c9d
--- /dev/null
+++ b/requestmatcher/src/test-common/java/br/com/concretesolutions/requestmatcher/test/dispachers/queue/QueueExceptionInStatementTest.java
@@ -0,0 +1,6 @@
+package br.com.concretesolutions.requestmatcher.test.dispachers.queue;
+
+import br.com.concretesolutions.requestmatcher.test.ExceptionInStatementTest;
+
+public abstract class QueueExceptionInStatementTest extends ExceptionInStatementTest {
+}
diff --git a/requestmatcher/src/test-common/java/br/com/concretesolutions/requestmatcher/test/dispachers/queue/QueueRequestMatcherRuleTest.java b/requestmatcher/src/test-common/java/br/com/concretesolutions/requestmatcher/test/dispachers/queue/QueueRequestMatcherRuleTest.java
new file mode 100644
index 0000000..06cf782
--- /dev/null
+++ b/requestmatcher/src/test-common/java/br/com/concretesolutions/requestmatcher/test/dispachers/queue/QueueRequestMatcherRuleTest.java
@@ -0,0 +1,7 @@
+package br.com.concretesolutions.requestmatcher.test.dispachers.queue;
+
+import br.com.concretesolutions.requestmatcher.test.RequestMatcherRuleTest;
+
+public abstract class QueueRequestMatcherRuleTest extends RequestMatcherRuleTest {
+
+}
diff --git a/requestmatcher/src/test/java/br/com/concretesolutions/requestmatcher/IOReaderTest.java b/requestmatcher/src/test/java/br/com/concretesolutions/requestmatcher/IOReaderTest.java
index 375fc49..208d183 100644
--- a/requestmatcher/src/test/java/br/com/concretesolutions/requestmatcher/IOReaderTest.java
+++ b/requestmatcher/src/test/java/br/com/concretesolutions/requestmatcher/IOReaderTest.java
@@ -1,9 +1,6 @@
package br.com.concretesolutions.requestmatcher;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.robolectric.RobolectricTestRunner;
-import org.robolectric.annotation.Config;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
diff --git a/requestmatcher/src/test/java/br/com/concretesolutions/requestmatcher/test/CustomRequestMatcherTest.java b/requestmatcher/src/test/java/br/com/concretesolutions/requestmatcher/test/CustomRequestMatcherTest.java
index f0dd219..0ad3f9b 100644
--- a/requestmatcher/src/test/java/br/com/concretesolutions/requestmatcher/test/CustomRequestMatcherTest.java
+++ b/requestmatcher/src/test/java/br/com/concretesolutions/requestmatcher/test/CustomRequestMatcherTest.java
@@ -41,7 +41,7 @@
public class CustomRequestMatcherTest {
private final ExpectedException exceptionRule = ExpectedException.none();
- private final RequestMatcherRule server = new LocalTestRequestMatcherRule();
+ private final RequestMatcherRule server = new LocalTestRequestMatcherRule.Builder().build();
@Rule
public TestRule chain = RuleChain
diff --git a/requestmatcher/src/test/java/br/com/concretesolutions/requestmatcher/test/LocalExceptionWitouhtEnqueuesTest.java b/requestmatcher/src/test/java/br/com/concretesolutions/requestmatcher/test/LocalExceptionWitouhtEnqueuesTest.java
deleted file mode 100644
index fd9e1dc..0000000
--- a/requestmatcher/src/test/java/br/com/concretesolutions/requestmatcher/test/LocalExceptionWitouhtEnqueuesTest.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package br.com.concretesolutions.requestmatcher.test;
-
-import br.com.concretesolutions.requestmatcher.LocalTestRequestMatcherRule;
-import br.com.concretesolutions.requestmatcher.RequestMatcherRule;
-
-public class LocalExceptionWitouhtEnqueuesTest extends ExceptionWitouhtEnqueuesTest {
-
- @Override
- protected RequestMatcherRule getRequestMatcherRule() {
- return new LocalTestRequestMatcherRule();
- }
-}
diff --git a/requestmatcher/src/test/java/br/com/concretesolutions/requestmatcher/test/LocalExceptionInStatementTest.java b/requestmatcher/src/test/java/br/com/concretesolutions/requestmatcher/test/dispachers/map/LocalExceptionInStatementTest.java
similarity index 59%
rename from requestmatcher/src/test/java/br/com/concretesolutions/requestmatcher/test/LocalExceptionInStatementTest.java
rename to requestmatcher/src/test/java/br/com/concretesolutions/requestmatcher/test/dispachers/map/LocalExceptionInStatementTest.java
index 370919f..f734854 100644
--- a/requestmatcher/src/test/java/br/com/concretesolutions/requestmatcher/test/LocalExceptionInStatementTest.java
+++ b/requestmatcher/src/test/java/br/com/concretesolutions/requestmatcher/test/dispachers/map/LocalExceptionInStatementTest.java
@@ -1,14 +1,14 @@
-package br.com.concretesolutions.requestmatcher.test;
+package br.com.concretesolutions.requestmatcher.test.dispachers.map;
import br.com.concretesolutions.requestmatcher.LocalTestRequestMatcherRule;
import br.com.concretesolutions.requestmatcher.RequestMatcherRule;
//@RunWith(RobolectricTestRunner.class)
//@Config(constants = BuildConfig.class, sdk = 23)
-public class LocalExceptionInStatementTest extends ExceptionInStatementTest {
+public class LocalExceptionInStatementTest extends MapExceptionInStatementTest {
@Override
protected RequestMatcherRule getRequestMatcherRule() {
- return new LocalTestRequestMatcherRule();
+ return new LocalTestRequestMatcherRule.Builder().build();
}
}
diff --git a/requestmatcher/src/test/java/br/com/concretesolutions/requestmatcher/test/dispachers/map/LocalExceptionWithoutEnqueuesTest.java b/requestmatcher/src/test/java/br/com/concretesolutions/requestmatcher/test/dispachers/map/LocalExceptionWithoutEnqueuesTest.java
new file mode 100644
index 0000000..c0ae9d1
--- /dev/null
+++ b/requestmatcher/src/test/java/br/com/concretesolutions/requestmatcher/test/dispachers/map/LocalExceptionWithoutEnqueuesTest.java
@@ -0,0 +1,13 @@
+package br.com.concretesolutions.requestmatcher.test.dispachers.map;
+
+import br.com.concretesolutions.requestmatcher.LocalTestRequestMatcherRule;
+import br.com.concretesolutions.requestmatcher.RequestMatcherRule;
+import br.com.concretesolutions.requestmatcher.test.ExceptionWithoutEnqueuesTest;
+
+public class LocalExceptionWithoutEnqueuesTest extends ExceptionWithoutEnqueuesTest {
+
+ @Override
+ protected RequestMatcherRule getRequestMatcherRule() {
+ return new LocalTestRequestMatcherRule.Builder().build();
+ }
+}
diff --git a/requestmatcher/src/test/java/br/com/concretesolutions/requestmatcher/test/LocalRequestMatcherRuleTest.java b/requestmatcher/src/test/java/br/com/concretesolutions/requestmatcher/test/dispachers/map/LocalRequestMatcherRuleTest.java
similarity index 51%
rename from requestmatcher/src/test/java/br/com/concretesolutions/requestmatcher/test/LocalRequestMatcherRuleTest.java
rename to requestmatcher/src/test/java/br/com/concretesolutions/requestmatcher/test/dispachers/map/LocalRequestMatcherRuleTest.java
index 801e818..c1ba340 100644
--- a/requestmatcher/src/test/java/br/com/concretesolutions/requestmatcher/test/LocalRequestMatcherRuleTest.java
+++ b/requestmatcher/src/test/java/br/com/concretesolutions/requestmatcher/test/dispachers/map/LocalRequestMatcherRuleTest.java
@@ -1,12 +1,12 @@
-package br.com.concretesolutions.requestmatcher.test;
+package br.com.concretesolutions.requestmatcher.test.dispachers.map;
import br.com.concretesolutions.requestmatcher.LocalTestRequestMatcherRule;
import br.com.concretesolutions.requestmatcher.RequestMatcherRule;
-public class LocalRequestMatcherRuleTest extends RequestMatcherRuleTest {
+public class LocalRequestMatcherRuleTest extends MapRequestMatcherRuleTest {
@Override
protected RequestMatcherRule getRequestMatcherRule() {
- return new LocalTestRequestMatcherRule();
+ return new LocalTestRequestMatcherRule.Builder().build();
}
}
diff --git a/requestmatcher/src/test/java/br/com/concretesolutions/requestmatcher/test/dispachers/queue/LocalExceptionInStatementTest.java b/requestmatcher/src/test/java/br/com/concretesolutions/requestmatcher/test/dispachers/queue/LocalExceptionInStatementTest.java
new file mode 100644
index 0000000..a909b2e
--- /dev/null
+++ b/requestmatcher/src/test/java/br/com/concretesolutions/requestmatcher/test/dispachers/queue/LocalExceptionInStatementTest.java
@@ -0,0 +1,17 @@
+package br.com.concretesolutions.requestmatcher.test.dispachers.queue;
+
+import br.com.concretesolutions.requestmatcher.LocalTestRequestMatcherRule;
+import br.com.concretesolutions.requestmatcher.QueueMatcherDispatcher;
+import br.com.concretesolutions.requestmatcher.RequestMatcherRule;
+
+//@RunWith(RobolectricTestRunner.class)
+//@Config(constants = BuildConfig.class, sdk = 23)
+public class LocalExceptionInStatementTest extends QueueExceptionInStatementTest {
+
+ @Override
+ protected RequestMatcherRule getRequestMatcherRule() {
+ return new LocalTestRequestMatcherRule.Builder()
+ .setDispatcher(new QueueMatcherDispatcher())
+ .build();
+ }
+}
diff --git a/requestmatcher/src/test/java/br/com/concretesolutions/requestmatcher/test/dispachers/queue/LocalExceptionWithoutEnqueuesTest.java b/requestmatcher/src/test/java/br/com/concretesolutions/requestmatcher/test/dispachers/queue/LocalExceptionWithoutEnqueuesTest.java
new file mode 100644
index 0000000..008b832
--- /dev/null
+++ b/requestmatcher/src/test/java/br/com/concretesolutions/requestmatcher/test/dispachers/queue/LocalExceptionWithoutEnqueuesTest.java
@@ -0,0 +1,16 @@
+package br.com.concretesolutions.requestmatcher.test.dispachers.queue;
+
+import br.com.concretesolutions.requestmatcher.LocalTestRequestMatcherRule;
+import br.com.concretesolutions.requestmatcher.QueueMatcherDispatcher;
+import br.com.concretesolutions.requestmatcher.RequestMatcherRule;
+import br.com.concretesolutions.requestmatcher.test.ExceptionWithoutEnqueuesTest;
+
+public class LocalExceptionWithoutEnqueuesTest extends ExceptionWithoutEnqueuesTest {
+
+ @Override
+ protected RequestMatcherRule getRequestMatcherRule() {
+ return new LocalTestRequestMatcherRule.Builder()
+ .setDispatcher(new QueueMatcherDispatcher())
+ .build();
+ }
+}
diff --git a/requestmatcher/src/test/java/br/com/concretesolutions/requestmatcher/test/dispachers/queue/LocalRequestMatcherRuleTest.java b/requestmatcher/src/test/java/br/com/concretesolutions/requestmatcher/test/dispachers/queue/LocalRequestMatcherRuleTest.java
new file mode 100644
index 0000000..60c3ba9
--- /dev/null
+++ b/requestmatcher/src/test/java/br/com/concretesolutions/requestmatcher/test/dispachers/queue/LocalRequestMatcherRuleTest.java
@@ -0,0 +1,15 @@
+package br.com.concretesolutions.requestmatcher.test.dispachers.queue;
+
+import br.com.concretesolutions.requestmatcher.LocalTestRequestMatcherRule;
+import br.com.concretesolutions.requestmatcher.QueueMatcherDispatcher;
+import br.com.concretesolutions.requestmatcher.RequestMatcherRule;
+
+public class LocalRequestMatcherRuleTest extends QueueRequestMatcherRuleTest {
+
+ @Override
+ protected RequestMatcherRule getRequestMatcherRule() {
+ return new LocalTestRequestMatcherRule.Builder()
+ .setDispatcher(new QueueMatcherDispatcher())
+ .build();
+ }
+}