All Downloads are FREE. Search and download functionalities are using the official Maven repository.

at.spardat.enterprise.fmt.test.ADateFmtMediumSmartTest Maven / Gradle / Ivy

There is a newer version: 6.0.2
Show newest version
/*
 * @(#) $Id: ADateFmtMediumSmartTest.java 8163 2011-07-12 15:50:39Z laslovd $
 *
 * Copyright 2009/2010 by sIT Solutions,
 * A-1110 Wien, Geiselbergstr.21-25.
 * All rights reserved.
 *
 */
package at.spardat.enterprise.fmt.test;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import junit.framework.TestCase;
import at.spardat.enterprise.fmt.ADateFmt;
import at.spardat.enterprise.fmt.ADateFmtMediumSmart;
import at.spardat.enterprise.fmt.FmtParseException;

public class ADateFmtMediumSmartTest extends TestCase {
    public void testSmartFormatting () {
        SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
        String ref = df.format(new Date());
        String ys = ref.substring(0,4);
        String ms = ref.substring(4,6);

        ADateFmt fmt = ADateFmtMediumSmart.getInstance(ADateFmt.MEDIUM,Locale.GERMAN);

        String internal = fmt.parse("24.5.2037");
        assertEquals("20370524",internal);
        internal = fmt.parse("24052037");
        assertEquals("20370524",internal);
        internal = fmt.parse("240537");
        assertEquals("20370524",internal);
        internal = fmt.parse("2405");
        assertEquals(ys + "0524",internal);
        internal = fmt.parse("24");
        assertEquals(ys + ms + "24",internal);
        internal = fmt.parse("1");
        assertEquals(ys + ms + "01",internal);
        internal = fmt.parse("105");
        assertEquals(ys + "0501",internal);
        internal = fmt.parse("101");
        assertEquals(ys + "0101",internal);
        internal = fmt.parse("10137");
        assertEquals("20370101",internal);
        internal = fmt.parse("311237");
        assertEquals("20371231",internal);
        internal = fmt.parse("24050037");
        assertEquals("00370524",internal);

        try {
            internal = fmt.parse("3002");
            fail("expected FmtParseException was not thrown!");
        } catch ( FmtParseException ex ) {}
        try {
            internal = fmt.parse("9876");
            fail("expected FmtParseException was not thrown!");
        } catch ( FmtParseException ex ) {}
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy