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 FormatConverter class.
032 *
033 * @author Henri Yandell
034 * @version $Id: FormatConverterTestCase.java 155441 2005-02-26 13:19:22Z dirkv $
035 */
036
037 public class FormatConverterTestCase extends TestCase {
038
039 // ------------------------------------------------------------------------
040
041 public FormatConverterTestCase(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(FormatConverterTestCase.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 FormatConverter fc = new FormatConverter(format);
062 assertEquals( "5.4", fc.convert( String.class, new Double(5.43) ) );
063 }
064
065 public void testDateFormat() {
066 Format format = new SimpleDateFormat("dd MM yyyy");
067 FormatConverter fc = new FormatConverter(format);
068 assertEquals( "31 12 1969", fc.convert( String.class, new Date(0) ) );
069 }
070 }
071