1 17 package org.apache.tools.ant.taskdefs; 18 19 import java.util.Calendar ; 20 import java.util.TimeZone ; 21 import java.util.Date ; 22 import java.text.SimpleDateFormat ; 23 24 import junit.framework.TestCase; 25 import org.apache.tools.ant.Project; 26 import org.apache.tools.ant.Location; 27 28 31 public class TStampTest extends TestCase { 32 33 protected Tstamp tstamp; 34 protected Project project; 35 protected Location location; 36 37 public TStampTest(String s) { 38 super(s); 39 } 40 41 protected void setUp() throws Exception { 42 location = new Location("test.xml"); 43 project = new Project(); 44 tstamp = new Tstamp(); 45 tstamp.setLocation(location); 46 tstamp.setProject(project); 47 } 48 49 public void testTimeZone() throws Exception { 50 Tstamp.CustomFormat format = tstamp.createFormat(); 51 format.setProperty("today"); 52 format.setPattern("HH:mm:ss z"); 53 format.setTimezone("GMT"); 54 Date date = Calendar.getInstance().getTime(); 55 format.execute(project, date, location); 56 String today = project.getProperty("today"); 57 58 SimpleDateFormat sdf = new SimpleDateFormat ("HH:mm:ss z"); 59 sdf.setTimeZone( TimeZone.getTimeZone("GMT") ); 60 String expected = sdf.format(date); 61 62 assertEquals(expected, today); 63 } 64 65 70 public void testWriteOrder() throws Exception { 71 Tstamp.CustomFormat format = tstamp.createFormat(); 72 format.setProperty("TODAY"); 73 format.setPattern("HH:mm:ss z"); 74 format.setTimezone("GMT"); 75 Date date = Calendar.getInstance().getTime(); 76 format.execute(project, date, location); 77 String today = project.getProperty("TODAY"); 78 79 SimpleDateFormat sdf = new SimpleDateFormat ("HH:mm:ss z"); 80 sdf.setTimeZone( TimeZone.getTimeZone("GMT") ); 81 String expected = sdf.format(date); 82 83 assertEquals(expected, today); 84 85 } 86 87 92 public void testPrefix() throws Exception { 93 tstamp.setPrefix("prefix"); 94 tstamp.execute(); 95 String prop= project.getProperty("prefix.DSTAMP"); 96 assertNotNull(prop); 97 } 98 99 public void testFormatPrefix() throws Exception { 100 Tstamp.CustomFormat format = tstamp.createFormat(); 101 format.setProperty("format"); 102 format.setPattern("HH:mm:ss z"); 103 format.setTimezone("GMT"); 104 105 tstamp.setPrefix("prefix"); 106 tstamp.execute(); 107 String prop= project.getProperty("prefix.format"); 108 assertNotNull(prop); 109 } 110 111 } 112 | Popular Tags |