001 /*
002 * Copyright 2003-2004 The Apache Software Foundation
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.apache.commons.convert1.format;
017
018 import junit.framework.TestCase;
019 import junit.framework.TestSuite;
020
021 import java.text.Format;
022 import java.text.SimpleDateFormat;
023 import java.text.DecimalFormat;
024
025 import java.util.Date;
026
027 import org.apache.commons.convert1.Converter;
028
029
030 /**
031 * Test Case for the ParseConverter class.
032 *
033 * @author Henri Yandell
034 * @version $Id: ParseConverterTestCase.java 155441 2005-02-26 13:19:22Z dirkv $
035 */
036
037 public class ParseConverterTestCase extends TestCase {
038
039 // ------------------------------------------------------------------------
040
041 public ParseConverterTestCase(String name) {
042 super(name);
043 }
044
045 // ------------------------------------------------------------------------
046
047 public void setUp() throws Exception {
048 }
049
050 public static TestSuite suite() {
051 return new TestSuite(ParseConverterTestCase.class);
052 }
053
054 public void tearDown() throws Exception {
055 }
056
057 // ------------------------------------------------------------------------
058
059 public void testNumberFormat() {
060 Format format = new DecimalFormat("0.0");
061 ParseConverter fc = new ParseConverter(format);
062 assertEquals( 5.43, ((Number)fc.convert( java.lang.Float.class, "5.43")).doubleValue(), 0 );
063 }
064
065 public void testDateFormat() {
066 // Have to deal with Locale's here to get a working test
067 // which pretty much means we ought to go ahead and solve Locales
068 /*
069 Format format = new SimpleDateFormat("dd MM yyyy zzz");
070 ParseConverter fc = new ParseConverter(format);
071 assertEquals( new Date(0), fc.convert( java.util.Date.class, "31 12 1969 GMT" ) );
072 */
073 }
074 }
075