<commit_before>package com.clouway.friendlyserve.testing;

import com.clouway.friendlyserve.Request;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map;

public class FakeRequest implements Request {

  private final Map<String, String> params;
  private final Map<String, String> headers;
  private final byte[] body;
  private final String path;

  public FakeRequest(String path, Map<String, String> params, Map<String, String> headers, byte[] content) {
    this.path = path;
    this.params = ImmutableMap.copyOf(params);
    this.body = Arrays.copyOf(content, content.length);
    this.headers = ImmutableMap.copyOf(headers);
  }

  public FakeRequest(Map<String, String> params, Map<String, String> headers) {
    this("/", params, headers, new byte[]{});
  }

  public FakeRequest(String path, Map<String, String> params, byte[] content) {
    this(path, params, new LinkedHashMap<String, String>(), content);
  }


  @Override
  public String path() {
    return path;
  }

  @Override
  public String param(String name) {
    return params.get(name);
  }

  @Override
  public Iterable<String> names() {
    return params.keySet();
  }

  @Override
  public Iterable<String> cookie(String name) {
    return Lists.newLinkedList();
  }

  @Override
  public String header(String name) {
    return headers.get(name);
  }

  @Override
  public InputStream body() {
    return new ByteArrayInputStream(body);
  }
}<commit_msg>testing: add builder for testing requests<commit_after>package com.clouway.friendlyserve.testing;

import com.clouway.friendlyserve.Cookie;
import com.clouway.friendlyserve.Request;
import com.google.common.collect.ImmutableMap;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class FakeRequest implements Request {

  public static Builder aNewRequest() {
    return new Builder();
  }

  public static class Builder {
    private String path = "/";
    private Map<String, String> params = new LinkedHashMap<>();
    private Map<String, String> headers = new LinkedHashMap<>();
    private List<Cookie> cookies = new LinkedList<>();
    private byte[] body = new byte[] {  };

    public Builder path(String path) {
      this.path = path;
      return this;
    }

    public Builder param(String key, String value) {
      params.put(key, value);
      return this;
    }

    public Builder params(Map<String, String> params) {
      this.params = params;
      return this;
    }

    public Builder header(String name, String value) {
      headers.put(name, value);
      return this;
    }

    public Builder headers(Map<String, String> headers) {
      this.headers = headers;
      return this;
    }

    public Builder cookie(Cookie cookie) {
      cookies.add(cookie);
      return this;
    }

    public Builder body(byte[] body) {
      this.body = body;
      return this;
    }

    public Request build() {
      return new FakeRequest(path, params, headers, cookies, body);
    }
  }

  private final String path;
  private final Map<String, String> params;
  private final Map<String, String> headers;
  private final List<Cookie> cookies;
  private final byte[] body;


  public FakeRequest(String path, Map<String, String> params, Map<String, String> headers, List<Cookie> cookies, byte[] content) {
    this.path = path;
    this.params = ImmutableMap.copyOf(params);
    this.headers = ImmutableMap.copyOf(headers);
    this.cookies = cookies;
    this.body = Arrays.copyOf(content, content.length);
  }

  public FakeRequest(String path, Map<String, String> params, Map<String, String> headers, byte[] content) {
    this(path, params, headers, Collections.<Cookie>emptyList(), content);
  }

  public FakeRequest(Map<String, String> params, Map<String, String> headers) {
    this("/", params, headers, new byte[]{});
  }

  public FakeRequest(String path, Map<String, String> params, byte[] content) {
    this(path, params, new LinkedHashMap<String, String>(), content);
  }


  @Override
  public String path() {
    return path;
  }

  @Override
  public String param(String name) {
    return params.get(name);
  }

  @Override
  public Iterable<String> names() {
    return params.keySet();
  }

  @Override
  public Iterable<String> cookie(String name) {
    List<String> values = new LinkedList<>();
    for (Cookie each : cookies) {
      if (each.name().equalsIgnoreCase(name)) {
        values.add(each.value());
      }
    }
    return values;
  }

  @Override
  public String header(String name) {
    return headers.get(name);
  }

  @Override
  public InputStream body() {
    return new ByteArrayInputStream(body);
  }
}
{'fraction_non_alphanumeric': 0.11639146194120016, 'fraction_numerical': 0.0, 'mean_word_length': 3.650749063670412, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 38, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '535060', 'n_tokens_mistral': 1484, 'n_tokens_neox': 1458, 'n_words': 407}