<commit_before>package net.sf.iwant.api;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URL;
import java.util.LinkedHashMap;
import java.util.Map;

import junit.framework.TestCase;
import net.sf.iwant.entry.Iwant;
import net.sf.iwant.entry3.CachesMock;
import net.sf.iwant.entry3.IwantEntry3TestArea;

public class DownloadedTest extends TestCase {

	private IwantEntry3TestArea testArea;
	private CachesMock caches;
	private File wsRoot;
	private IwantMock iwantMock;
	private TargetEvaluationContextMock ctx;
	private File cached;

	@Override
	public void setUp() {
		testArea = new IwantEntry3TestArea();
		wsRoot = testArea.newDir("wsroot");
		caches = new CachesMock(wsRoot);
		iwantMock = new IwantMock();
		ctx = new TargetEvaluationContextMock(iwantMock, caches);
		cached = new File(testArea.root(), "cachedDownload");
	}

	public void testThereAreNowIngredients() {
		assertTrue(Downloaded.withName("any").url("http://localhost/any")
				.md5("any").ingredients().isEmpty());
	}

	public void testContentDescriptor() {
		assertEquals(
				"net.sf.iwant.api.Downloaded {\n  url:http://localhost/url1\n}\n",
				Downloaded.withName("any").url("http://localhost/url1")
						.md5("any").contentDescriptor());
		assertEquals(
				"net.sf.iwant.api.Downloaded {\n  url:http://localhost/url2\n}\n",
				Downloaded.withName("any").url("http://localhost/url2")
						.md5("any").contentDescriptor());
	}

	public void testDownloadSucceedsWithoutDigestCheck() throws Exception {
		URL url = Iwant.url("http://localhost");
		caches.cachesUrlAt(url, cached);
		iwantMock.shallDownloadContent(url, "valid content");

		Downloaded target = Downloaded.withName("any").url(url).noCheck();
		target.path(ctx);

		assertEquals("{http://localhost=" + cached + "}",
				iwantMock.executedDownloads.toString());
		assertEquals("valid content", testArea.contentOf(cached));
	}

	public void testDownloadSucceedsWithCorrectMd5() throws Exception {<commit_msg>fixed typo in test name<commit_after>package net.sf.iwant.api;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URL;
import java.util.LinkedHashMap;
import java.util.Map;

import junit.framework.TestCase;
import net.sf.iwant.entry.Iwant;
import net.sf.iwant.entry3.CachesMock;
import net.sf.iwant.entry3.IwantEntry3TestArea;

public class DownloadedTest extends TestCase {

	private IwantEntry3TestArea testArea;
	private CachesMock caches;
	private File wsRoot;
	private IwantMock iwantMock;
	private TargetEvaluationContextMock ctx;
	private File cached;

	@Override
	public void setUp() {
		testArea = new IwantEntry3TestArea();
		wsRoot = testArea.newDir("wsroot");
		caches = new CachesMock(wsRoot);
		iwantMock = new IwantMock();
		ctx = new TargetEvaluationContextMock(iwantMock, caches);
		cached = new File(testArea.root(), "cachedDownload");
	}

	public void testThereAreNoIngredients() {
		assertTrue(Downloaded.withName("any").url("http://localhost/any")
				.md5("any").ingredients().isEmpty());
	}

	public void testContentDescriptor() {
		assertEquals(
				"net.sf.iwant.api.Downloaded {\n  url:http://localhost/url1\n}\n",
				Downloaded.withName("any").url("http://localhost/url1")
						.md5("any").contentDescriptor());
		assertEquals(
				"net.sf.iwant.api.Downloaded {\n  url:http://localhost/url2\n}\n",
				Downloaded.withName("any").url("http://localhost/url2")
						.md5("any").contentDescriptor());
	}

	public void testDownloadSucceedsWithoutDigestCheck() throws Exception {
		URL url = Iwant.url("http://localhost");
		caches.cachesUrlAt(url, cached);
		iwantMock.shallDownloadContent(url, "valid content");

		Downloaded target = Downloaded.withName("any").url(url).noCheck();
		target.path(ctx);

		assertEquals("{http://localhost=" + cached + "}",
				iwantMock.executedDownloads.toString());
		assertEquals("valid content", testArea.contentOf(cached));
	}

	public void testDownloadSucceedsWithCorrectMd5() throws Exception {
{'fraction_non_alphanumeric': 0.14217772215269087, 'fraction_numerical': 0.006508135168961202, 'mean_word_length': 5.195348837209302, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1373613', 'n_tokens_mistral': 1390, 'n_tokens_neox': 1279, 'n_words': 236}