KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > joda > time > format > TestDateTimeFormatterBuilder


1 /*
2  * Copyright 2001-2005 Stephen Colebourne
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 package org.joda.time.format;
17
18 import junit.framework.TestCase;
19 import junit.framework.TestSuite;
20
21 /**
22  * This class is a Junit unit test for DateTimeFormatterBuilder.
23  *
24  * @author Stephen Colebourne
25  */

26 public class TestDateTimeFormatterBuilder extends TestCase {
27
28     public static void main(String JavaDoc[] args) {
29         junit.textui.TestRunner.run(suite());
30     }
31
32     public static TestSuite suite() {
33         return new TestSuite(TestDateTimeFormatterBuilder.class);
34     }
35
36     public TestDateTimeFormatterBuilder(String JavaDoc name) {
37         super(name);
38     }
39
40     protected void setUp() throws Exception JavaDoc {
41     }
42
43     protected void tearDown() throws Exception JavaDoc {
44     }
45
46     //-----------------------------------------------------------------------
47
public void test_toFormatter() {
48         DateTimeFormatterBuilder bld = new DateTimeFormatterBuilder();
49         try {
50             bld.toFormatter();
51             fail();
52         } catch (UnsupportedOperationException JavaDoc ex) {}
53         bld.appendLiteral('X');
54         assertNotNull(bld.toFormatter());
55     }
56
57     public void test_toPrinter() {
58         DateTimeFormatterBuilder bld = new DateTimeFormatterBuilder();
59         try {
60             bld.toPrinter();
61             fail();
62         } catch (UnsupportedOperationException JavaDoc ex) {}
63         bld.appendLiteral('X');
64         assertNotNull(bld.toPrinter());
65     }
66
67     public void test_toParser() {
68         DateTimeFormatterBuilder bld = new DateTimeFormatterBuilder();
69         try {
70             bld.toParser();
71             fail();
72         } catch (UnsupportedOperationException JavaDoc ex) {}
73         bld.appendLiteral('X');
74         assertNotNull(bld.toParser());
75     }
76
77     //-----------------------------------------------------------------------
78
public void test_canBuildFormatter() {
79         DateTimeFormatterBuilder bld = new DateTimeFormatterBuilder();
80         assertEquals(false, bld.canBuildFormatter());
81         bld.appendLiteral('X');
82         assertEquals(true, bld.canBuildFormatter());
83     }
84
85     public void test_canBuildPrinter() {
86         DateTimeFormatterBuilder bld = new DateTimeFormatterBuilder();
87         assertEquals(false, bld.canBuildPrinter());
88         bld.appendLiteral('X');
89         assertEquals(true, bld.canBuildPrinter());
90     }
91
92     public void test_canBuildParser() {
93         DateTimeFormatterBuilder bld = new DateTimeFormatterBuilder();
94         assertEquals(false, bld.canBuildParser());
95         bld.appendLiteral('X');
96         assertEquals(true, bld.canBuildParser());
97     }
98
99     //-----------------------------------------------------------------------
100
public void test_append_Formatter() {
101         DateTimeFormatterBuilder bld = new DateTimeFormatterBuilder();
102         bld.appendLiteral('Y');
103         DateTimeFormatter f = bld.toFormatter();
104         
105         DateTimeFormatterBuilder bld2 = new DateTimeFormatterBuilder();
106         bld2.appendLiteral('X');
107         bld2.append(f);
108         bld2.appendLiteral('Z');
109         assertEquals("XYZ", bld2.toFormatter().print(0L));
110     }
111
112     //-----------------------------------------------------------------------
113
public void test_append_Printer() {
114         DateTimeFormatterBuilder bld = new DateTimeFormatterBuilder();
115         bld.appendLiteral('Y');
116         DateTimePrinter p = bld.toPrinter();
117         
118         DateTimeFormatterBuilder bld2 = new DateTimeFormatterBuilder();
119         bld2.appendLiteral('X');
120         bld2.append(p);
121         bld2.appendLiteral('Z');
122         assertEquals("XYZ", bld2.toFormatter().print(0L));
123     }
124
125 }
126
Popular Tags