<commit_before>package com.github.dannil.httpdownloader.test.unittest;

import java.io.File;
import java.io.IOException;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.github.dannil.httpdownloader.handler.DownloadThreadHandler;
import com.github.dannil.httpdownloader.model.Download;
import com.github.dannil.httpdownloader.test.utility.TestUtility;
import com.github.dannil.httpdownloader.utility.FileUtility;

/**
 * Unit tests for download thread handler
 * 
 * @author      <NAME> (daniel.nilsson @ dannils.se)
 * @version     1.0.0
 * @since       1.0.0
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:/WEB-INF/configuration/framework/spring-context.xml")
public class DownloadThreadHandlerUnitTest {

	@Autowired
	private DownloadThreadHandler downloadThreadHandler;

	@Test
	public final void saveToDiskNotNullDownload() throws InterruptedException {
		final Download download = new Download(TestUtility.getDownload());

		this.downloadThreadHandler.saveToDisk(download);

		// Make sure the thread started by downloadThreadHandler finish
		// executing before asserting
		Thread.sleep(500);

		Assert.assertTrue(FileUtility.getFromDrive(download).exists());
	}

	@Test(expected = NullPointerException.class)
	public final void saveToDiskNullDownload() {
		this.downloadThreadHandler.saveToDisk(null);
	}

	@Test
	public final void saveToDiskInvalidUrl() {
		final Download download = new Download(TestUtility.getDownload());
		download.setUrl("blabla/blabla");

		this.downloadThreadHandler.saveToDisk(download);
	}

	@Test
	public final void deleteFromDiskNotNullDownload() throws IOException, InterruptedException {
		final Download download = new Download(TestUtility.getDownload());

		File file = FileUtility.getFileFromURL(download);<commit_msg>Fixed faulty test<commit_after>package com.github.dannil.httpdownloader.test.unittest;

import java.io.File;
import java.io.IOException;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.github.dannil.httpdownloader.handler.DownloadThreadHandler;
import com.github.dannil.httpdownloader.model.Download;
import com.github.dannil.httpdownloader.test.utility.TestUtility;
import com.github.dannil.httpdownloader.utility.FileUtility;

/**
 * Unit tests for download thread handler
 * 
 * @author      <NAME> (daniel.nilsson @ dann<EMAIL>)
 * @version     1.0.0
 * @since       1.0.0
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:/WEB-INF/configuration/framework/spring-context.xml")
public class DownloadThreadHandlerUnitTest {

	@Autowired
	private DownloadThreadHandler downloadThreadHandler;

	@Test
	public final void saveToDiskNotNullDownload() throws InterruptedException {
		final Download download = new Download(TestUtility.getDownload());

		this.downloadThreadHandler.saveToDisk(download);

		// Make sure the thread started by downloadThreadHandler finish
		// executing before asserting
		Thread.sleep(500);

		Assert.assertTrue(FileUtility.getFromDrive(download).exists());
	}

	@Test(expected = IllegalArgumentException.class)
	public final void saveToDiskNullDownload() {
		this.downloadThreadHandler.saveToDisk(null);
	}

	@Test
	public final void saveToDiskInvalidUrl() {
		final Download download = new Download(TestUtility.getDownload());
		download.setUrl("blabla/blabla");

		this.downloadThreadHandler.saveToDisk(download);
	}

	@Test
	public final void deleteFromDiskNotNullDownload() throws IOException, InterruptedException {
		final Download download = new Download(TestUtility.getDownload());

		File file = FileUtility.getFileFromURL(download);
{'fraction_non_alphanumeric': 0.09894426712496932, 'fraction_numerical': 0.0058924625583108275, 'mean_word_length': 5.928571428571429, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 70, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4632502', 'n_tokens_mistral': 1197, 'n_tokens_neox': 1155, 'n_words': 221}