@Test public void testThenAnswer() throws Exception { String path = "sample"; RESTMockServer.whenGET(pathEndsWith(path)).thenAnswer(new MockAnswer() { @Override public MockResponse answer(RecordedRequest request) { if ("True".equals(request.getHeaders().get("header"))) { return new MockResponse().setBody("OK").setResponseCode(200); } else { return new MockResponse().setBody("NOT OK").setResponseCode(400); } } }); Response responseTrue = TestUtils.get(path, new AbstractMap.SimpleEntry<>("header", "True")); Response responseFalse = TestUtils.get(path, new AbstractMap.SimpleEntry<>("header", "False")); assertEquals(200, responseTrue.code()); assertEquals(400, responseFalse.code()); assertEquals("OK", responseTrue.body().string()); assertEquals("NOT OK", responseFalse.body().string()); }
public static MatchableCall whenGET(Matcher<RecordedRequest> requestMatcher) { return RESTMockServer.whenRequested(allOf(isGET(), requestMatcher)); }
RESTMockServer { public static MatchableCall whenGET(Matcher<RecordedRequest> requestMatcher) { return RESTMockServer.whenRequested(allOf(isGET(), requestMatcher)); } }
RESTMockServer { public static MatchableCall whenGET(Matcher<RecordedRequest> requestMatcher) { return RESTMockServer.whenRequested(allOf(isGET(), requestMatcher)); } private  RESTMockServer(); }
RESTMockServer { public static MatchableCall whenGET(Matcher<RecordedRequest> requestMatcher) { return RESTMockServer.whenRequested(allOf(isGET(), requestMatcher)); } private  RESTMockServer(); static SSLSocketFactory getSSLSocketFactory(); static X509TrustManager getTrustManager(); static RESTMockLogger getLogger(); synchronized static void init(RESTMockFileParser restMockFileParser, RESTMockLogger logger); synchronized static void init(RESTMockFileParser restMockFileParser, RESTMockLogger logger, RESTMockOptions restMockOptions); static void enableLogging(RESTMockLogger logger); static void disableLogging(); @Deprecated static void removeAllMatchableCalls(); static void reset(); static boolean removeMatchableCall(MatchableCall call); static void replaceMatchableCall(MatchableCall call, MatchableCall replacement); static String getUrl(); static void addMatchableCall(final MatchableCall call); static MatchableCall whenGET(Matcher<RecordedRequest> requestMatcher); static MatchableCall whenPOST(Matcher<RecordedRequest> requestMatcher); static MatchableCall whenPUT(Matcher<RecordedRequest> requestMatcher); static MatchableCall whenPATCH(Matcher<RecordedRequest> requestMatcher); static MatchableCall whenDELETE(Matcher<RecordedRequest> requestMatcher); static MatchableCall whenHEAD(Matcher<RecordedRequest> requestMatcher); static MatchableCall whenRequested(Matcher<RecordedRequest> requestMatcher); static void shutdown(); }
RESTMockServer { public static MatchableCall whenGET(Matcher<RecordedRequest> requestMatcher) { return RESTMockServer.whenRequested(allOf(isGET(), requestMatcher)); } private  RESTMockServer(); static SSLSocketFactory getSSLSocketFactory(); static X509TrustManager getTrustManager(); static RESTMockLogger getLogger(); synchronized static void init(RESTMockFileParser restMockFileParser, RESTMockLogger logger); synchronized static void init(RESTMockFileParser restMockFileParser, RESTMockLogger logger, RESTMockOptions restMockOptions); static void enableLogging(RESTMockLogger logger); static void disableLogging(); @Deprecated static void removeAllMatchableCalls(); static void reset(); static boolean removeMatchableCall(MatchableCall call); static void replaceMatchableCall(MatchableCall call, MatchableCall replacement); static String getUrl(); static void addMatchableCall(final MatchableCall call); static MatchableCall whenGET(Matcher<RecordedRequest> requestMatcher); static MatchableCall whenPOST(Matcher<RecordedRequest> requestMatcher); static MatchableCall whenPUT(Matcher<RecordedRequest> requestMatcher); static MatchableCall whenPATCH(Matcher<RecordedRequest> requestMatcher); static MatchableCall whenDELETE(Matcher<RecordedRequest> requestMatcher); static MatchableCall whenHEAD(Matcher<RecordedRequest> requestMatcher); static MatchableCall whenRequested(Matcher<RecordedRequest> requestMatcher); static void shutdown(); static final String RESPONSE_NOT_MOCKED; static final String MORE_THAN_ONE_RESPONSE_ERROR; }