source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/testcases/org/apache/tools/ant/taskdefs/TStampTest.java@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

File size: 3.4 KB
Line 
1/*
2 * Copyright 2001-2002,2004 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17package org.apache.tools.ant.taskdefs;
18
19import java.util.Calendar;
20import java.util.TimeZone;
21import java.util.Date;
22import java.text.SimpleDateFormat;
23
24import junit.framework.TestCase;
25import org.apache.tools.ant.Project;
26import org.apache.tools.ant.Location;
27
28/**
29 *
30 */
31public 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 /**
66 * verifies that custom props have priority over the
67 * originals
68 * @throws Exception
69 */
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 /**
88 * verifies that custom props have priority over the
89 * originals
90 * @throws Exception
91 */
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}
Note: See TracBrowser for help on using the repository browser.