// Path: core/src/test/java/io/appflate/restmock/utils/TestUtils.java
// public class TestUtils {
// 
//     private static final RequestBody EMPTY_JSON_BODY = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), "");
//     private static OkHttpClient okHttpClient =
//             new OkHttpClient.Builder()
//                     .sslSocketFactory(RESTMockServer.getSSLSocketFactory(), RESTMockServer.getTrustManager())
//                     .protocols(Collections.singletonList(Protocol.HTTP_1_1))
//                     .build();
// 
//     public static Response get(String path) throws IOException {
//         path = normalizePath(path);
//         return executeSync(requestBuilder().url(RESTMockServer.getUrl() + path).build());
//     }
// 
//     public static Response get(String path, Map.Entry<String, String>... headers) throws IOException {
//         path = normalizePath(path);
//         Request.Builder builder = new Request.Builder().url(RESTMockServer.getUrl() + path);
//         for (Map.Entry<String, String> entry : headers) {
//             builder.addHeader(entry.getKey(), entry.getValue());
//         }
//         return executeSync(builder.build());
//     }
// 
//     public static Response post(String path) throws IOException {
//         path = normalizePath(path);
//         return executeSync(requestBuilder().url(RESTMockServer.getUrl() + path).method("POST", EMPTY_JSON_BODY).build());
//     }
// 
//     public static Response put(String path) throws IOException {
//         path = normalizePath(path);
//         return executeSync(requestBuilder().url(RESTMockServer.getUrl() + path).method("PUT", EMPTY_JSON_BODY).build());
//     }
// 
//     public static Response delete(String path) throws IOException {
//         path = normalizePath(path);
//         return executeSync(requestBuilder().url(RESTMockServer.getUrl() + path).method("DELETE", null).build());
//     }
// 
//     public static Response head(String path) throws IOException {
//         path = normalizePath(path);
//         return executeSync(requestBuilder().url(RESTMockServer.getUrl() + path).method("HEAD", null).build());
//     }
// 
//     private static Response executeSync(Request request) throws IOException {
//         return okHttpClient.newCall(request).execute();
//     }
// 
//     public static void assertNotMocked(Response response) throws IOException {
//         assertResponseWithBodyContains(response, 500, RESTMockServer.RESPONSE_NOT_MOCKED);
//     }
// 
//     public static void assertNotMockedNoBody(Response response) throws IOException {
//         assertResponseCodeIs(response, 500);
//     }
// 
//     public static void assertMultipleMatches(Response response) throws IOException {
//         assertResponseWithBodyContains(response, 500, RESTMockServer.MORE_THAN_ONE_RESPONSE_ERROR);
//     }
// 
//     public static void assertResponseCodeIs(Response response, int code) {
//         assertEquals(code, response.code());
//     }
// 
//     public static void assertResponseWithBodyContains(Response response, int code, String body) throws IOException {
//         assertEquals(code, response.code());
//         assertTrue(response.body().string().contains(body));
//     }
// 
//     private static String normalizePath(String path) {
//         if (path.startsWith("/")) {
//             path = "/" + path;
//         }
//         return path;
//     }
// 
//     private static Request.Builder requestBuilder() {
//         return new Request.Builder().addHeader("Connection", "close");
//     }
// }
// 
// Path: core/src/main/java/io/appflate/restmock/utils/RequestMatchers.java
// public static RequestMatcher pathEndsWith(final String urlPart) {
//     return new RequestMatcher("path ends with: " + urlPart) {
// 
//         @Override
//         protected boolean matchesSafely(RecordedRequest item) {
//             String urlPartWithoutEndingSlash = urlPart.replaceAll("/$", "");
//             String itemPathWithoutEndingSlash = item.getPath().replaceAll("/$", "");
//             return itemPathWithoutEndingSlash.toLowerCase(Locale.US).endsWith(urlPartWithoutEndingSlash.toLowerCase(Locale.US));
//         }
//     };
// }


