Search in sources :

Example 61 with FieldPosition

use of java.text.FieldPosition in project robovm by robovm.

the class OldFieldPositionTest method test_hashCode.

public void test_hashCode() {
    // Test for method int java.text.FieldPosition.hashCode()
    FieldPosition fpos1 = new FieldPosition(1);
    FieldPosition fpos2 = new FieldPosition(1);
    assertTrue("test 1: hash codes are not equal for equal objects.", fpos1.hashCode() == fpos2.hashCode());
    fpos1.setBeginIndex(5);
    fpos1.setEndIndex(110);
    assertTrue("test 2: hash codes are equal for non equal objects.", fpos1.hashCode() != fpos2.hashCode());
    fpos2.setBeginIndex(5);
    fpos2.setEndIndex(110);
    assertTrue("test 3: hash codes are not equal for equal objects.", fpos1.hashCode() == fpos2.hashCode());
    FieldPosition fpos3 = new FieldPosition(DateFormat.Field.DAY_OF_WEEK_IN_MONTH);
    assertTrue("test 4: hash codes are equal for non equal objects.", fpos2.hashCode() != fpos3.hashCode());
}
Also used : FieldPosition(java.text.FieldPosition)

Example 62 with FieldPosition

use of java.text.FieldPosition in project robovm by robovm.

the class OldFieldPositionTest method test_setBeginIndexI.

public void test_setBeginIndexI() {
    // Test for method void java.text.FieldPosition.setBeginIndex(int)
    FieldPosition fpos = new FieldPosition(1);
    fpos.setBeginIndex(2);
    fpos.setEndIndex(3);
    assertEquals("beginIndex should have been set to 2", 2, fpos.getBeginIndex());
    fpos.setBeginIndex(Integer.MAX_VALUE);
    assertEquals("beginIndex should have been set to Integer.MAX_VALUE", Integer.MAX_VALUE, fpos.getBeginIndex());
    fpos.setBeginIndex(-1);
    assertEquals("beginIndex should have been set to -1", -1, fpos.getBeginIndex());
}
Also used : FieldPosition(java.text.FieldPosition)

Example 63 with FieldPosition

use of java.text.FieldPosition in project robovm by robovm.

the class OldSimpleDateFormatTest method test_formatLjava_util_DateLjava_lang_StringBufferLjava_text_FieldPosition.

