<commit_before>package com.maestrano.testhelpers;

import java.util.Map;

import com.google.gson.Gson;
import com.maestrano.net.MnoHttpClient;

public class MnoHttpClientStub extends MnoHttpClient {
	private String responseStub;
	
	public String get(String url) {
		return this.responseStub;
	}

	public String getResponseStub() {
		return responseStub;
	}

	public void setResponseStub(String responseStub) {
		this.responseStub = responseStub;
	}
	
	public void setResponseStub(Map<String,String> responseStub) {
		Gson gson = new Gson();
		this.responseStub = gson.toJson(responseStub);
	}
}
<commit_msg>customizable response stubs<commit_after>package com.maestrano.testhelpers;

import java.io.IOException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

import com.google.gson.Gson;
import com.maestrano.net.MnoHttpClient;

public class MnoHttpClientStub extends MnoHttpClient {
	private String defaultResponseStub;
	private Map<String,String> responseStubs;
	
	public MnoHttpClientStub() {
		responseStubs = new HashMap<String,String>();
		defaultResponseStub = null;
	}
	
	public String get(String url) {
		return get(url,null);
	}
	
	public String get(String url, Map<String,String> params) {
		String keyStr = url;
		String paramsStr = stringifyHash(params);
		
		if (paramsStr != null) {
			keyStr += "?" + paramsStr;
		}
		
		if (this.responseStubs.get(keyStr) != null) {
			return this.responseStubs.get(keyStr);
		}
		
		return this.defaultResponseStub;
	}

	public String getResponseStub() {
		return defaultResponseStub;
	}

	public void setResponseStub(String responseStub) {
		this.defaultResponseStub = responseStub;
	}
	
	public void setResponseStub(String responseStub, String url) {
		setResponseStub(responseStub,url,null);
	}
	
	public void setResponseStub(String responseStub, String url, Map<String,String> params) {
		String keyStr = url;
		String paramsStr = stringifyHash(params);
		
		if (paramsStr != null) {
			keyStr += "?" + paramsStr;
		}
		
		this.responseStubs.put(keyStr, responseStub);
	}
	
	public void setResponseStub(Map<String,String> responseStub) {
		Gson gson = new Gson();
		this.defaultResponseStub = gson.toJson(responseStub);
	}
	
	private String stringifyHash(Map<String,String> hash) {
		if (hash == null || hash.isEmpty()) return null;
		
		String stringified = "";
		for (Map.Entry<String, String> param : hash.entrySet())
		{
			String key = param.getKey();
			String val = param.getValue();
			stringified += "&" + key + "=" + val;
		}
		
		return stringified;
	}
}

{'fraction_non_alphanumeric': 0.11054488435907488, 'fraction_numerical': 0.0, 'mean_word_length': 4.547826086956522, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '6438967', 'n_tokens_mistral': 892, 'n_tokens_neox': 844, 'n_words': 184}