import io.appflate.restmock.utils.TestUtils;
import java.io.IOException;
import java.util.AbstractMap;
import java.util.Arrays;
import java.util.Collection;
import okhttp3.Response;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.RecordedRequest;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import static io.appflate.restmock.utils.RequestMatchers.pathEndsWith;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertNotNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
    public static Collection<Object> data() {
        return Arrays.asList(new Object[] {
            true, false
        });
    }

    public RESTMockServerTest(boolean useHttps) {
        this.useHttps = useHttps;
    }

    @Before
    public void setup() {
        fileParser = mock(RESTMockFileParser.class);
        RESTMockServerStarter.startSync(fileParser, new RESTMockOptions.Builder().useHttps(useHttps).build());
        RESTMockServer.dispatcher = spy(RESTMockServer.dispatcher);
    }

    @After
    public void teardown() throws IOException {
        RESTMockServer.shutdown();
    }

    @Test
    public void testWhenGET() throws Exception {
        String path = "/sample";
        String worksBody = "works";
        MatchableCall matchableCall = RESTMockServer.whenGET(pathEndsWith(path));
        assertNotNull(matchableCall);
        assertEquals(0, matchableCall.getNumberOfAnswers());
        verify(RESTMockServer.dispatcher, never()).addMatchableCall(matchableCall);
// Path: core/src/test/java/io/appflate/restmock/utils/TestUtils.java
// public class TestUtils {
// 
//     private static final RequestBody EMPTY_JSON_BODY = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), "");
//     private static OkHttpClient okHttpClient =
//             new OkHttpClient.Builder()
//                     .sslSocketFactory(RESTMockServer.getSSLSocketFactory(), RESTMockServer.getTrustManager())
//                     .protocols(Collections.singletonList(Protocol.HTTP_1_1))
//                     .build();
// 
//     public static Response get(String path) throws IOException {
//         path = normalizePath(path);
//         return executeSync(requestBuilder().url(RESTMockServer.getUrl() + path).build());
//     }
// 
//     public static Response get(String path, Map.Entry<String, String>... headers) throws IOException {
//         path = normalizePath(path);
//         Request.Builder builder = new Request.Builder().url(RESTMockServer.getUrl() + path);
//         for (Map.Entry<String, String> entry : headers) {
//             builder.addHeader(entry.getKey(), entry.getValue());
//         }
//         return executeSync(builder.build());
//     }
// 
//     public static Response post(String path) throws IOException {
//         path = normalizePath(path);
//         return executeSync(requestBuilder().url(RESTMockServer.getUrl() + path).method("POST", EMPTY_JSON_BODY).build());
//     }
// 
//     public static Response put(String path) throws IOException {
//         path = normalizePath(path);
//         return executeSync(requestBuilder().url(RESTMockServer.getUrl() + path).method("PUT", EMPTY_JSON_BODY).build());
//     }
// 
//     public static Response delete(String path) throws IOException {
//         path = normalizePath(path);
//         return executeSync(requestBuilder().url(RESTMockServer.getUrl() + path).method("DELETE", null).build());
//     }
// 
//     public static Response head(String path) throws IOException {
//         path = normalizePath(path);
//         return executeSync(requestBuilder().url(RESTMockServer.getUrl() + path).method("HEAD", null).build());
//     }
// 
//     private static Response executeSync(Request request) throws IOException {
//         return okHttpClient.newCall(request).execute();
//     }
// 
//     public static void assertNotMocked(Response response) throws IOException {
//         assertResponseWithBodyContains(response, 500, RESTMockServer.RESPONSE_NOT_MOCKED);
//     }
// 
//     public static void assertNotMockedNoBody(Response response) throws IOException {
//         assertResponseCodeIs(response, 500);
//     }
// 
//     public static void assertMultipleMatches(Response response) throws IOException {
//         assertResponseWithBodyContains(response, 500, RESTMockServer.MORE_THAN_ONE_RESPONSE_ERROR);
//     }
// 
//     public static void assertResponseCodeIs(Response response, int code) {
//         assertEquals(code, response.code());
//     }
// 
//     public static void assertResponseWithBodyContains(Response response, int code, String body) throws IOException {
//         assertEquals(code, response.code());
//         assertTrue(response.body().string().contains(body));
//     }
// 
//     private static String normalizePath(String path) {
//         if (path.startsWith("/")) {
//             path = "/" + path;
//         }
//         return path;
//     }
// 
//     private static Request.Builder requestBuilder() {
//         return new Request.Builder().addHeader("Connection", "close");
//     }
// }
// 
// Path: core/src/main/java/io/appflate/restmock/utils/RequestMatchers.java
// public static RequestMatcher pathEndsWith(final String urlPart) {
//     return new RequestMatcher("path ends with: " + urlPart) {
// 
//         @Override
//         protected boolean matchesSafely(RecordedRequest item) {
//             String urlPartWithoutEndingSlash = urlPart.replaceAll("/$", "");
//             String itemPathWithoutEndingSlash = item.getPath().replaceAll("/$", "");
//             return itemPathWithoutEndingSlash.toLowerCase(Locale.US).endsWith(urlPartWithoutEndingSlash.toLowerCase(Locale.US));
//         }
//     };
// }


// Path: core/src/test/java/io/appflate/restmock/RESTMockServerTest.java
import io.appflate.restmock.utils.TestUtils;
import java.io.IOException;
import java.util.AbstractMap;
import java.util.Arrays;
import java.util.Collection;
import okhttp3.Response;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.RecordedRequest;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import static io.appflate.restmock.utils.RequestMatchers.pathEndsWith;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertNotNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;

    public static Collection<Object> data() {
        return Arrays.asList(new Object[] {
            true, false
        });
    }

    public RESTMockServerTest(boolean useHttps) {
        this.useHttps = useHttps;
    }

    @Before
    public void setup() {
        fileParser = mock(RESTMockFileParser.class);
        RESTMockServerStarter.startSync(fileParser, new RESTMockOptions.Builder().useHttps(useHttps).build());
        RESTMockServer.dispatcher = spy(RESTMockServer.dispatcher);
    }

    @After
    public void teardown() throws IOException {
        RESTMockServer.shutdown();
    }

    @Test
    public void testWhenGET() throws Exception {
        String path = "/sample";
        String worksBody = "works";
        MatchableCall matchableCall = RESTMockServer.whenGET(pathEndsWith(path));
        assertNotNull(matchableCall);
        assertEquals(0, matchableCall.getNumberOfAnswers());
        verify(RESTMockServer.dispatcher, never()).addMatchableCall(matchableCall);
        TestUtils.assertNotMocked(TestUtils.get(path));