You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by mc...@apache.org on 2014/04/18 23:00:43 UTC
svn commit: r1588563 [15/16] - in /ant/core/trunk: ./ manual/ manual/Types/
src/etc/testcases/taskdefs/ src/etc/testcases/taskdefs/optional/
src/etc/testcases/taskdefs/optional/antlr/
src/etc/testcases/taskdefs/optional/depend/ src/etc/testcases/taskde...
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/FilenameSelectorTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/FilenameSelectorTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/FilenameSelectorTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/FilenameSelectorTest.java Fri Apr 18 21:00:38 2014
@@ -20,45 +20,42 @@ package org.apache.tools.ant.types.selec
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.types.Parameter;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
/**
* Tests Filename Selectors
*
*/
-public class FilenameSelectorTest extends BaseSelectorTest {
+public class FilenameSelectorTest {
- public FilenameSelectorTest(String name) {
- super(name);
- }
-
- /**
- * Factory method from base class. This is overriden in child
- * classes to return a specific Selector class.
- */
- public BaseSelector getInstance() {
- return new FilenameSelector();
- }
+ @Rule
+ public final BaseSelectorRule selectorRule = new BaseSelectorRule();
/**
* Test the code that validates the selector.
*/
+ @Test
public void testValidate() {
- FilenameSelector s = (FilenameSelector)getInstance();
+ FilenameSelector s = new FilenameSelector();
try {
- s.isSelected(basedir,filenames[0],files[0]);
+ s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
fail("FilenameSelector did not check for required fields");
} catch (BuildException be1) {
assertEquals("The name or regex attribute is required", be1.getMessage());
}
- s = (FilenameSelector)getInstance();
+ s = new FilenameSelector();
Parameter param = new Parameter();
param.setName("garbage in");
param.setValue("garbage out");
Parameter[] params = {param};
s.setParameters(params);
try {
- s.isSelected(basedir,filenames[0],files[0]);
+ s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
fail("FilenameSelector did not check for valid parameter element");
} catch (BuildException be2) {
assertEquals("Invalid parameter garbage in", be2.getMessage());
@@ -69,21 +66,20 @@ public class FilenameSelectorTest extend
/**
* Tests to make sure that the selector is selecting files correctly.
*/
+ @Test
public void testSelectionBehaviour() {
FilenameSelector s;
String results;
- try {
- makeBed();
- s = (FilenameSelector)getInstance();
+ s = new FilenameSelector();
s.setName("no match possible");
- results = selectionString(s);
+ results = selectorRule.selectionString(s);
assertEquals("FFFFFFFFFFFF", results);
- s = (FilenameSelector)getInstance();
+ s = new FilenameSelector();
s.setName("*.gz");
- results = selectionString(s);
+ results = selectorRule.selectionString(s);
// This is turned off temporarily. There appears to be a bug
// in SelectorUtils.matchPattern() where it is recursive on
// Windows even if no ** is in pattern.
@@ -91,31 +87,28 @@ public class FilenameSelectorTest extend
// vs
//assertEquals("FFFTFFFFTFFF", results); // Windows
- s = (FilenameSelector)getInstance();
+ s = new FilenameSelector();
s.setName("**/*.gz");
s.setNegate(true);
- results = selectionString(s);
+ results = selectorRule.selectionString(s);
assertEquals("TTTFTTTFFTTT", results);
- s = (FilenameSelector)getInstance();
+ s = new FilenameSelector();
s.setName("**/*.GZ");
s.setCasesensitive(false);
- results = selectionString(s);
+ results = selectorRule.selectionString(s);
assertEquals("FFFTFFFTTFFF", results);
- s = (FilenameSelector)getInstance();
+ s = new FilenameSelector();
Parameter param1 = new Parameter();
param1.setName("name");
param1.setValue("**/*.bz2");
Parameter[] params = {param1};
s.setParameters(params);
- results = selectionString(s);
+ results = selectorRule.selectionString(s);
assertEquals("FFTFFFFFFTTF", results);
- }
- finally {
- cleanupBed();
- }
+
}
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java Fri Apr 18 21:00:38 2014
@@ -25,7 +25,9 @@ import java.text.RuleBasedCollator;
import java.util.Comparator;
import java.util.Iterator;
+import org.apache.tools.ant.AntAssert;
import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildFileRule;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Target;
import org.apache.tools.ant.Task;
@@ -40,6 +42,17 @@ import org.apache.tools.ant.types.select
import org.apache.tools.ant.types.selectors.modifiedselector.ModifiedSelector;
import org.apache.tools.ant.types.selectors.modifiedselector.PropertiesfileCache;
import org.apache.tools.ant.util.FileUtils;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
/**
@@ -47,7 +60,10 @@ import org.apache.tools.ant.util.FileUti
*
* @since Ant 1.6
*/
-public class ModifiedSelectorTest extends BaseSelectorTest {
+public class ModifiedSelectorTest {
+
+ @Rule
+ public final BaseSelectorRule selectorRule = new BaseSelectorRule();
/** Utilities used for file operations */
private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
@@ -59,51 +75,24 @@ public class ModifiedSelectorTest extend
private Path testclasses = null;
- // ===================== constructors, factories =====================
-
-
- public ModifiedSelectorTest(String name) {
- super(name);
- }
-
-
- /**
- * Factory method from base class. This should be overriden in child
- * classes to return a specific Selector class (like here).
- */
- public BaseSelector getInstance() {
- return new ModifiedSelector();
- }
// ===================== JUnit stuff =====================
+ @Before
public void setUp() {
- // project reference is set in super.setUp()
- super.setUp();
// init the testclasses path object
- Project prj = getProject();
- if (prj != null) {
- testclasses = new Path(prj, prj.getProperty("build.tests.value"));
- }
- }
-
-
- /* * /
- // for test only - ignore tests where we arent work at the moment
- public static junit.framework.Test suite() {
- junit.framework.TestSuite suite= new junit.framework.TestSuite();
- suite.addTest(new ModifiedSelectorTest("testValidateWrongCache"));
- return suite;
+ Project prj = selectorRule.getProject();
+ testclasses = new Path(prj, prj.getProperty("build.tests.value"));
}
- /* */
// ======= testcases for the attributes and nested elements of the selector =====
/** Test right use of cache names. */
+ @Test
public void testValidateWrongCache() {
String name = "this-is-not-a-valid-cache-name";
try {
@@ -118,6 +107,7 @@ public class ModifiedSelectorTest extend
/** Test right use of cache names. */
+ @Test
public void testValidateWrongAlgorithm() {
String name = "this-is-not-a-valid-algorithm-name";
try {
@@ -133,6 +123,7 @@ public class ModifiedSelectorTest extend
/** Test right use of comparator names. */
+ @Test
public void testValidateWrongComparator() {
String name = "this-is-not-a-valid-comparator-name";
try {
@@ -147,12 +138,12 @@ public class ModifiedSelectorTest extend
}
+ @Test
public void testIllegalCustomAlgorithm() {
try {
getAlgoName("java.lang.Object");
fail("Illegal classname used.");
- } catch (Exception e) {
- assertTrue("Wrong exception type: " + e.getClass().getName(), e instanceof BuildException);
+ } catch (BuildException e) {
assertEquals("Wrong exception message.",
"Specified class (java.lang.Object) is not an Algorithm.",
e.getMessage());
@@ -161,16 +152,12 @@ public class ModifiedSelectorTest extend
}
+ @Test
public void testNonExistentCustomAlgorithm() {
- boolean noExcThrown = false;
- try {
+ try {
getAlgoName("non.existent.custom.Algorithm");
- noExcThrown = true;
- } catch (Exception e) {
- if (noExcThrown) {
- fail("does 'non.existent.custom.Algorithm' really exist?");
- }
- assertTrue("Wrong exception type: " + e.getClass().getName(), e instanceof BuildException);
+ fail("does 'non.existent.custom.Algorithm' really exist?");
+ } catch (BuildException e) {
assertEquals("Wrong exception message.",
"Specified class (non.existent.custom.Algorithm) not found.",
e.getMessage());
@@ -178,23 +165,22 @@ public class ModifiedSelectorTest extend
}
}
-
+ @Test
public void testCustomAlgorithm() {
String algo = getAlgoName("org.apache.tools.ant.types.selectors.modifiedselector.HashvalueAlgorithm");
assertTrue("Wrong algorithm used: "+algo, algo.startsWith("HashvalueAlgorithm"));
}
-
+ @Test
public void testCustomAlgorithm2() {
String algo = getAlgoName("org.apache.tools.ant.types.selectors.MockAlgorithm");
assertTrue("Wrong algorithm used: "+algo, algo.startsWith("MockAlgorithm"));
}
+ @Test
public void testCustomClasses() {
- if (getProject().getProperty("ant.home") == null) {
- return;
- }
+ Assume.assumeNotNull("Ant home not set", selectorRule.getProject().getProperty("ant.home") );
BFT bft = new BFT();
bft.setUp();
try {
@@ -220,16 +206,19 @@ public class ModifiedSelectorTest extend
}
+ @Test
public void testDelayUpdateTaskFinished() {
doDelayUpdateTest(1);
}
+ @Test
public void testDelayUpdateTargetFinished() {
doDelayUpdateTest(2);
}
+ @Test
public void testDelayUpdateBuildFinished() {
doDelayUpdateTest(3);
}
@@ -290,7 +279,7 @@ public class ModifiedSelectorTest extend
*/
private String getAlgoName(String classname) {
ModifiedSelector sel = new ModifiedSelector();
- sel.setProject(getProject());
+ sel.setProject(selectorRule.getProject());
// add the test classes to its classpath
sel.addClasspath(testclasses);
sel.setAlgorithmClass(classname);
@@ -316,6 +305,7 @@ public class ModifiedSelectorTest extend
* Propertycache must have a set 'cachefile' attribute.
* The default in ModifiedSelector "cache.properties" is set by the selector.
*/
+ @Test
public void testPropcacheInvalid() {
Cache cache = new PropertiesfileCache();
if (cache.isValid())
@@ -323,6 +313,7 @@ public class ModifiedSelectorTest extend
}
+ @Test
public void testPropertyfileCache() {
PropertiesfileCache cache = new PropertiesfileCache();
File cachefile = new File("cache.properties");
@@ -333,8 +324,9 @@ public class ModifiedSelectorTest extend
/** Checks whether a cache file is created. */
+ @Test
public void testCreatePropertiesCacheDirect() {
- File cachefile = new File(basedir, "cachefile.properties");
+ File cachefile = new File(selectorRule.getProject().getBaseDir(), "cachefile.properties");
PropertiesfileCache cache = new PropertiesfileCache();
cache.setCachefile(cachefile);
@@ -350,32 +342,27 @@ public class ModifiedSelectorTest extend
/** Checks whether a cache file is created. */
+ @Test
public void testCreatePropertiesCacheViaModifiedSelector() {
- File cachefile = new File(basedir, "cachefile.properties");
- try {
-
- // initialize test environment (called "bed")
- makeBed();
-
- // Configure the selector
- ModifiedSelector s = (ModifiedSelector)getSelector();
- s.setDelayUpdate(false);
- s.addParam("cache.cachefile", cachefile);
-
- ModifiedSelector.CacheName cacheName = new ModifiedSelector.CacheName();
- cacheName.setValue("propertyfile");
- s.setCache(cacheName);
-
- s.setUpdate(true);
-
- selectionString(s);
-
- // evaluate correctness
- assertTrue("Cache file is not created.", cachefile.exists());
- } finally {
- cleanupBed();
- if (cachefile!=null) cachefile.delete();
- }
+ File cachefile = new File(selectorRule.getProject().getBaseDir(), "cachefile.properties");
+
+ // Configure the selector
+ ModifiedSelector s = new ModifiedSelector();
+ s.setDelayUpdate(false);
+ s.addParam("cache.cachefile", cachefile);
+
+ ModifiedSelector.CacheName cacheName = new ModifiedSelector.CacheName();
+ cacheName.setValue("propertyfile");
+ s.setCache(cacheName);
+
+ s.setUpdate(true);
+
+ selectorRule.selectionString(s);
+
+ // evaluate correctness
+ assertTrue("Cache file is not created.", cachefile.exists());
+ cachefile.delete();
+
}
@@ -390,32 +377,30 @@ public class ModifiedSelectorTest extend
* the cache's configuration parameters. That results in the reorganized
* configure() method of ModifiedSelector. This testcase tests that.
*/
+ @Test
public void testCreatePropertiesCacheViaCustomSelector() {
File cachefile = FILE_UTILS.createTempFile("tmp-cache-", ".properties", null, false, false);
- try {
- // initialize test environment (called "bed")
- makeBed();
- // Configure the selector
+ // Configure the selector
- ExtendSelector s = new ExtendSelector();
- s.setClassname("org.apache.tools.ant.types.selectors.modifiedselector.ModifiedSelector");
- s.addParam(createParam("update", "true"));
- s.addParam(createParam("cache.cachefile", cachefile.getAbsolutePath()));
- s.addParam(createParam("cache", "propertyfile"));
+ ExtendSelector s = new ExtendSelector();
+ s.setClassname("org.apache.tools.ant.types.selectors.modifiedselector.ModifiedSelector");
+ s.addParam(createParam("update", "true"));
+ s.addParam(createParam("cache.cachefile", cachefile.getAbsolutePath()));
+ s.addParam(createParam("cache", "propertyfile"));
- selectionString(s);
+ selectorRule.selectionString(s);
+
+ // evaluate correctness
+ assertTrue("Cache file is not created.", cachefile.exists());
+ cachefile.delete();
- // evaluate correctness
- assertTrue("Cache file is not created.", cachefile.exists());
- } finally {
- cleanupBed();
- if (cachefile!=null) cachefile.delete();
- }
}
- public void _testCustomCache() {
+ @Test
+ @Ignore("same logic as on algorithm, no testcases created")
+ public void testCustomCache() {
// same logic as on algorithm, no testcases created
}
@@ -467,12 +452,14 @@ public class ModifiedSelectorTest extend
// ============== testcases for the algorithm implementations ==============
+ @Test
public void testHashvalueAlgorithm() {
HashvalueAlgorithm algo = new HashvalueAlgorithm();
doTest(algo);
}
+ @Test
public void testDigestAlgorithmMD5() {
DigestAlgorithm algo = new DigestAlgorithm();
algo.setAlgorithm("MD5");
@@ -480,6 +467,7 @@ public class ModifiedSelectorTest extend
}
+ @Test
public void testDigestAlgorithmSHA() {
DigestAlgorithm algo = new DigestAlgorithm();
algo.setAlgorithm("SHA");
@@ -487,12 +475,14 @@ public class ModifiedSelectorTest extend
}
+ @Test
public void testChecksumAlgorithm() {
ChecksumAlgorithm algo = new ChecksumAlgorithm();
doTest(algo);
}
+ @Test
public void testChecksumAlgorithmCRC() {
ChecksumAlgorithm algo = new ChecksumAlgorithm();
algo.setAlgorithm("CRC");
@@ -500,6 +490,7 @@ public class ModifiedSelectorTest extend
}
+ @Test
public void testChecksumAlgorithmAdler() {
ChecksumAlgorithm algo = new ChecksumAlgorithm();
algo.setAlgorithm("Adler");
@@ -516,35 +507,30 @@ public class ModifiedSelectorTest extend
* @param algo configured test object
*/
protected void doTest(Algorithm algo) {
- assertTrue("Algorithm not proper configured.", algo.isValid());
- try {
- makeBed();
+ assertTrue("Algorithm not proper configured.", algo.isValid());
+ for (int i=0; i<selectorRule.getFiles().length; i++) {
+ File file = selectorRule.getFiles()[i]; // must not be a directory
+ if (file.isFile()) {
+ // get the Hashvalues
+ String hash1 = algo.getValue(file);
+ String hash2 = algo.getValue(file);
+ String hash3 = algo.getValue(file);
+ String hash4 = algo.getValue(file);
+ String hash5 = algo.getValue(new File(file.getAbsolutePath()));
+
+ // Assert !=null and equality
+ assertNotNull("Hashvalue was null for "+file.getAbsolutePath(), hash1);
+ assertNotNull("Hashvalue was null for "+file.getAbsolutePath(), hash2);
+ assertNotNull("Hashvalue was null for "+file.getAbsolutePath(), hash3);
+ assertNotNull("Hashvalue was null for "+file.getAbsolutePath(), hash4);
+ assertNotNull("Hashvalue was null for "+file.getAbsolutePath(), hash5);
+ assertEquals("getHashvalue() returned different value for "+file.getAbsolutePath(), hash1, hash2);
+ assertEquals("getHashvalue() returned different value for "+file.getAbsolutePath(), hash1, hash3);
+ assertEquals("getHashvalue() returned different value for "+file.getAbsolutePath(), hash1, hash4);
+ assertEquals("getHashvalue() returned different value for "+file.getAbsolutePath(), hash1, hash5);
+ }//if-isFile
+ }//for
- for (int i=0; i<files.length; i++) {
- File file = files[i]; // must not be a directory
- if (file.isFile()) {
- // get the Hashvalues
- String hash1 = algo.getValue(file);
- String hash2 = algo.getValue(file);
- String hash3 = algo.getValue(file);
- String hash4 = algo.getValue(file);
- String hash5 = algo.getValue(new File(file.getAbsolutePath()));
-
- // Assert !=null and equality
- assertNotNull("Hashvalue was null for "+file.getAbsolutePath(), hash1);
- assertNotNull("Hashvalue was null for "+file.getAbsolutePath(), hash2);
- assertNotNull("Hashvalue was null for "+file.getAbsolutePath(), hash3);
- assertNotNull("Hashvalue was null for "+file.getAbsolutePath(), hash4);
- assertNotNull("Hashvalue was null for "+file.getAbsolutePath(), hash5);
- assertEquals("getHashvalue() returned different value for "+file.getAbsolutePath(), hash1, hash2);
- assertEquals("getHashvalue() returned different value for "+file.getAbsolutePath(), hash1, hash3);
- assertEquals("getHashvalue() returned different value for "+file.getAbsolutePath(), hash1, hash4);
- assertEquals("getHashvalue() returned different value for "+file.getAbsolutePath(), hash1, hash5);
- }//if-isFile
- }//for
- } finally {
- cleanupBed();
- }
}
@@ -552,20 +538,23 @@ public class ModifiedSelectorTest extend
// ============== testcases for the comparator implementations ==============
+ @Test
public void testEqualComparator() {
EqualComparator comp = new EqualComparator();
doTest(comp);
}
+ @Test
public void testRuleComparator() {
RuleBasedCollator comp = (RuleBasedCollator)RuleBasedCollator.getInstance();
doTest(comp);
}
+ @Test
public void testEqualComparatorViaSelector() {
- ModifiedSelector s = (ModifiedSelector)getSelector();
+ ModifiedSelector s = new ModifiedSelector();
ModifiedSelector.ComparatorName compName = new ModifiedSelector.ComparatorName();
compName.setValue("equal");
s.setComparator(compName);
@@ -577,8 +566,10 @@ public class ModifiedSelectorTest extend
}
- public void _testRuleComparatorViaSelector() { //not yet supported see note in selector
- ModifiedSelector s = (ModifiedSelector)getSelector();
+ @Test
+ @Ignore("not yet supported see note in selector")
+ public void testRuleComparatorViaSelector() {
+ ModifiedSelector s = new ModifiedSelector();
ModifiedSelector.ComparatorName compName = new ModifiedSelector.ComparatorName();
compName.setValue("rule");
s.setComparator(compName);
@@ -590,37 +581,46 @@ public class ModifiedSelectorTest extend
}
- public void _testCustomComparator() {
+ @Test
+ @Ignore("same logic as on algorithm, no testcases created")
+ public void testCustomComparator() {
// same logic as on algorithm, no testcases created
}
+ @Test
public void testResourceSelectorSimple() {
- BFT bft = new BFT("modifiedselector");
+ BFT bft = new BFT();
bft.doTarget("modifiedselectortest-ResourceSimple");
bft.deleteCachefile();
//new File("src/etc/testcases/types/resources/selectors/cache.properties").delete();
}
+
+ @Test
public void testResourceSelectorSelresTrue() {
- BFT bft = new BFT("modifiedselector");
+ BFT bft = new BFT();
bft.doTarget("modifiedselectortest-ResourceSelresTrue");
- bft.assertLogContaining("does not provide an InputStream");
+ AntAssert.assertContains("does not provide an InputStream", bft.getLog());
bft.deleteCachefile();
}
+
+ @Test
public void testResourceSelectorSelresFalse() {
- BFT bft = new BFT("modifiedselector");
+ BFT bft = new BFT();
bft.doTarget("modifiedselectortest-ResourceSelresFalse");
bft.deleteCachefile();
}
+
+ @Test
public void testResourceSelectorScenarioSimple() {
- if (getProject().getProperty("ant.home") == null) {
- return;
- }
- BFT bft = new BFT("modifiedselector");
+
+ Assume.assumeNotNull("Ant home not set", selectorRule.getProject().getProperty("ant.home"));
+ BFT bft = new BFT();
bft.doTarget("modifiedselectortest-scenario-resourceSimple");
bft.doTarget("modifiedselectortest-scenario-clean");
bft.deleteCachefile();
}
+
/**
* Test the interface semantic of Comparators.
* This method does some common test for comparator implementations.
@@ -644,35 +644,30 @@ public class ModifiedSelectorTest extend
/**
* Tests whether the seldirs attribute is used.
*/
+ @Test
public void testSeldirs() {
- ModifiedSelector s = (ModifiedSelector)getSelector();
- try {
- makeBed();
-
- StringBuffer sbTrue = new StringBuffer();
- StringBuffer sbFalse = new StringBuffer();
- for (int i=0; i<filenames.length; i++) {
- if (files[i].isDirectory()) {
- sbTrue.append("T");
- sbFalse.append("F");
- } else {
- sbTrue.append("T");
- sbFalse.append("T");
- }
+ ModifiedSelector s = new ModifiedSelector();
+ StringBuffer sbTrue = new StringBuffer();
+ StringBuffer sbFalse = new StringBuffer();
+ for (int i=0; i<selectorRule.getFiles().length; i++) {
+ if (selectorRule.getFiles()[i].isDirectory()) {
+ sbTrue.append("T");
+ sbFalse.append("F");
+ } else {
+ sbTrue.append("T");
+ sbFalse.append("T");
}
+ }
- s.setSeldirs(true);
- performTests(s, sbTrue.toString());
- s.getCache().delete();
-
- s.setSeldirs(false);
- performTests(s, sbFalse.toString());
- s.getCache().delete();
+ s.setSeldirs(true);
+ performTests(s, sbTrue.toString());
+ s.getCache().delete();
+
+ s.setSeldirs(false);
+ performTests(s, sbFalse.toString());
+ s.getCache().delete();
- } finally {
- cleanupBed();
- if (s!=null) s.getCache().delete();
- }
+ s.getCache().delete();
}
@@ -686,18 +681,16 @@ public class ModifiedSelectorTest extend
* <li> try third time --> should select only the file with modified
* content </li>
*/
+ @Test
public void testScenario1() {
BFT bft = null;
ModifiedSelector s = null;
try {
- //
- // ***** initialize test environment (called "bed") *****
- //
- makeBed();
- String results = null;
+
+ String results;
// Configure the selector - only defaults are used
- s = (ModifiedSelector)getSelector();
+ s = new ModifiedSelector();
//
// ***** First Run *****
@@ -735,7 +728,7 @@ public class ModifiedSelectorTest extend
// ***** Third Run *****
// third call should get only those files, which CONTENT changed
// (no timestamp changes required!)
- results = selectionString(s);
+ results = selectorRule.selectionString(s);
//
// ***** Check the result *****
@@ -745,12 +738,12 @@ public class ModifiedSelectorTest extend
// as (F)alse. Directories are always selected so they always are
// (T)rue.
StringBuffer expected = new StringBuffer();
- for (int i=0; i<filenames.length; i++) {
+ for (int i=0; i<selectorRule.getFiles().length; i++) {
String ch = "F";
- if (files[i].isDirectory()) ch = "T";
+ if (selectorRule.getFiles()[i].isDirectory()) ch = "T";
// f2name shouldn't be selected: only timestamp has changed!
- if (filenames[i].equalsIgnoreCase(f3name)) ch = "T";
- if (filenames[i].equalsIgnoreCase(f4name)) ch = "T";
+ if (selectorRule.getFilenames()[i].equalsIgnoreCase(f3name)) ch = "T";
+ if (selectorRule.getFilenames()[i].equalsIgnoreCase(f4name)) ch = "T";
expected.append(ch);
}
@@ -763,7 +756,6 @@ public class ModifiedSelectorTest extend
} finally {
// cleanup the environment
- cleanupBed();
if (s!=null) s.getCache().delete();
if (bft!=null) bft.deletePropertiesfile();
}
@@ -780,12 +772,13 @@ public class ModifiedSelectorTest extend
* <li><b>Comparator: </b> java.text.RuleBasedCollator
* <li><b>Update: </b> true </li>
*/
- public void _testScenario2() { // RuleBasedCollator not yet supported - see Selector:375 note
+ @Test
+ @Ignore("RuleBasedCollator not yet supported - see Selector:375 note")
+ public void testScenario2() {
ExtendSelector s = new ExtendSelector();
BFT bft = new BFT();
String cachefile = System.getProperty("java.io.tmpdir")+"/mycache.txt";
try {
- makeBed();
s.setClassname("org.apache.tools.ant.types.selectors.modifiedselector.ModifiedSelector");
@@ -809,13 +802,13 @@ public class ModifiedSelectorTest extend
bft.writeProperties("f4name="+f4name);
bft.doTarget("modifiedselectortest-makeDirty");
// third run
- String results = selectionString(s);
+ String results = selectorRule.selectionString(s);
StringBuffer expected = new StringBuffer();
- for (int i=0; i<filenames.length; i++) {
+ for (int i=0; i<selectorRule.getFilenames().length; i++) {
String ch = "F";
- if (files[i].isDirectory()) ch = "T";
- if (filenames[i].equalsIgnoreCase(f3name)) ch = "T";
- if (filenames[i].equalsIgnoreCase(f4name)) ch = "T";
+ if (selectorRule.getFiles()[i].isDirectory()) ch = "T";
+ if (selectorRule.getFilenames()[i].equalsIgnoreCase(f3name)) ch = "T";
+ if (selectorRule.getFilenames()[i].equalsIgnoreCase(f4name)) ch = "T";
expected.append(ch);
}
assertEquals(
@@ -826,33 +819,29 @@ public class ModifiedSelectorTest extend
);
} finally {
// cleanup the environment
- cleanupBed();
(new java.io.File(cachefile)).delete();
- if (bft!=null) bft.deletePropertiesfile();
+ bft.deletePropertiesfile();
}
}
+ @Test
public void testScenarioCoreSelectorDefaults() {
- if (getProject().getProperty("ant.home") == null) {
- return;
- }
+ Assume.assumeNotNull("Ant home not set", selectorRule.getProject().getProperty("ant.home") );
doScenarioTest("modifiedselectortest-scenario-coreselector-defaults", "cache.properties");
}
+ @Test
public void testScenarioCoreSelectorSettings() {
- if (getProject().getProperty("ant.home") == null) {
- return;
- }
+ Assume.assumeNotNull("Ant home not set", selectorRule.getProject().getProperty("ant.home") );
doScenarioTest("modifiedselectortest-scenario-coreselector-settings", "core.cache.properties");
}
+ @Test
public void testScenarioCustomSelectorSettings() {
- if (getProject().getProperty("ant.home") == null) {
- return;
- }
+ Assume.assumeNotNull("Ant home not set", selectorRule.getProject().getProperty("ant.home") );
doScenarioTest("modifiedselectortest-scenario-customselector-settings", "core.cache.properties");
}
@@ -860,16 +849,16 @@ public class ModifiedSelectorTest extend
public void doScenarioTest(String target, String cachefilename) {
BFT bft = new BFT();
bft.setUp();
- File cachefile = new File(basedir, cachefilename);
+ File cachefile = new File(selectorRule.getProject().getBaseDir(), cachefilename);
try {
// do the actions
bft.doTarget("modifiedselectortest-scenario-clean");
bft.doTarget(target);
// the directories to check
- File to1 = new File(getOutputDir(), "selectortest/to-1");
- File to2 = new File(getOutputDir(), "selectortest/to-2");
- File to3 = new File(getOutputDir(), "selectortest/to-3");
+ File to1 = new File(selectorRule.getOutputDir(), "selectortest/to-1");
+ File to2 = new File(selectorRule.getOutputDir(), "selectortest/to-2");
+ File to3 = new File(selectorRule.getOutputDir(), "selectortest/to-3");
// do the checks
assertTrue("Cache file not created.", cachefile.exists());
@@ -905,23 +894,19 @@ public class ModifiedSelectorTest extend
/**
* The BFT class wrapps the selector test-builfile inside an
- * ant project (BuildFileTest). It supports target execution
+ * ant project. It supports target execution
* and property transfer to that project.
*/
- private class BFT extends org.apache.tools.ant.BuildFileTest {
+ private class BFT extends BuildFileRule {
String buildfile = "src/etc/testcases/types/selectors.xml";
- BFT() { super("nothing"); }
- BFT(String name) {
- super(name);
- }
-
String propfile = "ModifiedSelectorTest.properties";
boolean isConfigured = false;
+
public void setUp() {
- configureProject(buildfile);
+ super.configureProject(buildfile);
isConfigured = true;
}
@@ -931,11 +916,8 @@ public class ModifiedSelectorTest extend
* tearDown method, and in the superclass it is protected.
*/
public void tearDown() {
- try {
- super.tearDown();
- } catch (Exception e) {
- // ignore
- }
+ super.after();
+
}
public void doTarget(String target) {
@@ -944,7 +926,7 @@ public class ModifiedSelectorTest extend
}
public String getProperty(String property) {
- return project.getProperty(property);
+ return super.getProject().getProperty(property);
}
public void writeProperties(String line) {
@@ -974,12 +956,6 @@ public class ModifiedSelectorTest extend
cacheFile.delete();
}
- public String getBuildfile() {
- return buildfile;
- }
- public void setBuildfile(String buildfile) {
- this.buildfile = buildfile;
- }
}//class-BFT
@@ -1025,4 +1001,62 @@ public class ModifiedSelectorTest extend
}//class-MockProject
+ /**
+ * Does the selection test for a given selector and prints the
+ * filenames of the differing files (selected but shouldn't,
+ * not selected but should).
+ * @param selector The selector to test
+ * @param expected The expected result
+ */
+ private void performTests(FileSelector selector, String expected) {
+ String result = selectorRule.selectionString(selector);
+ String diff = diff(expected, result);
+ String resolved = resolve(diff);
+ assertEquals("Differing files: " + resolved, result, expected);
+ }
+ /**
+ * Checks which files are selected and shouldn't be or which
+ * are not selected but should.
+ * @param expected String containing 'F's and 'T's
+ * @param result String containing 'F's and 'T's
+ * @return Difference as String containing '-' (equal) and
+ * 'X' (difference).
+ */
+ private String diff(String expected, String result) {
+ int length1 = expected.length();
+ int length2 = result.length();
+ int min = (length1 > length2) ? length2 : length1;
+ StringBuffer sb = new StringBuffer();
+ for (int i=0; i<min; i++) {
+ sb.append(
+ (expected.charAt(i) == result.charAt(i))
+ ? "-"
+ : "X"
+ );
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Resolves a diff-String (@see diff()) against the (inherited) filenames-
+ * and files arrays.
+ * @param filelist Diff-String
+ * @return String containing the filenames for all differing files,
+ * separated with semicolons ';'
+ */
+ private String resolve(String filelist) {
+ StringBuffer sb = new StringBuffer();
+ int min = (selectorRule.getFilenames().length > filelist.length())
+ ? filelist.length()
+ : selectorRule.getFilenames().length;
+ for (int i=0; i<min; i++) {
+ if ('X'==filelist.charAt(i)) {
+ sb.append(selectorRule.getFilenames()[i]);
+ sb.append(";");
+ }
+ }
+ return sb.toString();
+ }
+
+
}//class-ModifiedSelectorTest
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/PresentSelectorTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/PresentSelectorTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/PresentSelectorTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/PresentSelectorTest.java Fri Apr 18 21:00:38 2014
@@ -20,33 +20,31 @@ package org.apache.tools.ant.types.selec
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.types.Mapper;
+import org.junit.Rule;
+import org.junit.Test;
import java.io.File;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
/**
* Tests Present Selectors
*
*/
-public class PresentSelectorTest extends BaseSelectorTest {
+public class PresentSelectorTest {
- public PresentSelectorTest(String name) {
- super(name);
- }
- /**
- * Factory method from base class. This is overriden in child
- * classes to return a specific Selector class.
- */
- public BaseSelector getInstance() {
- return new PresentSelector();
- }
+ @Rule
+ public final BaseSelectorRule selectorRule = new BaseSelectorRule();
/**
* Test the code that validates the selector.
*/
+ @Test
public void testValidate() {
- PresentSelector s = (PresentSelector)getInstance();
+ PresentSelector s = new PresentSelector();
try {
s.createMapper();
s.createMapper();
@@ -56,9 +54,9 @@ public class PresentSelectorTest extends
be1.getMessage());
}
- s = (PresentSelector)getInstance();
+ s = new PresentSelector();
try {
- s.isSelected(basedir,filenames[0],files[0]);
+ s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
fail("PresentSelector did not check for required fields");
} catch (BuildException be2) {
assertEquals("The targetdir attribute is required.",
@@ -70,6 +68,7 @@ public class PresentSelectorTest extends
/**
* Tests to make sure that the selector is selecting files correctly.
*/
+ @Test
public void testSelectionBehaviour() {
PresentSelector s;
String results;
@@ -83,68 +82,55 @@ public class PresentSelectorTest extends
Mapper.MapperType flatten = new Mapper.MapperType();
flatten.setValue("flatten");
- try {
- makeBed();
-
- s = (PresentSelector)getInstance();
- s.setTargetdir(beddir);
- results = selectionString(s);
- assertEquals("TTTTTTTTTTTT", results);
-
- s = (PresentSelector)getInstance();
- s.setTargetdir(beddir);
- m = s.createMapper();
- m.setType(identity);
- results = selectionString(s);
- assertEquals("TTTTTTTTTTTT", results);
-
- s = (PresentSelector)getInstance();
- File subdir = new File(System.getProperty("root"), "src/etc/testcases/taskdefs/expected");
- s.setTargetdir(subdir);
- m = s.createMapper();
- m.setType(flatten);
- results = selectionString(s);
- assertEquals("TTTTTTTTTTTF", results);
-
- s = (PresentSelector)getInstance();
- s.setTargetdir(beddir);
- m = s.createMapper();
- m.setType(merge);
- m.setTo("asf-logo.gif.gz");
- results = selectionString(s);
- assertEquals("TTTTTTTTTTTT", results);
-
- s = (PresentSelector)getInstance();
- subdir = new File(beddir, "tar/bz2");
- s.setTargetdir(subdir);
- m = s.createMapper();
- m.setType(glob);
- m.setFrom("*.bz2");
- m.setTo("*.tar.bz2");
- results = selectionString(s);
- assertEquals("FFTFFFFFFFFF", results);
-
- try {
- makeMirror();
-
- s = (PresentSelector)getInstance();
- subdir = new File(getOutputDir(), "selectortest2");
- s.setTargetdir(subdir);
- results = mirrorSelectionString(s);
- assertEquals("TTTFFTTTTTTT", results);
- results = selectionString(s);
- assertEquals("TTTFFTTTTTTT", results);
-
-
- }
- finally {
- cleanupMirror();
- }
+ File beddir = selectorRule.getBeddir();
+
+ s = new PresentSelector();
+ s.setTargetdir(beddir);
+ results = selectorRule.selectionString(s);
+ assertEquals("TTTTTTTTTTTT", results);
+
+ s = new PresentSelector();
+ s.setTargetdir(beddir);
+ m = s.createMapper();
+ m.setType(identity);
+ results = selectorRule.selectionString(s);
+ assertEquals("TTTTTTTTTTTT", results);
+
+ s = new PresentSelector();
+ File subdir = new File(System.getProperty("root"), "src/etc/testcases/taskdefs/expected");
+ s.setTargetdir(subdir);
+ m = s.createMapper();
+ m.setType(flatten);
+ results = selectorRule.selectionString(s);
+ assertEquals("TTTTTTTTTTTF", results);
+
+ s = new PresentSelector();
+ s.setTargetdir(beddir);
+ m = s.createMapper();
+ m.setType(merge);
+ m.setTo("asf-logo.gif.gz");
+ results = selectorRule.selectionString(s);
+ assertEquals("TTTTTTTTTTTT", results);
+
+ s = new PresentSelector();
+ subdir = new File(beddir, "tar/bz2");
+ s.setTargetdir(subdir);
+ m = s.createMapper();
+ m.setType(glob);
+ m.setFrom("*.bz2");
+ m.setTo("*.tar.bz2");
+ results = selectorRule.selectionString(s);
+ assertEquals("FFTFFFFFFFFF", results);
+
+
+ s = new PresentSelector();
+ subdir = new File(selectorRule.getOutputDir(), "selectortest2");
+ s.setTargetdir(subdir);
+ results = selectorRule.selectionString(s);
+ assertEquals("TTTFFTTTTTTT", results);
+ results = selectorRule.selectionString(s);
+ assertEquals("TTTFFTTTTTTT", results);
- }
- finally {
- cleanupBed();
- }
}
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/SignedSelectorTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/SignedSelectorTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/SignedSelectorTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/SignedSelectorTest.java Fri Apr 18 21:00:38 2014
@@ -18,28 +18,37 @@
package org.apache.tools.ant.types.selectors;
-import org.apache.tools.ant.BuildFileTest;
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
/**
* Testcase for the <signedselector> selector.
*
*/
-public class SignedSelectorTest extends BuildFileTest {
+public class SignedSelectorTest {
- public SignedSelectorTest(String name) {
- super(name);
- }
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ @Before
public void setUp() {
- configureProject("src/etc/testcases/types/selectors/signedselector.xml");
+ buildRule.configureProject("src/etc/testcases/types/selectors/signedselector.xml");
}
+ @Test
public void testSelectSigned() {
- executeTarget("selectsigned");
+ buildRule.executeTarget("selectsigned");
}
+
+ @Test
public void testNotSelected() {
- executeTarget("notselected");
+ buildRule.executeTarget("notselected");
}
+
+ @Test
public void testName() {
- executeTarget("name");
+ buildRule.executeTarget("name");
}
}
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/SizeSelectorTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/SizeSelectorTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/SizeSelectorTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/SizeSelectorTest.java Fri Apr 18 21:00:38 2014
@@ -21,42 +21,39 @@ package org.apache.tools.ant.types.selec
import java.util.Locale;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.types.Parameter;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
/**
* Tests Size Selectors
*
*/
-public class SizeSelectorTest extends BaseSelectorTest {
-
- public SizeSelectorTest(String name) {
- super(name);
- }
-
- /**
- * Factory method from base class. This is overriden in child
- * classes to return a specific Selector class.
- */
- public BaseSelector getInstance() {
- return new SizeSelector();
- }
+public class SizeSelectorTest {
+
+ @Rule
+ public final BaseSelectorRule selectorRule = new BaseSelectorRule();
/**
* Test the code that validates the selector.
*/
+ @Test
public void testValidate() {
- SizeSelector s = (SizeSelector)getInstance();
+ SizeSelector s = new SizeSelector();
try {
- s.isSelected(basedir,filenames[0],files[0]);
+ s.isSelected(selectorRule.getProject().getBaseDir(), selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
fail("SizeSelector did not check for required fields");
} catch (BuildException be1) {
assertEquals("The value attribute is required, and must "
+ "be positive", be1.getMessage());
}
- s = (SizeSelector)getInstance();
+ s = new SizeSelector();
s.setValue(-10);
try {
- s.isSelected(basedir,filenames[0],files[0]);
+ s.isSelected(selectorRule.getProject().getBaseDir(), selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
fail("SizeSelector did not check for value being in the "
+ "allowable range");
} catch (BuildException be2) {
@@ -64,34 +61,34 @@ public class SizeSelectorTest extends Ba
+ "be positive", be2.getMessage());
}
- s = (SizeSelector)getInstance();
+ s = new SizeSelector();
Parameter param = new Parameter();
param.setName("garbage in");
param.setValue("garbage out");
Parameter[] params = {param};
s.setParameters(params);
try {
- s.isSelected(basedir,filenames[0],files[0]);
+ s.isSelected(selectorRule.getProject().getBaseDir(), selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
fail("SizeSelector did not check for valid parameter element");
} catch (BuildException be3) {
assertEquals("Invalid parameter garbage in", be3.getMessage());
}
- s = (SizeSelector)getInstance();
+ s = new SizeSelector();
param = new Parameter();
param.setName("value");
param.setValue("garbage out");
params[0] = param;
s.setParameters(params);
try {
- s.isSelected(basedir,filenames[0],files[0]);
+ s.isSelected(selectorRule.getProject().getBaseDir(), selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
fail("SizeSelector accepted bad value as parameter");
} catch (BuildException be4) {
assertEquals("Invalid size setting garbage out",
be4.getMessage());
}
- s = (SizeSelector)getInstance();
+ s = new SizeSelector();
Parameter param1 = new Parameter();
Parameter param2 = new Parameter();
param1.setName("value");
@@ -103,7 +100,7 @@ public class SizeSelectorTest extends Ba
params[1] = param2;
try {
s.setParameters(params);
- s.isSelected(basedir,filenames[0],files[0]);
+ s.isSelected(selectorRule.getProject().getBaseDir(), selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
fail("SizeSelector accepted bad units as parameter");
} catch (BuildException be5) {
assertEquals("garbage out is not a legal value for this attribute",
@@ -115,6 +112,7 @@ public class SizeSelectorTest extends Ba
/**
* Tests to make sure that the selector is selecting files correctly.
*/
+ @Test
public void testSelectionBehaviour() {
SizeSelector s;
String results;
@@ -133,77 +131,75 @@ public class SizeSelectorTest extends Ba
more.setValue("more");
- try {
- makeBed();
+
+ s = new SizeSelector();
+ s.setValue(10);
+ s.setWhen(less);
+ results = selectorRule.selectionString(s);
+ assertEquals("TFFFFFFFFFFT", results);
+
+ s = new SizeSelector();
+ s.setValue(10);
+ s.setWhen(more);
+ results = selectorRule.selectionString(s);
+ assertEquals("TTTTTTTTTTTT", results);
+
+ s = new SizeSelector();
+ s.setValue(32);
+ s.setWhen(equal);
+ results = selectorRule.selectionString(s);
+ assertEquals("TFFFTFFFFFFT", results);
+
+ s = new SizeSelector();
+ s.setValue(7);
+ s.setWhen(more);
+ s.setUnits(kilo);
+ results = selectorRule.selectionString(s);
+ assertEquals("TFTFFTTTTTTT", results);
+
+ s = new SizeSelector();
+ s.setValue(7);
+ s.setWhen(more);
+ s.setUnits(kibi);
+ results = selectorRule.selectionString(s);
+ assertEquals("TFTFFFTTFTTT", results);
+
+ s = new SizeSelector();
+ s.setValue(99999);
+ s.setWhen(more);
+ s.setUnits(tibi);
+ results = selectorRule.selectionString(s);
+ assertEquals("TFFFFFFFFFFT", results);
- s = (SizeSelector)getInstance();
- s.setValue(10);
- s.setWhen(less);
- results = selectionString(s);
- assertEquals("TFFFFFFFFFFT", results);
-
- s = (SizeSelector)getInstance();
- s.setValue(10);
- s.setWhen(more);
- results = selectionString(s);
- assertEquals("TTTTTTTTTTTT", results);
-
- s = (SizeSelector)getInstance();
- s.setValue(32);
- s.setWhen(equal);
- results = selectionString(s);
- assertEquals("TFFFTFFFFFFT", results);
-
- s = (SizeSelector)getInstance();
- s.setValue(7);
- s.setWhen(more);
- s.setUnits(kilo);
- results = selectionString(s);
- assertEquals("TFTFFTTTTTTT", results);
-
- s = (SizeSelector)getInstance();
- s.setValue(7);
- s.setWhen(more);
- s.setUnits(kibi);
- results = selectionString(s);
- assertEquals("TFTFFFTTFTTT", results);
-
- s = (SizeSelector)getInstance();
- s.setValue(99999);
- s.setWhen(more);
- s.setUnits(tibi);
- results = selectionString(s);
- assertEquals("TFFFFFFFFFFT", results);
-
- s = (SizeSelector)getInstance();
- Parameter param1 = new Parameter();
- Parameter param2 = new Parameter();
- Parameter param3 = new Parameter();
- param1.setName("value");
- param1.setValue("20");
- param2.setName("units");
- param2.setValue("Ki");
- param3.setName("when");
- param3.setValue("more");
- Parameter[] params = {param1,param2,param3};
- s.setParameters(params);
- results = selectionString(s);
- assertEquals("TFFFFFFTFFTT", results);
- }
- finally {
- cleanupBed();
- }
+ s = new SizeSelector();
+ Parameter param1 = new Parameter();
+ Parameter param2 = new Parameter();
+ Parameter param3 = new Parameter();
+ param1.setName("value");
+ param1.setValue("20");
+ param2.setName("units");
+ param2.setValue("Ki");
+ param3.setName("when");
+ param3.setValue("more");
+ Parameter[] params = {param1,param2,param3};
+ s.setParameters(params);
+ results = selectorRule.selectionString(s);
+ assertEquals("TFFFFFFTFFTT", results);
+
}
+ @Test
public void testParameterParsingLowerCase() {
testCaseInsensitiveParameterParsing("units");
}
+ @Test
public void testParameterParsingUpperCase() {
testCaseInsensitiveParameterParsing("UNITS");
}
+ @Test
public void testParameterParsingLowerCaseTurkish() {
Locale l = Locale.getDefault();
try {
@@ -214,6 +210,7 @@ public class SizeSelectorTest extends Ba
}
}
+ @Test
public void testParameterParsingUpperCaseTurkish() {
Locale l = Locale.getDefault();
try {
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/TokenizedPatternTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/TokenizedPatternTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/TokenizedPatternTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/TokenizedPatternTest.java Fri Apr 18 21:00:38 2014
@@ -19,13 +19,17 @@
package org.apache.tools.ant.types.selectors;
import java.io.File;
-import junit.framework.TestCase;
+import org.junit.Test;
-public class TokenizedPatternTest extends TestCase {
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class TokenizedPatternTest {
private static final String DOT_SVN_PATTERN =
SelectorUtils.DEEP_TREE_MATCH + File.separator + ".svn"
+ File.separator + SelectorUtils.DEEP_TREE_MATCH;
+ @Test
public void testTokenization() {
TokenizedPattern pat = new TokenizedPattern(DOT_SVN_PATTERN);
assertEquals(3, pat.depth());
@@ -34,11 +38,13 @@ public class TokenizedPatternTest extend
assertTrue(pat.containsPattern(".svn"));
}
+ @Test
public void testEndsWith() {
assertTrue(new TokenizedPattern(DOT_SVN_PATTERN)
.endsWith(SelectorUtils.DEEP_TREE_MATCH));
}
+ @Test
public void testWithoutLastToken() {
assertEquals(SelectorUtils.DEEP_TREE_MATCH + File.separatorChar
+ ".svn" + File.separator,
@@ -46,6 +52,7 @@ public class TokenizedPatternTest extend
.withoutLastToken().getPattern());
}
+ @Test
public void testMatchPath() {
File f = new File(".svn");
TokenizedPath p = new TokenizedPath(f.getAbsolutePath());
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/TypeSelectorTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/TypeSelectorTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/TypeSelectorTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/TypeSelectorTest.java Fri Apr 18 21:00:38 2014
@@ -19,32 +19,30 @@
package org.apache.tools.ant.types.selectors;
import org.apache.tools.ant.BuildException;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
/**
* Tests Type Selectors.
*
*/
-public class TypeSelectorTest extends BaseSelectorTest {
+public class TypeSelectorTest {
- public TypeSelectorTest(String name) {
- super(name);
- }
+ @Rule
+ public BaseSelectorRule selectorRule = new BaseSelectorRule();
- /**
- * Factory method from base class. This is overriden in child
- * classes to return a specific Selector class.
- */
- public BaseSelector getInstance() {
- return new TypeSelector();
- }
/**
* Test the code that validates the selector.
*/
+ @Test
public void testValidate() {
- TypeSelector s = (TypeSelector)getInstance();
+ TypeSelector s = new TypeSelector();
try {
- s.isSelected(basedir,filenames[0],files[0]);
+ s.isSelected(selectorRule.getProject().getBaseDir(), selectorRule.getFilenames()[0] ,selectorRule.getFiles()[0]);
fail("TypeSelector did not check for required fields");
} catch (BuildException be1) {
assertEquals("The type attribute is required"
@@ -55,35 +53,28 @@ public class TypeSelectorTest extends Ba
/**
* Tests to make sure that the selector is selecting files correctly.
*/
+ @Test
public void testSelectionBehaviour() {
TypeSelector s;
String results;
- TypeSelector.FileType directory = new
- TypeSelector.FileType();
+ TypeSelector.FileType directory = new TypeSelector.FileType();
directory.setValue("dir");
- TypeSelector.FileType file = new
- TypeSelector.FileType();
+ TypeSelector.FileType file = new TypeSelector.FileType();
file.setValue("file");
- try {
- makeBed();
-
- s = (TypeSelector)getInstance();
- s.setType(directory);
- results = selectionString(s);
- assertEquals("TFFFFFFFFFFT", results);
-
- s = (TypeSelector)getInstance();
- s.setType(file);
- results = selectionString(s);
- assertEquals("FTTTTTTTTTTF", results);
+
+ s = new TypeSelector();
+ s.setType(directory);
+ results = selectorRule.selectionString(s);
+ assertEquals("TFFFFFFFFFFT", results);
+
+ s = new TypeSelector();
+ s.setType(file);
+ results = selectorRule.selectionString(s);
+ assertEquals("FTTTTTTTTTTF", results);
- }
- finally {
- cleanupBed();
- }
}
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/Base64ConverterTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/Base64ConverterTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/Base64ConverterTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/Base64ConverterTest.java Fri Apr 18 21:00:38 2014
@@ -17,25 +17,24 @@
*/
package org.apache.tools.ant.util;
-import junit.framework.TestCase;
+import org.junit.Test;
-import java.util.Calendar;
-import java.util.TimeZone;
+import static org.junit.Assert.assertEquals;
/**
* TestCase for Base64Converter.
*
*/
-public class Base64ConverterTest extends TestCase {
- public Base64ConverterTest(String s) {
- super(s);
- }
+public class Base64ConverterTest {
+
+ @Test
public void testOneValue() {
byte[] mybytes = {0, 0, (byte)0xFF};
Base64Converter base64Converter = new Base64Converter();
assertEquals("AAD/",base64Converter.encode(mybytes));
}
+ @Test
public void testHelloWorld() {
byte[] mybytes = "Hello World".getBytes();
Base64Converter base64Converter = new Base64Converter();
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/ClasspathUtilsTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/ClasspathUtilsTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/ClasspathUtilsTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/ClasspathUtilsTest.java Fri Apr 18 21:00:38 2014
@@ -21,31 +21,31 @@ package org.apache.tools.ant.util;
import java.io.IOException;
import java.util.Enumeration;
-import junit.framework.TestCase;
-
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.Path;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
/**
* Test case for ClasspathUtils
*
*/
-public class ClasspathUtilsTest extends TestCase {
+public class ClasspathUtilsTest {
private Project p;
- public ClasspathUtilsTest(String name) {
- super(name);
- }
-
+ @Before
public void setUp() {
p = new Project();
p.init();
}
+ @Test
public void testOnlyOneInstance() {
Enumeration enumeration;
String list = "";
@@ -55,7 +55,7 @@ public class ClasspathUtilsTest extends
"org/apache/tools/ant/taskdefs/defaults.properties");
} catch (IOException e) {
throw new BuildException(
- "Could not get the defaults.properties resource");
+ "Could not get the defaults.properties resource", e);
}
int count = 0;
while (enumeration.hasMoreElements()) {
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/CollectionUtilsTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/CollectionUtilsTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/CollectionUtilsTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/CollectionUtilsTest.java Fri Apr 18 21:00:38 2014
@@ -23,18 +23,18 @@ import java.util.Properties;
import java.util.Stack;
import java.util.Vector;
-import junit.framework.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
/**
* Tests for org.apache.tools.ant.util.CollectionUtils.
*
*/
-public class CollectionUtilsTest extends TestCase {
+public class CollectionUtilsTest {
- public CollectionUtilsTest(String name) {
- super(name);
- }
+ @Test
public void testVectorEquals() {
assertTrue(!CollectionUtils.equals(null, new Vector()));
assertTrue(!CollectionUtils.equals(new Vector(), null));
@@ -63,6 +63,7 @@ public class CollectionUtilsTest extends
assertTrue(!CollectionUtils.equals(s2, v1));
}
+ @Test
public void testDictionaryEquals() {
assertTrue(!CollectionUtils.equals(null, new Hashtable()));
assertTrue(!CollectionUtils.equals(new Hashtable(), null));
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/DOMElementWriterTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/DOMElementWriterTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/DOMElementWriterTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/DOMElementWriterTest.java Fri Apr 18 21:00:38 2014
@@ -18,26 +18,25 @@
package org.apache.tools.ant.util;
+import org.junit.Test;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
import java.io.IOException;
import java.io.StringWriter;
-import junit.framework.TestCase;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
/**
* Tests for org.apache.tools.ant.util.DOMElementWriter.
*
*/
-public class DOMElementWriterTest extends TestCase {
+public class DOMElementWriterTest {
private DOMElementWriter w = new DOMElementWriter();
- public DOMElementWriterTest(String name) {
- super(name);
- }
-
+ @Test
public void testIsReference() {
assertTrue("", w.isReference(""));
assertTrue(" ", w.isReference(" "));
@@ -52,6 +51,7 @@ public class DOMElementWriterTest extend
assertTrue("&", w.isReference("&"));
}
+ @Test
public void testEncode() {
assertEquals("&#20;", w.encode(""));
assertEquals("&#x20;", w.encode(" "));
@@ -71,6 +71,7 @@ public class DOMElementWriterTest extend
assertEquals("\r\n\t", w.encode("\r\n\t"));
}
+ @Test
public void testEncodeAttributeValue() {
assertEquals("&#20;", w.encodeAttributeValue(""));
assertEquals("&#x20;", w.encodeAttributeValue(" "));
@@ -90,6 +91,7 @@ public class DOMElementWriterTest extend
assertEquals("
	", w.encodeAttributeValue("\r\n\t"));
}
+ @Test
public void testAttributeWithWhitespace() throws IOException {
Document d = DOMUtils.newDocument();
Element root = d.createElement("root");
@@ -101,11 +103,13 @@ public class DOMElementWriterTest extend
sw.toString());
}
+ @Test
public void testEncodeData() {
assertEquals("\"20;&", w.encodedata("\"20;&"));
assertEquals("", w.encodedata("\u0017"));
}
+ @Test
public void testIsLegalCharacter() {
assertTrue("0x00", !w.isLegalCharacter('\u0000'));
assertTrue("0x09", w.isLegalCharacter('\t'));
@@ -121,6 +125,7 @@ public class DOMElementWriterTest extend
assertTrue("0xFFFE", !w.isLegalCharacter('\uFFFE'));
}
+ @Test
public void testCDATAEndEncoding() {
assertEquals("]>", w.encodedata("]>"));
assertEquals("]]", w.encodedata("]]"));
@@ -132,6 +137,7 @@ public class DOMElementWriterTest extend
w.encodedata("A]]>B]]>C"));
}
+ @Test
public void testNoAdditionalWhiteSpaceForText() throws IOException {
Document d = DOMUtils.newDocument();
Element root = d.createElement("root");
@@ -147,6 +153,7 @@ public class DOMElementWriterTest extend
sw.toString());
}
+ @Test
public void testNoAdditionalWhiteSpaceForCDATA() throws IOException {
Document d = DOMUtils.newDocument();
Element root = d.createElement("root");
@@ -162,6 +169,7 @@ public class DOMElementWriterTest extend
sw.toString());
}
+ @Test
public void testNoAdditionalWhiteSpaceForEmptyElement() throws IOException {
Document d = DOMUtils.newDocument();
Element root = d.createElement("root");
@@ -178,6 +186,7 @@ public class DOMElementWriterTest extend
sw.toString());
}
+ @Test
public void testNoNSPrefixByDefault() throws IOException {
Document d = DOMUtils.newDocument();
Element root = d.createElementNS("urn:foo", "root");
@@ -190,6 +199,7 @@ public class DOMElementWriterTest extend
+ StringUtils.LINE_SEP, sw.toString());
}
+ @Test
public void testNSOnElement() throws IOException {
Document d = DOMUtils.newDocument();
Element root = d.createElementNS("urn:foo", "root");
@@ -205,6 +215,7 @@ public class DOMElementWriterTest extend
+ StringUtils.LINE_SEP, sw.toString());
}
+ @Test
public void testNSPrefixOnAttribute() throws IOException {
Document d = DOMUtils.newDocument();
Element root = d.createElementNS("urn:foo", "root");
@@ -221,6 +232,7 @@ public class DOMElementWriterTest extend
+ StringUtils.LINE_SEP, sw.toString());
}
+ @Test
public void testNSPrefixOnAttributeEvenWithoutElement() throws IOException {
Document d = DOMUtils.newDocument();
Element root = d.createElementNS("urn:foo", "root");
@@ -237,6 +249,7 @@ public class DOMElementWriterTest extend
+ StringUtils.LINE_SEP, sw.toString());
}
+ @Test
public void testNSGetsReused() throws IOException {
Document d = DOMUtils.newDocument();
Element root = d.createElementNS("urn:foo", "root");
@@ -256,6 +269,7 @@ public class DOMElementWriterTest extend
+ StringUtils.LINE_SEP, sw.toString());
}
+ @Test
public void testNSGoesOutOfScope() throws IOException {
Document d = DOMUtils.newDocument();
Element root = d.createElementNS("urn:foo", "root");
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/DateUtilsTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/DateUtilsTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/DateUtilsTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/DateUtilsTest.java Fri Apr 18 21:00:38 2014
@@ -20,17 +20,18 @@ package org.apache.tools.ant.util;
import java.util.Calendar;
import java.util.TimeZone;
-import junit.framework.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
/**
* TestCase for DateUtils.
*
*/
-public class DateUtilsTest extends TestCase {
- public DateUtilsTest(String s) {
- super(s);
- }
+public class DateUtilsTest {
+
+ @Test
public void testElapsedTime(){
String text = DateUtils.formatElapsedTime(50*1000);
assertEquals("50 seconds", text);
@@ -43,6 +44,7 @@ public class DateUtilsTest extends TestC
}
// https://issues.apache.org/bugzilla/show_bug.cgi?id=44659
+ @Test
public void testLongElapsedTime(){
assertEquals("2926 minutes 13 seconds",
DateUtils.formatElapsedTime(1000 * 175573));
@@ -50,6 +52,7 @@ public class DateUtilsTest extends TestC
DateUtils.formatElapsedTime(Long.MAX_VALUE));
}
+ @Test
public void testDateTimeISO(){
TimeZone timeZone = TimeZone.getTimeZone("GMT+1");
Calendar cal = Calendar.getInstance(timeZone);
@@ -59,6 +62,7 @@ public class DateUtilsTest extends TestC
assertEquals("2002-02-23T09:11:12", text);
}
+ @Test
public void testDateISO(){
TimeZone timeZone = TimeZone.getTimeZone("GMT");
Calendar cal = Calendar.getInstance(timeZone);
@@ -68,6 +72,7 @@ public class DateUtilsTest extends TestC
assertEquals("2002-02-23", text);
}
+ @Test
public void testTimeISODate(){
// make sure that elapsed time in set via date works
TimeZone timeZone = TimeZone.getTimeZone("GMT+1");
@@ -78,6 +83,7 @@ public class DateUtilsTest extends TestC
assertEquals("20:11:12", text);
}
+ @Test
public void testTimeISO(){
// make sure that elapsed time in ms works
long ms = (20*3600 + 11*60 + 12)*1000;
@@ -86,6 +92,7 @@ public class DateUtilsTest extends TestC
assertEquals("20:11:12", text);
}
+ @Test
public void testPhaseOfMoon() {
TimeZone timeZone = TimeZone.getTimeZone("GMT");
Calendar cal = Calendar.getInstance(timeZone);
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/DeweyDecimalTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/DeweyDecimalTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/DeweyDecimalTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/DeweyDecimalTest.java Fri Apr 18 21:00:38 2014
@@ -18,7 +18,9 @@
package org.apache.tools.ant.util;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import org.junit.Test;
@SuppressWarnings("ResultOfObjectAllocationIgnored")
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java Fri Apr 18 21:00:38 2014
@@ -22,30 +22,36 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
-import junit.framework.TestCase;
-
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.taskdefs.condition.Os;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.junit.Assume.assumeTrue;
/**
* Tests for org.apache.tools.ant.util.FileUtils.
*
*/
-public class FileUtilsTest extends TestCase {
+public class FileUtilsTest {
private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
private File removeThis;
private String root;
- public FileUtilsTest(String name) {
- super(name);
- }
+ @Before
public void setUp() {
// Windows adds the drive letter in uppercase, unless you run Cygwin
root = new File(File.separator).getAbsolutePath().toUpperCase();
}
+ @After
public void tearDown() {
if (removeThis != null && removeThis.exists()) {
if (!removeThis.delete())
@@ -65,24 +71,16 @@ public class FileUtilsTest extends TestC
* @see FileUtils#setFileLastModified(java.io.File, long)
* @throws IOException
*/
+ @Test
public void testSetLastModified() throws IOException {
removeThis = new File("dummy");
FileOutputStream fos = new FileOutputStream(removeThis);
fos.write(new byte[0]);
fos.close();
+ assumeTrue("Could not change file modified time", removeThis.setLastModified(removeThis.lastModified() - 2000));
long modTime = removeThis.lastModified();
assertTrue(modTime != 0);
- /*
- * Sleep for some time to make sure a touched file would get a
- * more recent timestamp according to the file system's
- * granularity (should be > 2s to account for Windows FAT).
- */
- try {
- Thread.sleep(5000);
- } catch (InterruptedException ie) {
- fail(ie.getMessage());
- }
FILE_UTILS.setFileLastModified(removeThis, -1);
long secondModTime = removeThis.lastModified();
@@ -104,6 +102,7 @@ public class FileUtilsTest extends TestC
assertTrue(thirdModTime != secondModTime);
}
+ @Test
public void testResolveFile() {
if (!(Os.isFamily("dos") || Os.isFamily("netware"))) {
/*
@@ -203,6 +202,7 @@ public class FileUtilsTest extends TestC
}
+ @Test
public void testNormalize() {
if (!(Os.isFamily("dos") || Os.isFamily("netware"))) {
/*
@@ -324,6 +324,7 @@ public class FileUtilsTest extends TestC
/**
* Test handling of null arguments.
*/
+ @Test
public void testNullArgs() {
try {
FILE_UTILS.normalize(null);
@@ -340,6 +341,7 @@ public class FileUtilsTest extends TestC
/**
* Test createTempFile
*/
+ @Test
public void testCreateTempFile()
{
// null parent dir
@@ -391,6 +393,7 @@ public class FileUtilsTest extends TestC
/**
* Test contentEquals
*/
+ @Test
public void testContentEquals() throws IOException {
assertTrue("Non existing files", FILE_UTILS.contentEquals(new File(System.getProperty("root"), "foo"),
new File(System.getProperty("root"), "bar")));
@@ -409,6 +412,7 @@ public class FileUtilsTest extends TestC
/**
* Test createNewFile
*/
+ @Test
public void testCreateNewFile() throws IOException {
removeThis = new File("dummy");
assertTrue(!removeThis.exists());
@@ -419,6 +423,7 @@ public class FileUtilsTest extends TestC
/**
* Test removeLeadingPath.
*/
+ @Test
public void testRemoveLeadingPath() {
assertEquals("bar", FILE_UTILS.removeLeadingPath(new File("/foo"),
new File("/foo/bar")));
@@ -465,8 +470,9 @@ public class FileUtilsTest extends TestC
/**
* test toUri
*/
+ @Test
public void testToURI() {
- String dosRoot = null;
+ String dosRoot;
if (Os.isFamily("dos") || Os.isFamily("netware")) {
dosRoot = System.getProperty("user.dir")
.substring(0, 3).replace(File.separatorChar, '/');
@@ -513,17 +519,19 @@ public class FileUtilsTest extends TestC
}
}
+ @Test
public void testIsContextRelativePath() {
- if (Os.isFamily("dos")) {
- assertTrue(FileUtils.isContextRelativePath("/\u00E4nt"));
- assertTrue(FileUtils.isContextRelativePath("\\foo"));
- }
+ assumeTrue("Test only runs on DOS", Os.isFamily("dos"));
+ assertTrue(FileUtils.isContextRelativePath("/\u00E4nt"));
+ assertTrue(FileUtils.isContextRelativePath("\\foo"));
}
+
/**
* test fromUri
*/
+ @Test
public void testFromURI() {
- String dosRoot = null;
+ String dosRoot;
if (Os.isFamily("dos") || Os.isFamily("netware")) {
dosRoot = System.getProperty("user.dir").substring(0, 2);
} else {
@@ -542,6 +550,7 @@ public class FileUtilsTest extends TestC
assertEquals(dosRoot + File.separator + "foo#bar", FILE_UTILS.fromURI("file:///foo%23bar"));
}
+ @Test
public void testModificationTests() {
//get a time
@@ -564,6 +573,7 @@ public class FileUtilsTest extends TestC
!FILE_UTILS.isUpToDate(firstTime,-1L));
}
+ @Test
public void testHasErrorInCase() {
File tempFolder = new File(System.getProperty("java.io.tmpdir"));
File wellcased = FILE_UTILS.createTempFile("alpha", "beta", tempFolder,
@@ -603,8 +613,8 @@ public class FileUtilsTest extends TestC
private void assertEqualsIgnoreDriveCase(String s1, String s2) {
if ((Os.isFamily("dos") || Os.isFamily("netware"))
&& s1.length() > 0 && s2.length() > 0) {
- StringBuffer sb1 = new StringBuffer(s1);
- StringBuffer sb2 = new StringBuffer(s2);
+ StringBuilder sb1 = new StringBuilder(s1);
+ StringBuilder sb2 = new StringBuilder(s2);
sb1.setCharAt(0, Character.toUpperCase(s1.charAt(0)));
sb2.setCharAt(0, Character.toUpperCase(s2.charAt(0)));
assertEquals(sb1.toString(), sb2.toString());
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/GlobPatternMapperTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/GlobPatternMapperTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/GlobPatternMapperTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/GlobPatternMapperTest.java Fri Apr 18 21:00:38 2014
@@ -18,18 +18,19 @@
package org.apache.tools.ant.util;
-import junit.framework.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
/**
* Tests for org.apache.tools.ant.util;GlobPatternMapper.
*
*/
-public class GlobPatternMapperTest extends TestCase {
-
- public GlobPatternMapperTest(String name) {
- super(name);
- }
+public class GlobPatternMapperTest {
+ @Test
public void testNoPatternAtAll() {
GlobPatternMapper m = new GlobPatternMapper();
m.setFrom("foobar");
@@ -41,6 +42,7 @@ public class GlobPatternMapperTest exten
assertEquals("baz", result[0]);
}
+ @Test
public void testPostfixOnly() {
GlobPatternMapper m = new GlobPatternMapper();
m.setFrom("*foo");
@@ -57,6 +59,7 @@ public class GlobPatternMapperTest exten
assertEquals("foobar.", result[0]);
}
+ @Test
public void testPrefixOnly() {
GlobPatternMapper m = new GlobPatternMapper();
m.setFrom("foo*");
@@ -73,6 +76,7 @@ public class GlobPatternMapperTest exten
assertEquals(".barfoo", result[0]);
}
+ @Test
public void testPreAndPostfix() {
GlobPatternMapper m = new GlobPatternMapper();
m.setFrom("foo*bar");
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/JAXPUtilsTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/JAXPUtilsTest.java?rev=1588563&r1=1588562&r2=1588563&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/JAXPUtilsTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/JAXPUtilsTest.java Fri Apr 18 21:00:38 2014
@@ -17,18 +17,18 @@
*/
package org.apache.tools.ant.util;
-import junit.framework.TestCase;
+import org.junit.Test;
import java.io.File;
+import static org.junit.Assert.assertTrue;
+
/**
* JAXPUtils test case
*/
-public class JAXPUtilsTest extends TestCase {
- public JAXPUtilsTest(String name){
- super(name);
- }
+public class JAXPUtilsTest {
+ @Test
public void testGetSystemId(){
File file = null;
if ( File.separatorChar == '\\' ){