use of java.text.FieldPosition in project j2objc by google.
the class MessageFormatTest method test_format$Ljava_lang_ObjectLjava_lang_StringBufferLjava_text_FieldPosition.
/* J2ObjC: String hash codes are not consistent with Java.
public void test_hashCode() {
assertEquals("Should be equal", 3648, new MessageFormat("rr", null).hashCode());
}*/
public void test_format$Ljava_lang_ObjectLjava_lang_StringBufferLjava_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(0));
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 expectedText = "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" + expectedText + "\n" + buffer, expectedText, buffer.toString());
StringBuffer str = format.format(new Object[] { new Double(0.6), new Integer(3) }, buffer, null);
assertEquals(expectedText + "zero", str.toString());
assertEquals(expectedText + "zero", buffer.toString());
try {
format.format(new Object[] { "0", new Double(1), "" }, buffer, new FieldPosition(MessageFormat.Field.ARGUMENT));
fail();
} catch (IllegalArgumentException expected) {
}
try {
format.format(new Object[] { "", new Integer(3) }, buffer, new FieldPosition(MessageFormat.Field.ARGUMENT));
fail();
} catch (IllegalArgumentException expected) {
}
}
use of java.text.FieldPosition in project j2objc by google.
the class NumberFormatTest method test_formatLjava_lang_ObjectLjava_lang_StringBufferLjava_text_FieldPosition.
/**
* @tests java.text.NumberFormat#format(java.lang.Object,
* java.lang.StringBuffer, java.text.FieldPosition)
*/
public void test_formatLjava_lang_ObjectLjava_lang_StringBufferLjava_text_FieldPosition() {
FieldPosition pos;
StringBuffer out;
DecimalFormat format = (DecimalFormat) NumberFormat.getInstance(Locale.US);
pos = new FieldPosition(0);
out = format.format(new Long(Long.MAX_VALUE), new StringBuffer(), pos);
assertEquals("Wrong result L1: " + out, "9,223,372,036,854,775,807", out.toString());
pos = new FieldPosition(0);
out = format.format(new Long(Long.MIN_VALUE), new StringBuffer(), pos);
assertEquals("Wrong result L2: " + out, "-9,223,372,036,854,775,808", out.toString());
pos = new FieldPosition(0);
out = format.format(new java.math.BigInteger(String.valueOf(Long.MAX_VALUE)), new StringBuffer(), pos);
assertEquals("Wrong result BI1: " + out, "9,223,372,036,854,775,807", out.toString());
pos = new FieldPosition(0);
out = format.format(new java.math.BigInteger(String.valueOf(Long.MIN_VALUE)), new StringBuffer(), pos);
assertEquals("Wrong result BI2: " + out, "-9,223,372,036,854,775,808", out.toString());
java.math.BigInteger big;
pos = new FieldPosition(0);
big = new java.math.BigInteger(String.valueOf(Long.MAX_VALUE)).add(new java.math.BigInteger("1"));
out = format.format(big, new StringBuffer(), pos);
assertEquals("Wrong result BI3: " + out, "9,223,372,036,854,775,808", out.toString());
pos = new FieldPosition(0);
big = new java.math.BigInteger(String.valueOf(Long.MIN_VALUE)).add(new java.math.BigInteger("-1"));
out = format.format(big, new StringBuffer(), pos);
assertEquals("Wrong result BI4: " + out, "-9,223,372,036,854,775,809", out.toString());
pos = new FieldPosition(0);
out = format.format(new java.math.BigDecimal("51.348"), new StringBuffer(), pos);
assertEquals("Wrong result BD1: " + out, "51.348", out.toString());
pos = new FieldPosition(0);
out = format.format(new java.math.BigDecimal("51"), new StringBuffer(), pos);
assertEquals("Wrong result BD2: " + out, "51", out.toString());
try {
format.format(this, new StringBuffer(), pos);
fail("Should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
format.format(null, new StringBuffer(), pos);
fail("Should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
format.format(new Long(0), null, pos);
fail("Should throw NullPointerException");
} catch (NullPointerException e) {
// Expected
}
try {
format.format(new Long(0), new StringBuffer(), null);
fail("Should throw NullPointerException");
} catch (NullPointerException e) {
// Expected
}
}
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());
}
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());
}
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);
}
Aggregations