*/
@Test
public void testApplyObjectDate() throws ParseException {
-
CellFormat cf1 = CellFormat.getInstance("m/d/yyyy");
Date date1 = new SimpleDateFormat("M/d/y", Locale.ROOT).parse("01/11/2012");
- //assertEquals("1/11/2012", cf1.apply(date1).text);
-
+ assertEquals("1/11/2012", cf1.apply(date1).text);
}
@Test
public void testSimpleFractionFormat() throws IOException {
CellFormat cf1 = CellFormat.getInstance("# ?/?");
// Create a workbook, row and cell to test with
- Workbook wb = new HSSFWorkbook();
- try {
+ try (Workbook wb = new HSSFWorkbook()) {
Sheet sheet = wb.createSheet();
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
cell.setCellValue(123456.6);
//System.out.println(cf1.apply(cell).text);
assertEquals("123456 3/5", cf1.apply(cell).text);
- } finally {
- wb.close();
}
}
@Test
- public void testAccountingFormats() throws IOException {
+ public void testAccountingFormats() {
char pound = '\u00A3';
char euro = '\u20AC';
assertNotNull(instance);
assertEquals("01/01/1970", instance.apply(new Date(12345)).text);
}
-}
\ No newline at end of file
+}
DataFormatter dfUS = new DataFormatter(Locale.US, true);
// Create a spreadsheet with some formula errors in it
- Workbook wb = new HSSFWorkbook();
- try {
+ try (Workbook wb = new HSSFWorkbook()) {
Sheet s = wb.createSheet();
Row r = s.createRow(0);
Cell c = r.createCell(0, CellType.ERROR);
c.setCellErrorValue(FormulaError.REF.getCode());
assertEquals(FormulaError.REF.getString(), dfUS.formatCellValue(c));
- } finally {
- wb.close();
}
}
DataFormatter formatter = new DataFormatter();
// Create a spreadsheet with some TRUE/FALSE boolean values in it
- Workbook wb = new HSSFWorkbook();
- try {
+ try (Workbook wb = new HSSFWorkbook()) {
Sheet s = wb.createSheet();
Row r = s.createRow(0);
Cell c = r.createCell(0);
c.setCellValue(false);
assertEquals("FALSE", formatter.formatCellValue(c));
- } finally {
- wb.close();
}
}
}
private static void assertFormatsTo(String expected, double input) throws IOException {
- Workbook wb = new HSSFWorkbook();
- try {
+ try (Workbook wb = new HSSFWorkbook()) {
Sheet s1 = wb.createSheet();
Row row = s1.createRow(0);
Cell rawValue = row.createCell(0);
String actual = new DataFormatter().formatCellValue(rawValue);
assertEquals(expected, actual);
}
- finally {
- wb.close();
- }
}
@Test
}
@Test
- public void testFormatWithTrailingDotsOtherLocale() throws Exception {
+ public void testFormatWithTrailingDotsOtherLocale() {
DataFormatter dfIT = new DataFormatter(Locale.ITALY);
assertEquals("1.000.000", dfIT.formatRawCellContents(1000000, -1, "#,##0"));
assertEquals("1.000", dfIT.formatRawCellContents(1000000, -1, "#,##0,"));
*/
@Test
public void testSimpleNumericFormatsInGermanyLocale() {
- List<Locale> locales = Arrays.asList(new Locale[] {Locale.GERMANY, Locale.US, Locale.ROOT} );
+ Locale[] locales = new Locale[] {Locale.GERMANY, Locale.US, Locale.ROOT};
for (Locale locale : locales) {
//show that LocaleUtil has no effect on these tests
LocaleUtil.setUserLocale(locale);
return true;
}
-}
\ No newline at end of file
+}