1 16 package org.joda.time.convert; 17 18 import java.lang.reflect.Constructor ; 19 import java.lang.reflect.Field ; 20 import java.lang.reflect.Modifier ; 21 import java.util.Arrays ; 22 23 import junit.framework.TestCase; 24 import junit.framework.TestSuite; 25 26 import org.joda.time.Chronology; 27 import org.joda.time.DateTimeZone; 28 import org.joda.time.TimeOfDay; 29 import org.joda.time.chrono.ISOChronology; 30 import org.joda.time.chrono.JulianChronology; 31 32 37 public class TestLongConverter extends TestCase { 38 39 private static final DateTimeZone UTC = DateTimeZone.UTC; 40 private static final DateTimeZone PARIS = DateTimeZone.forID("Europe/Paris"); 41 private static final Chronology ISO_PARIS = ISOChronology.getInstance(PARIS); 42 private static Chronology JULIAN; 43 private static Chronology ISO; 44 45 private DateTimeZone zone = null; 46 47 public static void main(String [] args) { 48 junit.textui.TestRunner.run(suite()); 49 } 50 51 public static TestSuite suite() { 52 return new TestSuite(TestLongConverter.class); 53 } 54 55 public TestLongConverter(String name) { 56 super(name); 57 } 58 59 protected void setUp() throws Exception { 60 JULIAN = JulianChronology.getInstance(); 61 ISO = ISOChronology.getInstance(); 62 } 63 64 public void testSingleton() throws Exception { 66 Class cls = LongConverter.class; 67 assertEquals(false, Modifier.isPublic(cls.getModifiers())); 68 assertEquals(false, Modifier.isProtected(cls.getModifiers())); 69 assertEquals(false, Modifier.isPrivate(cls.getModifiers())); 70 71 Constructor con = cls.getDeclaredConstructor((Class []) null); 72 assertEquals(1, cls.getDeclaredConstructors().length); 73 assertEquals(true, Modifier.isProtected(con.getModifiers())); 74 75 Field fld = cls.getDeclaredField("INSTANCE"); 76 assertEquals(false, Modifier.isPublic(fld.getModifiers())); 77 assertEquals(false, Modifier.isProtected(fld.getModifiers())); 78 assertEquals(false, Modifier.isPrivate(fld.getModifiers())); 79 } 80 81 public void testSupportedType() throws Exception { 83 assertEquals(Long .class, LongConverter.INSTANCE.getSupportedType()); 84 } 85 86 public void testGetInstantMillis_Object_Chronology() throws Exception { 88 assertEquals(123L, LongConverter.INSTANCE.getInstantMillis(new Long (123L), JULIAN)); 89 assertEquals(123L, LongConverter.INSTANCE.getInstantMillis(new Long (123L), (Chronology) null)); 90 } 91 92 public void testGetChronology_Object_Zone() throws Exception { 94 assertEquals(ISO_PARIS, LongConverter.INSTANCE.getChronology(new Long (123L), PARIS)); 95 assertEquals(ISO, LongConverter.INSTANCE.getChronology(new Long (123L), (DateTimeZone) null)); 96 } 97 98 public void testGetChronology_Object_Chronology() throws Exception { 99 assertEquals(JULIAN, LongConverter.INSTANCE.getChronology(new Long (123L), JULIAN)); 100 assertEquals(ISO, LongConverter.INSTANCE.getChronology(new Long (123L), (Chronology) null)); 101 } 102 103 public void testGetPartialValues() throws Exception { 105 TimeOfDay tod = new TimeOfDay(); 106 int[] expected = ISOChronology.getInstance().get(tod, 12345678L); 107 int[] actual = LongConverter.INSTANCE.getPartialValues(tod, new Long (12345678L), ISOChronology.getInstance()); 108 assertEquals(true, Arrays.equals(expected, actual)); 109 } 110 111 public void testGetDurationMillis_Object() throws Exception { 113 assertEquals(123L, LongConverter.INSTANCE.getDurationMillis(new Long (123L))); 114 } 115 116 public void testToString() { 118 assertEquals("Converter[java.lang.Long]", LongConverter.INSTANCE.toString()); 119 } 120 121 } 122 | Popular Tags |