| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
package net.sf.antcontrib.logic; |
| 17 |
|
| 18 |
import org.apache.tools.ant.BuildFileTest; |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
public class ForeachTaskTest extends BuildFileTest { |
| 24 |
|
| 25 |
public ForeachTaskTest(String name) { |
| 26 |
super(name); |
| 27 |
} |
| 28 |
|
| 29 |
public void setUp() { |
| 30 |
configureProject("test/resources/logic/foreach.xml"); |
| 31 |
} |
| 32 |
|
| 33 |
public void tearDown() { |
| 34 |
executeTarget("teardown"); |
| 35 |
} |
| 36 |
|
| 37 |
public void testSimpleList() { |
| 38 |
simpleTest("simpleList"); |
| 39 |
} |
| 40 |
|
| 41 |
public void testDelimiter() { |
| 42 |
simpleTest("delimiter"); |
| 43 |
} |
| 44 |
|
| 45 |
public void testFileset() { |
| 46 |
simpleTest("fileset"); |
| 47 |
assertTrue(getLog().indexOf("The nested fileset element is deprectated," |
| 48 |
+ " use a nested path instead") > -1); |
| 49 |
} |
| 50 |
|
| 51 |
public void testFilesetAndList() { |
| 52 |
simpleTest("filesetAndList"); |
| 53 |
assertTrue(getLog().indexOf("The nested fileset element is deprectated," |
| 54 |
+ " use a nested path instead") > -1); |
| 55 |
} |
| 56 |
|
| 57 |
public void testNoList() { |
| 58 |
expectSpecificBuildException("noList", "neither list nor fileset", |
| 59 |
"You must have a list or path to iterate through"); |
| 60 |
} |
| 61 |
|
| 62 |
public void testNoTarget() { |
| 63 |
expectSpecificBuildException("noTarget", "no target", |
| 64 |
"You must supply a target to perform"); |
| 65 |
} |
| 66 |
|
| 67 |
public void testNoParam() { |
| 68 |
expectSpecificBuildException("noParam", "no param", |
| 69 |
"You must supply a property name to set on each iteration in param"); |
| 70 |
} |
| 71 |
|
| 72 |
public void testNestedParam() { |
| 73 |
executeTarget("nestedParam"); |
| 74 |
assertTrue(getLog().indexOf("Called with param: rincewind") > -1); |
| 75 |
} |
| 76 |
|
| 77 |
public void testNestedReference() { |
| 78 |
executeTarget("nestedReference"); |
| 79 |
assertTrue(getLog().indexOf("Called with param: twoflower") > -1); |
| 80 |
} |
| 81 |
|
| 82 |
public void testPath() { |
| 83 |
simpleTest("path"); |
| 84 |
} |
| 85 |
|
| 86 |
public void testPathAndList() { |
| 87 |
simpleTest("pathAndList"); |
| 88 |
} |
| 89 |
|
| 90 |
private void simpleTest(String target) { |
| 91 |
executeTarget(target); |
| 92 |
int last = -1; |
| 93 |
for (int i = 1; i < 4; i++) { |
| 94 |
int thisIdx = getLog().indexOf("Called with param: " + i); |
| 95 |
assertTrue(thisIdx > last); |
| 96 |
last = thisIdx; |
| 97 |
} |
| 98 |
} |
| 99 |
} |