1 17 18 package org.apache.tools.ant.util; 19 20 import junit.framework.Test; 21 import junit.framework.TestCase; 22 import junit.framework.TestSuite; 23 24 28 public class GlobPatternMapperTest extends TestCase { 29 30 public GlobPatternMapperTest(String name) { 31 super(name); 32 } 33 34 public void testNoPatternAtAll() { 35 GlobPatternMapper m = new GlobPatternMapper(); 36 m.setFrom("foobar"); 37 m.setTo("baz"); 38 assertNull("Shouldn\'t match foobar", m.mapFileName("plonk")); 39 String [] result = m.mapFileName("foobar"); 40 assertNotNull("Should match foobar", result); 41 assertEquals("only one result for foobar", 1, result.length); 42 assertEquals("baz", result[0]); 43 } 44 45 public void testPostfixOnly() { 46 GlobPatternMapper m = new GlobPatternMapper(); 47 m.setFrom("*foo"); 48 m.setTo("*plonk"); 49 assertNull("Shouldn\'t match *foo", m.mapFileName("bar.baz")); 50 String [] result = m.mapFileName("bar.foo"); 51 assertNotNull("Should match *.foo", result); 52 assertEquals("only one result for bar.foo", 1, result.length); 53 assertEquals("bar.plonk", result[0]); 54 55 m.setTo("foo*"); 57 result = m.mapFileName("bar.foo"); 58 assertEquals("foobar.", result[0]); 59 } 60 61 public void testPrefixOnly() { 62 GlobPatternMapper m = new GlobPatternMapper(); 63 m.setFrom("foo*"); 64 m.setTo("plonk*"); 65 assertNull("Shouldn\'t match foo*", m.mapFileName("bar.baz")); 66 String [] result = m.mapFileName("foo.bar"); 67 assertNotNull("Should match foo*", result); 68 assertEquals("only one result for foo.bar", 1, result.length); 69 assertEquals("plonk.bar", result[0]); 70 71 m.setTo("*foo"); 73 result = m.mapFileName("foo.bar"); 74 assertEquals(".barfoo", result[0]); 75 } 76 77 public void testPreAndPostfix() { 78 GlobPatternMapper m = new GlobPatternMapper(); 79 m.setFrom("foo*bar"); 80 m.setTo("plonk*pling"); 81 assertNull("Shouldn\'t match foo*bar", m.mapFileName("bar.baz")); 82 String [] result = m.mapFileName("foo.bar"); 83 assertNotNull("Should match foo*bar", result); 84 assertEquals("only one result for foo.bar", 1, result.length); 85 assertEquals("plonk.pling", result[0]); 86 87 result = m.mapFileName("foo.baz.bar"); 89 assertNotNull("Should match foo*bar", result); 90 assertEquals("only one result for foo.baz.bar", 1, result.length); 91 assertEquals("plonk.baz.pling", result[0]); 92 93 result = m.mapFileName("foobar"); 95 assertNotNull("Should match foo*bar", result); 96 assertEquals("only one result for foobar", 1, result.length); 97 assertEquals("plonkpling", result[0]); 98 } 99 } 100 | Popular Tags |