import java.text.DecimalFormatSymbols;
import java.text.SimpleDateFormat;
import java.util.GregorianCalendar;
+import java.util.Locale;
import junit.framework.TestCase;
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
*/
public final class TestText extends TestCase {
private static final TextFunction T = null;
-
+
public void testTextWithStringFirstArg() {
ValueEval strArg = new StringEval("abc");
ValueEval result = T.TEXT.evaluate(args, -1, (short)-1);
assertEquals(ErrorEval.VALUE_INVALID, result);
}
-
+
public void testTextWithDeciamlFormatSecondArg() {
ValueEval numArg = new NumberEval(321321.321);
ValueEval formatArg = new StringEval("#,###.00000");
ValueEval[] args = { numArg, formatArg };
ValueEval result = T.TEXT.evaluate(args, -1, (short)-1);
- char groupSeparator = DecimalFormatSymbols.getInstance().getGroupingSeparator();
- char decimalSeparator = DecimalFormatSymbols.getInstance().getDecimalSeparator();
+ char groupSeparator = new DecimalFormatSymbols(Locale.getDefault()).getGroupingSeparator();
+ char decimalSeparator = new DecimalFormatSymbols(Locale.getDefault()).getDecimalSeparator();
ValueEval testResult = new StringEval("321" + groupSeparator + "321" + decimalSeparator + "32100");
assertEquals(testResult.toString(), result.toString());
numArg = new NumberEval(321.321);
formatArg = new StringEval("00000.00000");
- args[0] = numArg;
- args[1] = formatArg;
+ args[0] = numArg;
+ args[1] = formatArg;
result = T.TEXT.evaluate(args, -1, (short)-1);
testResult = new StringEval("00321" + decimalSeparator + "32100");
assertEquals(testResult.toString(), result.toString());
-
+
formatArg = new StringEval("$#.#");
- args[1] = formatArg;
+ args[1] = formatArg;
result = T.TEXT.evaluate(args, -1, (short)-1);
testResult = new StringEval("$321" + decimalSeparator + "3");
assertEquals(testResult.toString(), result.toString());
}
-
+
public void testTextWithFractionFormatSecondArg() {
ValueEval numArg = new NumberEval(321.321);
ValueEval result = T.TEXT.evaluate(args, -1, (short)-1);
ValueEval testResult = new StringEval("321 1/3");
assertEquals(testResult.toString(), result.toString());
-
+
formatArg = new StringEval("# #/##");
- args[1] = formatArg;
+ args[1] = formatArg;
result = T.TEXT.evaluate(args, -1, (short)-1);
testResult = new StringEval("321 26/81");
assertEquals(testResult.toString(), result.toString());
-
+
formatArg = new StringEval("#/##");
- args[1] = formatArg;
+ args[1] = formatArg;
result = T.TEXT.evaluate(args, -1, (short)-1);
testResult = new StringEval("26027/81");
assertEquals(testResult.toString(), result.toString());
}
-
+
public void testTextWithDateFormatSecondArg() {
ValueEval numArg = new NumberEval(321.321);
ValueEval result = T.TEXT.evaluate(args, -1, (short)-1);
ValueEval testResult = new StringEval("16:11:1900 07:42:14");
assertEquals(testResult.toString(), result.toString());
-
- // this line is intended to compute how "November" would look like in the current locale
- String november = new SimpleDateFormat("MMMM").format(new GregorianCalendar(2010,10,15).getTime());
-
+
+ // this line is intended to compute how "November" would look like in the current locale
+ String november = new SimpleDateFormat("MMMM").format(new GregorianCalendar(2010,10,15).getTime());
+
formatArg = new StringEval("MMMM dd, yyyy");
- args[1] = formatArg;
+ args[1] = formatArg;
result = T.TEXT.evaluate(args, -1, (short)-1);
testResult = new StringEval(november + " 16, 1900");
assertEquals(testResult.toString(), result.toString());
}
-
-
}