1 16 package org.joda.time.format; 17 18 import junit.framework.TestCase; 19 import junit.framework.TestSuite; 20 21 26 public class TestDateTimeFormatterBuilder extends TestCase { 27 28 public static void main(String [] 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 name) { 37 super(name); 38 } 39 40 protected void setUp() throws Exception { 41 } 42 43 protected void tearDown() throws Exception { 44 } 45 46 public void test_toFormatter() { 48 DateTimeFormatterBuilder bld = new DateTimeFormatterBuilder(); 49 try { 50 bld.toFormatter(); 51 fail(); 52 } catch (UnsupportedOperationException 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 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 ex) {} 73 bld.appendLiteral('X'); 74 assertNotNull(bld.toParser()); 75 } 76 77 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 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 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 |