1 16 package net.sf.dozer.util.mapping.converters; 17 18 import java.text.DateFormat ; 19 20 import net.sf.dozer.util.mapping.DozerTestBase; 21 import net.sf.dozer.util.mapping.util.DateFormatContainer; 22 23 26 public class ConverterTest extends DozerTestBase { 27 30 public void testAccessors() throws Exception { 31 DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.LONG); 32 33 CalendarConverter cc = new CalendarConverter(null); 34 cc.setDateFormat(dateFormat); 35 assertEquals(dateFormat, cc.getDateFormat()); 36 37 DateConverter dc = new DateConverter(null); 38 dc.setDateFormat(dateFormat); 39 assertEquals(dateFormat, dc.getDateFormat()); 40 41 StringConverter sc = new StringConverter(null); 42 DateFormatContainer dfc = new DateFormatContainer(null, null); 43 sc.setDateFormat(dfc); 44 assertEquals(dfc, sc.getDateFormat()); 45 } 46 47 public void testInvalidDateInput() throws Exception { 48 DateConverter dc = new DateConverter(DateFormat.getDateInstance(DateFormat.LONG)); 49 try { 50 dc.convert(java.util.Date .class, "jfdlajf"); 51 fail("should have thrown ConversionException"); 52 } catch (ConversionException e) { 53 } 54 55 try { 56 dc = new DateConverter(null); 58 dc.convert(String .class, "123"); 59 fail("should have thrown ConversionException"); 60 } catch (ConversionException e) { 61 } 62 } 63 64 public void testInvalidCalendarInput() throws Exception { 65 CalendarConverter dc = new CalendarConverter(DateFormat.getDateInstance(DateFormat.LONG)); 66 try { 67 dc.convert(java.util.GregorianCalendar .class, "jfdlajf"); 68 fail("should have thrown ConversionException"); 69 } catch (ConversionException e) { 70 } 71 } 72 } 73 | Popular Tags |