<commit_before>/*
 * Copyright (C) 2016 Appflate.io
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.appflate.restmock.utils;

import java.util.Locale;

import okhttp3.mockwebserver.RecordedRequest;

public class RequestMatchers {
    private RequestMatchers() {
        throw new UnsupportedOperationException();
    }

    public static RequestMatcher pathContains(final String urlPart) {
        return new RequestMatcher("url contains: " + urlPart) {
            @Override
            protected boolean matchesSafely(RecordedRequest item) {
                return item.getPath().toLowerCase(Locale.US).contains(urlPart.toLowerCase(Locale.US));
            }
        };
    }

    public static RequestMatcher pathEndsWith(final String urlPart) {
        return new RequestMatcher("url ends with: " + urlPart) {
            @Override
            protected boolean matchesSafely(RecordedRequest item) {
                String urlPartWithoutEndingSlash =
                        urlPart.endsWith("/") ? urlPart.substring(0,
                                urlPart.length() - 1) : urlPart;
                String itemPathWithoutEndingSlash = item.getPath().endsWith("/") ? item.getPath()
                        .substring(0, item.getPath().length() - 1) : item.getPath();
                return itemPathWithoutEndingSlash.toLowerCase(Locale.US).endsWith(urlPartWithoutEndingSlash.toLowerCase(Locale.US));
            }
        };
    }

    public static RequestMatcher pathStartsWith(final String urlPart) {
        return new RequestMatcher("url starts with: " + urlPart) {
            @Override
            protected boolean matchesSafely(RecordedRequest item) {
                return item.getPath().toLowerCase(Locale.US).startsWith(urlPart.toLowerCase(Locale.US));
            }
        };
    }

    public static RequestMatcher httpMethodIs(final String method) {
        return new RequestMatcher("HTTP method is: " + method) {
            @Override
            protected boolean matchesSafely(final RecordedRequest item) {<commit_msg>Add a RequestMatcher for determining if a path does not contain a string.<commit_after>/*
 * Copyright (C) 2016 Appflate.io
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.appflate.restmock.utils;

import java.util.Locale;

import okhttp3.mockwebserver.RecordedRequest;

public class RequestMatchers {
    private RequestMatchers() {
        throw new UnsupportedOperationException();
    }

    public static RequestMatcher pathContains(final String urlPart) {
        return new RequestMatcher("url contains: " + urlPart) {
            @Override
            protected boolean matchesSafely(RecordedRequest item) {
                return item.getPath().toLowerCase(Locale.US).contains(urlPart.toLowerCase(Locale.US));
            }
        };
    }

    public static RequestMatcher pathDoesNotContain(final String urlPart) {
        return new RequestMatcher("url does not contain: " + urlPart) {
            @Override
            protected boolean matchesSafely(RecordedRequest item) {
                return !item.getPath().toLowerCase(Locale.US).contains(urlPart.toLowerCase(Locale.US));
            }
        };
    }

    public static RequestMatcher pathEndsWith(final String urlPart) {
        return new RequestMatcher("url ends with: " + urlPart) {
            @Override
            protected boolean matchesSafely(RecordedRequest item) {
                String urlPartWithoutEndingSlash =
                        urlPart.endsWith("/") ? urlPart.substring(0,
                                urlPart.length() - 1) : urlPart;
                String itemPathWithoutEndingSlash = item.getPath().endsWith("/") ? item.getPath()
                        .substring(0, item.getPath().length() - 1) : item.getPath();
                return itemPathWithoutEndingSlash.toLowerCase(Locale.US).endsWith(urlPartWithoutEndingSlash.toLowerCase(Locale.US));
            }
        };
    }

    public static RequestMatcher pathStartsWith(final String urlPart) {
        return new RequestMatcher("url starts with: " + urlPart) {
            @Override
            protected boolean matchesSafely(RecordedRequest item) {
                return item.getPath().toLowerCase(Locale.US).startsWith(urlPart.toLowerCase(Locale.US));
            }
        };
    }

    public static RequestMatcher httpMethodIs(final String method) {
        return new RequestMatcher("HTTP method is: " + method) {
            @Override
            protected boolean matchesSafely(final RecordedRequest item) {
{'fraction_non_alphanumeric': 0.08632447954055994, 'fraction_numerical': 0.00466618808327351, 'mean_word_length': 2.611795204147764, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7487637', 'n_tokens_mistral': 1406, 'n_tokens_neox': 1401, 'n_words': 404}