use of java.text.ParsePosition in project poi by apache.
the class TestPackageCoreProperties method compareProperties.
private void compareProperties(OPCPackage p) throws InvalidFormatException {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ROOT);
df.setTimeZone(LocaleUtil.TIMEZONE_UTC);
Date expectedDate = df.parse("2007-05-12T08:00:00Z", new ParsePosition(0));
// Gets the core properties
PackageProperties props = p.getPackageProperties();
assertEquals("MyCategory", props.getCategoryProperty().getValue());
assertEquals("MyContentStatus", props.getContentStatusProperty().getValue());
assertEquals("MyContentType", props.getContentTypeProperty().getValue());
assertEquals(expectedDate, props.getCreatedProperty().getValue());
assertEquals("MyCreator", props.getCreatorProperty().getValue());
assertEquals("MyDescription", props.getDescriptionProperty().getValue());
assertEquals("MyIdentifier", props.getIdentifierProperty().getValue());
assertEquals("MyKeywords", props.getKeywordsProperty().getValue());
assertEquals("MyLanguage", props.getLanguageProperty().getValue());
assertEquals("Julien Chable", props.getLastModifiedByProperty().getValue());
assertEquals(expectedDate, props.getLastPrintedProperty().getValue());
assertEquals(expectedDate, props.getModifiedProperty().getValue());
assertEquals("2", props.getRevisionProperty().getValue());
assertEquals("MySubject", props.getSubjectProperty().getValue());
assertEquals("MyTitle", props.getTitleProperty().getValue());
assertEquals("2", props.getVersionProperty().getValue());
}
use of java.text.ParsePosition in project robovm by robovm.
the class NumberFormatTest method test_small_BigInteger_gets_longValue.
// NumberFormat.format(Object, StringBuffer, FieldPosition) guarantees it calls longValue for
// any BigInteger with a bitLength strictly less than 64.
public void test_small_BigInteger_gets_longValue() throws Exception {
class MyNumberFormat extends NumberFormat {
public StringBuffer format(double value, StringBuffer b, FieldPosition f) {
b.append("double");
return b;
}
public StringBuffer format(long value, StringBuffer b, FieldPosition f) {
b.append("long");
return b;
}
public Number parse(String string, ParsePosition p) {
throw new UnsupportedOperationException();
}
}
NumberFormat nf = new MyNumberFormat();
assertEquals("long", nf.format(BigInteger.valueOf(Long.MAX_VALUE)));
assertEquals("double", nf.format(BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE)));
assertEquals("long", nf.format(BigInteger.valueOf(Long.MIN_VALUE)));
assertEquals("double", nf.format(BigInteger.valueOf(Long.MIN_VALUE).subtract(BigInteger.ONE)));
}
use of java.text.ParsePosition in project robovm by robovm.
the class OldMessageFormatTest method test_parseLjava_lang_StringLjava_text_ParsePosition.
public void test_parseLjava_lang_StringLjava_text_ParsePosition() {
ParsePosition pos = new ParsePosition(2);
MessageFormat mf = new MessageFormat("{0}; {0}; {0}");
String parse = "a; b; c";
try {
mf.parse(parse, null);
fail("NullPointerException was not thrown.");
} catch (NullPointerException npe) {
//expected
}
try {
mf.parse(null, pos);
} catch (NullPointerException npe) {
fail("NullPointerException was thrown.");
}
}
use of java.text.ParsePosition in project robovm by robovm.
the class OldDateFormatTest method test_parseObjectLjava_lang_StringLjava_text_ParsePosition.
/**
* java.text.DateFormat#parseObject(String, ParsePosition) Test of
* method java.text.DateFormat#parseObject(String, ParsePosition).
* Case 1: Try to parse correct data string. Case 2: Try to parse
* partialy correct data string. Case 3: Try to use argument
* ParsePosition as null.
*/
public void test_parseObjectLjava_lang_StringLjava_text_ParsePosition() {
DateFormat df = DateFormat.getInstance();
try {
// case 1: Try to parse correct data string.
Date current = new Date();
ParsePosition pp = new ParsePosition(0);
int parseIndex = pp.getIndex();
Date result = (Date) df.parseObject(df.format(current), pp);
assertEquals("Dates are different.", current.getDate(), result.getDate());
assertEquals("Days are different.", current.getDay(), result.getDay());
assertEquals("Months are different.", current.getMonth(), result.getMonth());
assertEquals("Years are different.", current.getYear(), result.getYear());
assertEquals("Hours are different", current.getHours(), result.getHours());
assertEquals("Minutes are diffetrent,", current.getMinutes(), result.getMinutes());
assertTrue("Parse operation return null", result != null);
assertTrue("ParseIndex is incorrect", pp.getIndex() != parseIndex);
// case 2: Try to parse partially correct data string.
pp.setIndex(0);
char[] cur = df.format(current).toCharArray();
cur[cur.length / 2] = 'Z';
String partialCorrect = new String(cur);
result = (Date) df.parseObject(partialCorrect, pp);
assertTrue("Parse operation return not-null", result == null);
assertTrue("ParseIndex is incorrect", pp.getIndex() == 0);
assertTrue("ParseErrorIndex is incorrect", pp.getErrorIndex() == cur.length / 2);
pp.setIndex(2);
char[] curDate = df.format(current).toCharArray();
char[] newArray = new char[curDate.length + pp.getIndex()];
for (int i = 0; i < curDate.length; i++) {
newArray[i + pp.getIndex()] = curDate[i];
}
result = (Date) df.parseObject(new String(newArray), pp);
//assertEquals(current, result);
assertEquals("Dates are different.", current.getDate(), result.getDate());
assertEquals("Days are different.", current.getDay(), result.getDay());
assertEquals("Months are different.", current.getMonth(), result.getMonth());
assertEquals("Years are different.", current.getYear(), result.getYear());
assertEquals("Hours are different", current.getHours(), result.getHours());
assertEquals("Minutes are diffetrent,", current.getMinutes(), result.getMinutes());
// case 3: Try to use argument ParsePosition as null.
try {
df.parseObject(df.format(current), null);
fail("Expected NullPointerException was not thrown");
} catch (NullPointerException e) {
// expected
}
assertNull(df.parseObject("test", pp));
} catch (Exception e) {
fail("Unexpected exception " + e.toString());
}
}
use of java.text.ParsePosition in project robovm by robovm.
the class OldDecimalFormatTest method test_parseLjava_lang_StringLjava_text_ParsePosition.
public void test_parseLjava_lang_StringLjava_text_ParsePosition() {
DecimalFormat format = (DecimalFormat) NumberFormat.getNumberInstance(Locale.ENGLISH);
ParsePosition pos = new ParsePosition(0);
Number result = format.parse("9223372036854775807", pos);
assertTrue("Wrong result type for Long.MAX_VALUE", result.getClass() == Long.class);
assertEquals("Wrong result Long.MAX_VALUE", Long.MAX_VALUE, result.longValue());
pos = new ParsePosition(0);
result = format.parse("-9223372036854775808", pos);
assertTrue("Wrong result type for Long.MIN_VALUE", result.getClass() == Long.class);
assertTrue("Wrong result Long.MIN_VALUE: " + result.longValue(), result.longValue() == Long.MIN_VALUE);
pos = new ParsePosition(0);
result = format.parse("9223372036854775808", pos);
assertTrue("Wrong result type for Long.MAX_VALUE+1", result.getClass() == Double.class);
assertEquals("Wrong result Long.MAX_VALUE + 1", (double) Long.MAX_VALUE + 1, result.doubleValue());
pos = new ParsePosition(0);
result = format.parse("-9223372036854775809", pos);
assertTrue("Wrong result type for Long.MIN_VALUE - 1", result.getClass() == Double.class);
assertEquals("Wrong result Long.MIN_VALUE - 1", (double) Long.MIN_VALUE - 1, result.doubleValue());
pos = new ParsePosition(0);
result = format.parse("18446744073709551629", pos);
assertTrue("Wrong result type for overflow", result.getClass() == Double.class);
assertEquals("Wrong result for overflow", 18446744073709551629d, result.doubleValue());
pos = new ParsePosition(0);
result = format.parse("42325917317067571199", pos);
assertTrue("Wrong result type for overflow a: " + result, result.getClass() == Double.class);
assertTrue("Wrong result for overflow a: " + result, result.doubleValue() == 42325917317067571199d);
pos = new ParsePosition(0);
result = format.parse("4232591731706757119E1", pos);
assertTrue("Wrong result type for overflow b: " + result, result.getClass() == Double.class);
assertEquals("Wrong result for overflow b: " + result, 42325917317067571190d, result.doubleValue());
pos = new ParsePosition(0);
result = format.parse(".42325917317067571199E20", pos);
assertTrue("Wrong result type for overflow c: " + result, result.getClass() == Double.class);
assertTrue("Wrong result for overflow c: " + result, result.doubleValue() == 42325917317067571199d);
pos = new ParsePosition(0);
result = format.parse("922337203685477580.9E1", pos);
assertTrue("Wrong result type for overflow d: " + result, result.getClass() == Double.class);
assertTrue("Wrong result for overflow d: " + result, result.doubleValue() == 9223372036854775809d);
pos = new ParsePosition(0);
result = format.parse("9.223372036854775809E18", pos);
assertTrue("Wrong result type for overflow e: " + result, result.getClass() == Double.class);
assertTrue("Wrong result for overflow e: " + result, result.doubleValue() == 9223372036854775809d);
// test parse with multipliers
format.setMultiplier(100);
result = format.parse("9223372036854775807", new ParsePosition(0));
assertEquals("Wrong result type multiplier 100: " + result, Long.class, result.getClass());
// RI on windows and linux both answer with a slightly rounded result
assertTrue("Wrong result for multiplier 100: " + result, result.longValue() == 92233720368547760L);
format.setMultiplier(1000);
result = format.parse("9223372036854775807", new ParsePosition(0));
assertTrue("Wrong result type multiplier 1000: " + result, result.getClass() == Long.class);
assertTrue("Wrong result for multiplier 1000: " + result, result.longValue() == 9223372036854776L);
format.setMultiplier(10000);
result = format.parse("9223372036854775807", new ParsePosition(0));
assertTrue("Wrong result type multiplier 10000: " + result, result.getClass() == Double.class);
assertTrue("Wrong result for multiplier 10000: " + result, result.doubleValue() == 922337203685477.5807d);
}
Aggregations