You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TestHSSFDataFormat.java 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.hssf.usermodel;
  16. import static org.apache.poi.hssf.HSSFTestDataSamples.openSampleWorkbook;
  17. import static org.junit.jupiter.api.Assertions.assertEquals;
  18. import static org.junit.jupiter.api.Assertions.assertNotNull;
  19. import java.io.IOException;
  20. import java.util.Arrays;
  21. import java.util.List;
  22. import org.apache.poi.hssf.HSSFITestDataProvider;
  23. import org.apache.poi.ss.usermodel.BaseTestDataFormat;
  24. import org.apache.poi.ss.usermodel.Cell;
  25. import org.apache.poi.ss.usermodel.CellStyle;
  26. import org.apache.poi.ss.usermodel.Row;
  27. import org.apache.poi.ss.usermodel.Sheet;
  28. import org.apache.poi.util.POILogFactory;
  29. import org.apache.poi.util.POILogger;
  30. import org.junit.jupiter.api.Test;
  31. /**
  32. * Tests for {@link HSSFDataFormat}
  33. */
  34. public final class TestHSSFDataFormat extends BaseTestDataFormat {
  35. private static final POILogger _logger = POILogFactory.getLogger(TestHSSFDataFormat.class);
  36. public TestHSSFDataFormat() {
  37. super(HSSFITestDataProvider.instance);
  38. }
  39. /**
  40. * Bug 51378: getDataFormatString method call crashes when reading the test file
  41. */
  42. @Test
  43. public void test51378() throws IOException {
  44. List<String> expNull = Arrays.asList( "0-3-0","0-43-11" );
  45. try (HSSFWorkbook wb = openSampleWorkbook("12561-1.xls")) {
  46. for (Sheet sheet : wb) {
  47. for (Row row : sheet) {
  48. for (Cell cell : row) {
  49. CellStyle style = cell.getCellStyle();
  50. assertNotNull(style);
  51. String coord = wb.getSheetIndex(sheet)+"-"+cell.getRowIndex()+"-"+cell.getColumnIndex();
  52. String fmt = style.getDataFormatString();
  53. assertEquals(expNull.contains(coord), fmt == null, coord+" unexpected");
  54. }
  55. }
  56. }
  57. }
  58. }
  59. }