KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > dozer > util > mapping > converters > ConverterTest


1 /*
2  * Copyright 2005-2007 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package net.sf.dozer.util.mapping.converters;
17
18 import java.text.DateFormat JavaDoc;
19
20 import net.sf.dozer.util.mapping.DozerTestBase;
21 import net.sf.dozer.util.mapping.util.DateFormatContainer;
22
23 /**
24  * @author tierney.matt
25  */

26 public class ConverterTest extends DozerTestBase {
27   /*
28   * See DataConvertionTest for more thorough data conversion unit tests
29   */

30   public void testAccessors() throws Exception JavaDoc {
31     DateFormat JavaDoc 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 JavaDoc {
48     DateConverter dc = new DateConverter(DateFormat.getDateInstance(DateFormat.LONG));
49     try {
50       dc.convert(java.util.Date JavaDoc.class, "jfdlajf");
51       fail("should have thrown ConversionException");
52     } catch (ConversionException e) {
53     }
54
55     try {
56       //no long constructor
57
dc = new DateConverter(null);
58       dc.convert(String JavaDoc.class, "123");
59       fail("should have thrown ConversionException");
60     } catch (ConversionException e) {
61     }
62   }
63
64   public void testInvalidCalendarInput() throws Exception JavaDoc {
65     CalendarConverter dc = new CalendarConverter(DateFormat.getDateInstance(DateFormat.LONG));
66     try {
67       dc.convert(java.util.GregorianCalendar JavaDoc.class, "jfdlajf");
68       fail("should have thrown ConversionException");
69     } catch (ConversionException e) {
70     }
71   }
72 }
73
Popular Tags