Browse Source

Parameterize

master
Gintas Grigelionis 7 years ago
parent
commit
0add853104
3 changed files with 162 additions and 157 deletions
  1. +111
    -111
      src/tests/junit/org/apache/tools/ant/taskdefs/DefaultExcludesTest.java
  2. +27
    -25
      src/tests/junit/org/apache/tools/ant/types/DescriptionTest.java
  3. +24
    -21
      src/tests/junit/org/apache/tools/ant/types/PolyTest.java

+ 111
- 111
src/tests/junit/org/apache/tools/ant/taskdefs/DefaultExcludesTest.java View File

@@ -24,15 +24,121 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import java.util.Arrays;
import java.util.Collection;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
*/
@RunWith(Parameterized.class)
public class DefaultExcludesTest {
@Parameterized.Parameters(name = "{0}")
public static Collection<Object[]> targets() {
return Arrays.asList(new Object[][]{
/* default */
{"test1", new String[]{
"**/*~",
"**/#*#",
"**/.#*",
"**/%*%",
"**/._*",
"**/CVS",
"**/CVS/**",
"**/.cvsignore",
"**/SCCS",
"**/SCCS/**",
"**/vssver.scc",
"**/.svn",
"**/.svn/**",
"**/.git",
"**/.git/**",
"**/.gitattributes",
"**/.gitignore",
"**/.gitmodules",
"**/.hg",
"**/.hg/**",
"**/.hgignore",
"**/.hgsub",
"**/.hgsubstate",
"**/.hgtags",
"**/.bzr",
"**/.bzr/**",
"**/.bzrignore",
"**/.DS_Store"}},
/* add */
{"test2", new String[]{
"**/*~",
"**/#*#",
"**/.#*",
"**/%*%",
"**/._*",
"**/CVS",
"**/CVS/**",
"**/.cvsignore",
"**/SCCS",
"**/SCCS/**",
"**/vssver.scc",
"**/.svn",
"**/.svn/**",
"**/.git",
"**/.git/**",
"**/.gitattributes",
"**/.gitignore",
"**/.gitmodules",
"**/.hg",
"**/.hg/**",
"**/.hgignore",
"**/.hgsub",
"**/.hgsubstate",
"**/.hgtags",
"**/.bzr",
"**/.bzr/**",
"**/.bzrignore",
"**/.DS_Store",
"foo"}},
/* subtract */
{"test3", new String[]{
"**/*~",
"**/#*#",
"**/.#*",
"**/%*%",
"**/._*",
//CVS missing
"**/CVS/**",
"**/.cvsignore",
"**/SCCS",
"**/SCCS/**",
"**/vssver.scc",
"**/.svn",
"**/.svn/**",
"**/.git",
"**/.git/**",
"**/.gitattributes",
"**/.gitignore",
"**/.gitmodules",
"**/.hg",
"**/.hg/**",
"**/.hgignore",
"**/.hgsub",
"**/.hgsubstate",
"**/.hgtags",
"**/.bzr",
"**/.bzr/**",
"**/.bzrignore",
"**/.DS_Store"}}
});
}

@Parameterized.Parameter
public String targetName;

@Parameterized.Parameter(1)
public String[] expected;

@Rule
public final BuildFileRule buildRule = new BuildFileRule();
@@ -47,120 +153,14 @@ public class DefaultExcludesTest {
buildRule.executeTarget("cleanup");
}

// Output the default excludes
@Test
public void test1() {
String[] expected = {
"**/*~",
"**/#*#",
"**/.#*",
"**/%*%",
"**/._*",
"**/CVS",
"**/CVS/**",
"**/.cvsignore",
"**/SCCS",
"**/SCCS/**",
"**/vssver.scc",
"**/.svn",
"**/.svn/**",
"**/.git",
"**/.git/**",
"**/.gitattributes",
"**/.gitignore",
"**/.gitmodules",
"**/.hg",
"**/.hg/**",
"**/.hgignore",
"**/.hgsub",
"**/.hgsubstate",
"**/.hgtags",
"**/.bzr",
"**/.bzr/**",
"**/.bzrignore",
"**/.DS_Store"};
buildRule.getProject().executeTarget("test1");
assertArrayContentsEquals("current default excludes", expected, DirectoryScanner.getDefaultExcludes());
}

// adding something to the excludes'
@Test
public void test2() {
String[] expected = {
"**/*~",
"**/#*#",
"**/.#*",
"**/%*%",
"**/._*",
"**/CVS",
"**/CVS/**",
"**/.cvsignore",
"**/SCCS",
"**/SCCS/**",
"**/vssver.scc",
"**/.svn",
"**/.svn/**",
"**/.git",
"**/.git/**",
"**/.gitattributes",
"**/.gitignore",
"**/.gitmodules",
"**/.hg",
"**/.hg/**",
"**/.hgignore",
"**/.hgsub",
"**/.hgsubstate",
"**/.hgtags",
"**/.bzr",
"**/.bzr/**",
"**/.bzrignore",
"**/.DS_Store",
"foo"};
buildRule.executeTarget("test2");
assertArrayContentsEquals("current default excludes", expected, DirectoryScanner.getDefaultExcludes());
}

// removing something from the defaults
@Test
public void test3() {
String[] expected = {
"**/*~",
"**/#*#",
"**/.#*",
"**/%*%",
"**/._*",
//CVS missing
"**/CVS/**",
"**/.cvsignore",
"**/SCCS",
"**/SCCS/**",
"**/vssver.scc",
"**/.svn",
"**/.svn/**",
"**/.git",
"**/.git/**",
"**/.gitattributes",
"**/.gitignore",
"**/.gitmodules",
"**/.hg",
"**/.hg/**",
"**/.hgignore",
"**/.hgsub",
"**/.hgsubstate",
"**/.hgtags",
"**/.bzr",
"**/.bzr/**",
"**/.bzrignore",
"**/.DS_Store"};
buildRule.executeTarget("test3");
assertArrayContentsEquals("current default excludes", expected, DirectoryScanner.getDefaultExcludes());
}

private void assertArrayContentsEquals(String message, String[] expected, String[] actual) {
public void test() {
buildRule.getProject().executeTarget(targetName);
String[] actual = DirectoryScanner.getDefaultExcludes();
// check that both arrays have the same size
assertEquals(message + " : string array length match", expected.length, actual.length);
assertEquals("current default excludes: string array length match", expected.length, actual.length);
for (String element : expected) {
assertTrue(message + " : didn't find element " + element + " in array match",
assertTrue("current default excludes: didn't find element " + element + " in array match",
Arrays.stream(actual).anyMatch(member -> member.equals(element)));
}
}


+ 27
- 25
src/tests/junit/org/apache/tools/ant/types/DescriptionTest.java View File

@@ -21,43 +21,45 @@ package org.apache.tools.ant.types;
import org.apache.tools.ant.BuildFileRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import java.util.Arrays;
import java.util.Collection;

import static org.junit.Assert.assertEquals;

/**
* FilterSet testing
*
* Description tests
*/
@RunWith(Parameterized.class)
public class DescriptionTest {
@Parameterized.Parameters(name = "{1}")
public static Collection<Object[]> targets() {
return Arrays.asList(new Object[][]{
{"description1", "Single", "Test Project Description"},
{"description2", "Multi line", "Multi Line\nProject Description"},
{"description3", "Multi instance", "Multi Instance Project Description"},
{"description4", "Multi instance nested", "Multi Instance Nested Project Description"}
});
}

@Rule
public BuildFileRule buildRule = new BuildFileRule();
@Parameterized.Parameter
public String fileName;

@Test
public void test1() {
buildRule.configureProject("src/etc/testcases/types/description1.xml");
assertEquals("Single description failed", "Test Project Description",
buildRule.getProject().getDescription());
}
@Parameterized.Parameter(1)
public String description;

@Test
public void test2() {
buildRule.configureProject("src/etc/testcases/types/description2.xml");
assertEquals("Multi line description failed", "Multi Line\nProject Description",
buildRule.getProject().getDescription());
}
@Parameterized.Parameter(2)
public String outcome;

@Test
public void test3() {
buildRule.configureProject("src/etc/testcases/types/description3.xml");
assertEquals("Multi instance description failed", "Multi Instance Project Description",
buildRule.getProject().getDescription());
}
@Rule
public BuildFileRule buildRule = new BuildFileRule();

@Test
public void test4() {
buildRule.configureProject("src/etc/testcases/types/description4.xml");
assertEquals("Multi instance nested description failed", "Multi Instance Nested Project Description",
public void test() {
buildRule.configureProject("src/etc/testcases/types/" + fileName + ".xml");
assertEquals(description + " description failed", outcome,
buildRule.getProject().getDescription());
}
}

+ 24
- 21
src/tests/junit/org/apache/tools/ant/types/PolyTest.java View File

@@ -24,11 +24,32 @@ import org.apache.tools.ant.Task;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import java.util.Arrays;
import java.util.Collection;

import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertThat;

@RunWith(Parameterized.class)
public class PolyTest {
@Parameterized.Parameters(name = "{0}")
public static Collection<Object[]> targets() {
return Arrays.asList(new Object[][]{
{"fileset", "types.FileSet"},
{"fileset-ant-type", "types.PolyTest$MyFileSet"},
{"path", "types.Path"},
{"path-ant-type", "types.PolyTest$MyPath"}
});
}

@Parameterized.Parameter
public String targetName;

@Parameterized.Parameter(1)
public String outcome;

@Rule
public BuildFileRule buildRule = new BuildFileRule();
@@ -39,27 +60,9 @@ public class PolyTest {
}

@Test
public void testFileSet() {
buildRule.executeTarget("fileset");
assertThat(buildRule.getLog(), containsString("types.FileSet"));
}

@Test
public void testFileSetAntType() {
buildRule.executeTarget("fileset-ant-type");
assertThat(buildRule.getLog(), containsString("types.PolyTest$MyFileSet"));
}

@Test
public void testPath() {
buildRule.executeTarget("path");
assertThat(buildRule.getLog(), containsString("types.Path"));
}

@Test
public void testPathAntType() {
buildRule.executeTarget("path-ant-type");
assertThat(buildRule.getLog(), containsString("types.PolyTest$MyPath"));
public void test() {
buildRule.executeTarget(targetName);
assertThat(buildRule.getLog(), containsString(outcome));
}

public static class MyFileSet extends FileSet {


Loading…
Cancel
Save