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