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 22 import junit.framework.TestCase; 23 import junit.framework.TestSuite; 24 25 import org.joda.time.Chronology; 26 import org.joda.time.DateTimeZone; 27 import org.joda.time.PeriodType; 28 import org.joda.time.MutablePeriod; 29 import org.joda.time.ReadablePeriod; 30 import org.joda.time.Period; 31 import org.joda.time.chrono.ISOChronology; 32 import org.joda.time.chrono.JulianChronology; 33 34 39 public class TestReadablePeriodConverter extends TestCase { 40 41 private static final DateTimeZone UTC = DateTimeZone.UTC; 42 private static final DateTimeZone PARIS = DateTimeZone.forID("Europe/Paris"); 43 private static final Chronology ISO_PARIS = ISOChronology.getInstance(PARIS); 44 private static Chronology JULIAN; 45 private static Chronology ISO; 46 47 private DateTimeZone zone = null; 48 49 public static void main(String [] args) { 50 junit.textui.TestRunner.run(suite()); 51 } 52 53 public static TestSuite suite() { 54 return new TestSuite(TestReadablePeriodConverter.class); 55 } 56 57 public TestReadablePeriodConverter(String name) { 58 super(name); 59 } 60 61 protected void setUp() throws Exception { 62 JULIAN = JulianChronology.getInstance(); 63 ISO = ISOChronology.getInstance(); 64 } 65 66 public void testSingleton() throws Exception { 68 Class cls = ReadablePeriodConverter.class; 69 assertEquals(false, Modifier.isPublic(cls.getModifiers())); 70 assertEquals(false, Modifier.isProtected(cls.getModifiers())); 71 assertEquals(false, Modifier.isPrivate(cls.getModifiers())); 72 73 Constructor con = cls.getDeclaredConstructor((Class []) null); 74 assertEquals(1, cls.getDeclaredConstructors().length); 75 assertEquals(true, Modifier.isProtected(con.getModifiers())); 76 77 Field fld = cls.getDeclaredField("INSTANCE"); 78 assertEquals(false, Modifier.isPublic(fld.getModifiers())); 79 assertEquals(false, Modifier.isProtected(fld.getModifiers())); 80 assertEquals(false, Modifier.isPrivate(fld.getModifiers())); 81 } 82 83 public void testSupportedType() throws Exception { 85 assertEquals(ReadablePeriod.class, ReadablePeriodConverter.INSTANCE.getSupportedType()); 86 } 87 88 public void testGetPeriodType_Object() throws Exception { 90 assertEquals(PeriodType.standard(), 91 ReadablePeriodConverter.INSTANCE.getPeriodType(new Period(123L, PeriodType.standard()))); 92 assertEquals(PeriodType.yearMonthDayTime(), 93 ReadablePeriodConverter.INSTANCE.getPeriodType(new Period(123L, PeriodType.yearMonthDayTime()))); 94 } 95 96 public void testSetInto_Object() throws Exception { 97 MutablePeriod m = new MutablePeriod(PeriodType.yearMonthDayTime()); 98 ReadablePeriodConverter.INSTANCE.setInto(m, new Period(0, 0, 0, 3, 0, 4, 0, 5), null); 99 assertEquals(0, m.getYears()); 100 assertEquals(0, m.getMonths()); 101 assertEquals(0, m.getWeeks()); 102 assertEquals(3, m.getDays()); 103 assertEquals(0, m.getHours()); 104 assertEquals(4, m.getMinutes()); 105 assertEquals(0, m.getSeconds()); 106 assertEquals(5, m.getMillis()); 107 } 108 109 public void testToString() { 111 assertEquals("Converter[org.joda.time.ReadablePeriod]", ReadablePeriodConverter.INSTANCE.toString()); 112 } 113 114 } 115 | Popular Tags |