public void test_formatLjava_util_DateLjava_lang_StringBufferLjava_text_FieldPosition() {
    FormatTester test = new FormatTester();
    Calendar cal = new GregorianCalendar(1999, Calendar.JUNE, 2, 15, 3, 6);
    test.test(" G", cal, " AD", DateFormat.ERA_FIELD);
    test.test(" GG", cal, " AD", DateFormat.ERA_FIELD);
    test.test(" GGG", cal, " AD", DateFormat.ERA_FIELD);
    test.test(" G", new GregorianCalendar(-1999, Calendar.JUNE, 2), " BC", DateFormat.ERA_FIELD);
    test.test(" M", cal, " 6", DateFormat.MONTH_FIELD);
    test.test(" M", new GregorianCalendar(1999, Calendar.NOVEMBER, 2), " 11", DateFormat.MONTH_FIELD);
    test.test(" MM", cal, " 06", DateFormat.MONTH_FIELD);
    test.test(" MMM", cal, " Jun", DateFormat.MONTH_FIELD);
    test.test(" MMMM", cal, " June", DateFormat.MONTH_FIELD);
    test.test(" MMMMM", cal, " J", DateFormat.MONTH_FIELD);
    test.test(" d", cal, " 2", DateFormat.DATE_FIELD);
    test.test(" d", new GregorianCalendar(1999, Calendar.NOVEMBER, 12), " 12", DateFormat.DATE_FIELD);
    test.test(" dd", cal, " 02", DateFormat.DATE_FIELD);
    test.test(" dddd", cal, " 0002", DateFormat.DATE_FIELD);
    test.test(" h", cal, " 3", DateFormat.HOUR1_FIELD);
    test.test(" h", new GregorianCalendar(1999, Calendar.NOVEMBER, 12), " 12", DateFormat.HOUR1_FIELD);
    test.test(" hh", cal, " 03", DateFormat.HOUR1_FIELD);
    test.test(" hhhh", cal, " 0003", DateFormat.HOUR1_FIELD);
    test.test(" H", cal, " 15", DateFormat.HOUR_OF_DAY0_FIELD);
    test.test(" H", new GregorianCalendar(1999, Calendar.NOVEMBER, 12, 4, 0), " 4", DateFormat.HOUR_OF_DAY0_FIELD);
    test.test(" H", new GregorianCalendar(1999, Calendar.NOVEMBER, 12, 12, 0), " 12", DateFormat.HOUR_OF_DAY0_FIELD);
    test.test(" H", new GregorianCalendar(1999, Calendar.NOVEMBER, 12), " 0", DateFormat.HOUR_OF_DAY0_FIELD);
    test.test(" HH", cal, " 15", DateFormat.HOUR_OF_DAY0_FIELD);
    test.test(" HHHH", cal, " 0015", DateFormat.HOUR_OF_DAY0_FIELD);
    test.test(" m", cal, " 3", DateFormat.MINUTE_FIELD);
    test.test(" m", new GregorianCalendar(1999, Calendar.NOVEMBER, 12, 4, 47), " 47", DateFormat.MINUTE_FIELD);
    test.test(" mm", cal, " 03", DateFormat.MINUTE_FIELD);
    test.test(" mmmm", cal, " 0003", DateFormat.MINUTE_FIELD);
    test.test(" s", cal, " 6", DateFormat.SECOND_FIELD);
    test.test(" s", new GregorianCalendar(1999, Calendar.NOVEMBER, 12, 4, 47, 13), " 13", DateFormat.SECOND_FIELD);
    test.test(" ss", cal, " 06", DateFormat.SECOND_FIELD);
    test.test(" ssss", cal, " 0006", DateFormat.SECOND_FIELD);
    test.test(" S", cal, " 0", DateFormat.MILLISECOND_FIELD);
    Calendar temp = new GregorianCalendar();
    temp.set(Calendar.MILLISECOND, 961);
    test.test(" SS", temp, " 961", DateFormat.MILLISECOND_FIELD);
    test.test(" SSSS", cal, " 0000", DateFormat.MILLISECOND_FIELD);
    test.test(" SS", cal, " 00", DateFormat.MILLISECOND_FIELD);
    test.test(" E", cal, " Wed", DateFormat.DAY_OF_WEEK_FIELD);
    test.test(" EE", cal, " Wed", DateFormat.DAY_OF_WEEK_FIELD);
    test.test(" EEE", cal, " Wed", DateFormat.DAY_OF_WEEK_FIELD);
    test.test(" EEEE", cal, " Wednesday", DateFormat.DAY_OF_WEEK_FIELD);
    test.test(" EEEEE", cal, " W", DateFormat.DAY_OF_WEEK_FIELD);
    test.test(" D", cal, " 153", DateFormat.DAY_OF_YEAR_FIELD);
    test.test(" DD", cal, " 153", DateFormat.DAY_OF_YEAR_FIELD);
    test.test(" DDDD", cal, " 0153", DateFormat.DAY_OF_YEAR_FIELD);
    test.test(" F", cal, " 1", DateFormat.DAY_OF_WEEK_IN_MONTH_FIELD);
    test.test(" F", new GregorianCalendar(1999, Calendar.NOVEMBER, 14), " 2", DateFormat.DAY_OF_WEEK_IN_MONTH_FIELD);
    test.test(" FF", cal, " 01", DateFormat.DAY_OF_WEEK_IN_MONTH_FIELD);
    test.test(" FFFF", cal, " 0001", DateFormat.DAY_OF_WEEK_IN_MONTH_FIELD);
    test.test(" a", cal, " PM", DateFormat.AM_PM_FIELD);
    test.test(" a", new GregorianCalendar(1999, Calendar.NOVEMBER, 14), " AM", DateFormat.AM_PM_FIELD);
    test.test(" a", new GregorianCalendar(1999, Calendar.NOVEMBER, 14, 12, 0), " PM", DateFormat.AM_PM_FIELD);
    test.test(" aa", cal, " PM", DateFormat.AM_PM_FIELD);
    test.test(" aaa", cal, " PM", DateFormat.AM_PM_FIELD);
    test.test(" aaaa", cal, " PM", DateFormat.AM_PM_FIELD);
    test.test(" aaaaa", cal, " PM", DateFormat.AM_PM_FIELD);
    test.test(" k", cal, " 15", DateFormat.HOUR_OF_DAY1_FIELD);
    test.test(" k", new GregorianCalendar(1999, Calendar.NOVEMBER, 12, 4, 0), " 4", DateFormat.HOUR_OF_DAY1_FIELD);
    test.test(" k", new GregorianCalendar(1999, Calendar.NOVEMBER, 12, 12, 0), " 12", DateFormat.HOUR_OF_DAY1_FIELD);
    test.test(" k", new GregorianCalendar(1999, Calendar.NOVEMBER, 12), " 24", DateFormat.HOUR_OF_DAY1_FIELD);
    test.test(" kk", cal, " 15", DateFormat.HOUR_OF_DAY1_FIELD);
    test.test(" kkkk", cal, " 0015", DateFormat.HOUR_OF_DAY1_FIELD);
    test.test(" K", cal, " 3", DateFormat.HOUR0_FIELD);
    test.test(" K", new GregorianCalendar(1999, Calendar.NOVEMBER, 12), " 0", DateFormat.HOUR0_FIELD);
    test.test(" KK", cal, " 03", DateFormat.HOUR0_FIELD);
    test.test(" KKKK", cal, " 0003", DateFormat.HOUR0_FIELD);
    format.applyPattern("'Mkz''':.@5");
    assertEquals("Wrong output", "Mkz':.@5", format.format(new Date()));
    //assertTrue("Tests failed", !test.testsFailed());
    // Test invalid args to format.
    SimpleDateFormat dateFormat = new SimpleDateFormat();
    try {
        dateFormat.format(null, new StringBuffer(), new FieldPosition(1));
        fail("Expected test to throw NPE.");
    } catch (NullPointerException ex) {
    // expected
    } catch (Throwable ex) {
        fail("Expected test to throw NPE, not " + ex.getClass().getName());
    }
    assertFalse(test.testsFailed);
}
Also used : Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) FieldPosition(java.text.FieldPosition) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 64 with FieldPosition

use of java.text.FieldPosition in project robovm by robovm.

the class OldMessageFormatTest method test_formatLjava_lang_ObjectLjava_lang_StringBufferLjava_text_FieldPosition.

public void test_formatLjava_lang_ObjectLjava_lang_StringBufferLjava_text_FieldPosition() {
    // Test for method java.lang.StringBuffer
    // java.text.MessageFormat.format(java.lang.Object,
    // java.lang.StringBuffer, java.text.FieldPosition)
    new Support_MessageFormat("test_formatLjava_lang_ObjectLjava_lang_StringBufferLjava_text_FieldPosition").t_format_with_FieldPosition();
    String pattern = "On {4,date} at {3,time}, he ate {2,number, integer} " + "hamburger{2,choice,1#|1<s}.";
    MessageFormat format = new MessageFormat(pattern, Locale.US);
    Object[] objects = new Object[] { "", new Integer(3), 8, "" };
    try {
        format.format(objects, new StringBuffer(), new FieldPosition(DateFormat.Field.AM_PM));
        fail("IllegalArgumentException was not thrown.");
    } catch (IllegalArgumentException iae) {
    //expected
    }
}
Also used : Support_MessageFormat(tests.support.Support_MessageFormat) MessageFormat(java.text.MessageFormat) Support_MessageFormat(tests.support.Support_MessageFormat) FieldPosition(java.text.FieldPosition)

Example 65 with FieldPosition

use of java.text.FieldPosition in project robovm by robovm.

the class OldMessageFormatTest method test_format$Ljava_lang_ObjectLjava_lang_StringBufferLjava_text_FieldPosition.

public void test_format$Ljava_lang_ObjectLjava_lang_StringBufferLjava_text_FieldPosition() {
    // Test for method java.lang.StringBuffer
    // java.text.MessageFormat.format(java.lang.Object [],
    // java.lang.StringBuffer, java.text.FieldPosition)
    MessageFormat format = new MessageFormat("{1,number,integer}");
    StringBuffer buffer = new StringBuffer();
    format.format(new Object[] { "0", new Double(53.863) }, buffer, new FieldPosition(MessageFormat.Field.ARGUMENT));
    assertEquals("Wrong result", "54", buffer.toString());
    format.format(new Object[] { "0", new Double(53.863) }, buffer, new FieldPosition(MessageFormat.Field.ARGUMENT));
    assertEquals("Wrong result", "5454", buffer.toString());
    buffer = new StringBuffer();
    format.applyPattern("{0,choice,0#zero|1#one '{1,choice,2#two {2,time}}'}");
    Date date = new Date();
    String expected = "one two " + DateFormat.getTimeInstance().format(date);
    format.format(new Object[] { new Double(1.6), new Integer(3), date }, buffer, new FieldPosition(MessageFormat.Field.ARGUMENT));
    assertEquals("Choice not recursive:\n" + expected + "\n" + buffer, expected, buffer.toString());
    StringBuffer str = format.format(new Object[] { new Double(0.6), new Integer(3) }, buffer, null);
    assertEquals(expected + "zero", str.toString());
    assertEquals(expected + "zero", buffer.toString());
    try {
        format.format(new Object[] { "0", new Double(1), "" }, buffer, new FieldPosition(MessageFormat.Field.ARGUMENT));
        fail("IllegalArgumentException was not thrown.");
    } catch (IllegalArgumentException iae) {
    //expected
    }
    try {
        format.format(new Object[] { "", new Integer(3) }, buffer, new FieldPosition(MessageFormat.Field.ARGUMENT));
        fail("IllegalArgumentException was not thrown.");
    } catch (IllegalArgumentException iae) {
    //expected
    }
}
Also used : MessageFormat(java.text.MessageFormat) Support_MessageFormat(tests.support.Support_MessageFormat) FieldPosition(java.text.FieldPosition) Date(java.util.Date)

Aggregations

FieldPosition (java.text.FieldPosition)100 Date (java.util.Date)31 SimpleDateFormat (java.text.SimpleDateFormat)28 DecimalFormat (java.text.DecimalFormat)12 NumberFormat (java.text.NumberFormat)12 ParsePosition (java.text.ParsePosition)12 IsoDateFormat (alma.acs.util.IsoDateFormat)9 Test (org.junit.Test)9 ILogEntry (com.cosylab.logging.engine.log.ILogEntry)8 Format (java.text.Format)8 MessageFormat (java.text.MessageFormat)8 DateFormat (java.text.DateFormat)6 ACSLogParser (alma.acs.logging.engine.parser.ACSLogParser)5 IOException (java.io.IOException)3 ParseException (java.text.ParseException)3 Calendar (java.util.Calendar)3 GregorianCalendar (java.util.GregorianCalendar)3 Vector (java.util.Vector)3 ExtendedDateFormat (org.jkiss.utils.time.ExtendedDateFormat)3 LogTypeHelper (com.cosylab.logging.engine.log.LogTypeHelper)2