package com.github.keub.maven.plugin.service;

import java.util.HashSet;
import java.util.Set;

import org.junit.Assert;
import org.junit.Test;

import com.github.keub.maven.plugin.resources.CopyResourcesMojo;

public class IncludeServiceTest {

	@Test
	public void process_with_empty_include_set_do_nothing() {
		Set<String> includes = null;
		Set<String> files = new HashSet<String>();
		String file = "foo.txt";
		files.add(file);

		Set<String> retval = IncludeService.process(new CopyResourcesMojo(),
				includes, files);
		Assert.assertNotNull(retval);
		Assert.assertEquals(files.size(), retval.size());
		Assert.assertTrue(retval.contains(file));
	}

	@Test
	public void process_with_empty_file_set_do_nothing() {
		Set<String> includes = null;
		Set<String> files = new HashSet<String>();

		Set<String> retval = IncludeService.process(new CopyResourcesMojo(),
				includes, files);
		Assert.assertNotNull(retval);
		Assert.assertEquals(files.size(), retval.size());
	}

	@Test
	public void process_with_includes_and_empty_files_set() {
		Set<String> includes = new HashSet<String>();
		includes.add("**/foo.txt");
		Set<String> files = new HashSet<String>();

		Set<String> retval = IncludeService.process(new CopyResourcesMojo(),
				includes, files);
		Assert.assertNotNull(retval);
		Assert.assertEquals(files.size(), retval.size());
	}

	@Test
	public void process_with_includes_and_files() {
		Set<String> includes = new HashSet<String>();
		includes.add("**/foo.txt");
		Set<String> files = new HashSet<String>();
		String file1 = "foo.txt";
		files.add(file1);
		String file2 = "toto/foo.txt";
		files.add(file2);
		String file3 = "bar.txt";
		files.add(file3);

		Set<String> retval = IncludeService.process(new CopyResourcesMojo(),
				includes, files);
		Assert.assertNotNull(retval);
		Assert.assertEquals(2, retval.size());
		Assert.assertTrue(retval.contains(file1));
		Assert.assertTrue(retval.contains(file2));
	}
}

@@ -1933,10 +1933,891 @@
 2));%0A%09%7D%0A
+%0A%09@Test%0A%09public void process_with_invalid_includes_and_unix_path() %7B%0A%09%09Set%3CString%3E includes = new HashSet%3CString%3E();%0A%09%09includes.add(%22**/foo.txt%22);%0A%09%09Set%3CString%3E files = new HashSet%3CString%3E();%0A%09%09String file1 = %22/root/foo.txt%22;%0A%09%09files.add(file1);%0A%0A%09%09Set%3CString%3E retval = IncludeService.process(new CopyResourcesMojo(),%0A%09%09%09%09includes, files);%0A%0A%09%09Assert.assertNotNull(retval);%0A%09%09Assert.assertEquals(0, retval.size());%0A%0A%09%7D%0A%0A%09@Test%0A%09public void process_with_valid_includes_and_unix_path() %7B%0A%09%09Set%3CString%3E includes = new HashSet%3CString%3E();%0A%09%09includes.add(%22/**/foo.txt%22);%0A%09%09Set%3CString%3E files = new HashSet%3CString%3E();%0A%09%09String file1 = %22/root/foo.txt%22;%0A%09%09files.add(file1);%0A%0A%09%09Set%3CString%3E retval = IncludeService.process(new CopyResourcesMojo(),%0A%09%09%09%09includes, files);%0A%0A%09%09Assert.assertNotNull(retval);%0A%09%09Assert.assertEquals(1, retval.size());%0A%09%09Assert.assertTrue(retval.contains(file1));%0A%0A%09%7D%0A%0A
 %7D%0A

add junit test - understand ant pattern with unix path starting with slashes