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.

TestPOITestCase.java 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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;
  16. import static org.junit.jupiter.api.Assertions.assertNotNull;
  17. import java.io.IOException;
  18. import java.util.Collections;
  19. import java.util.Locale;
  20. import java.util.Map;
  21. import org.apache.poi.poifs.filesystem.POIFSFileSystem;
  22. import org.apache.poi.poifs.property.PropertyTable;
  23. import org.junit.jupiter.api.Test;
  24. /**
  25. * A class for testing the POI Junit TestCase utility class
  26. */
  27. final class TestPOITestCase {
  28. @Test
  29. void assertStartsWith() {
  30. POITestCase.assertStartsWith("Apache POI", "");
  31. POITestCase.assertStartsWith("Apache POI", "Apache");
  32. POITestCase.assertStartsWith("Apache POI", "Apache POI");
  33. }
  34. @Test
  35. void assertEndsWith() {
  36. POITestCase.assertEndsWith("Apache POI", "");
  37. POITestCase.assertEndsWith("Apache POI", "POI");
  38. POITestCase.assertEndsWith("Apache POI", "Apache POI");
  39. }
  40. @Test
  41. void assertContains() {
  42. POITestCase.assertContains("There is a needle in this haystack", "needle");
  43. }
  44. @Test
  45. void assertContainsIgnoreCase_Locale() {
  46. POITestCase.assertContainsIgnoreCase("There is a Needle in this haystack", "needlE", Locale.ROOT);
  47. }
  48. @Test
  49. void assertContainsIgnoreCase() {
  50. POITestCase.assertContainsIgnoreCase("There is a Needle in this haystack", "needlE");
  51. }
  52. @Test
  53. void assertNotContained() {
  54. POITestCase.assertNotContained("There is a needle in this haystack", "gold");
  55. }
  56. @Test
  57. void assertMapContains() {
  58. Map<String, String> haystack = Collections.singletonMap("needle", "value");
  59. POITestCase.assertContains(haystack, "needle");
  60. }
  61. /**
  62. * Utility method to get the value of a private/protected field.
  63. * Only use this method in test cases!!!
  64. */
  65. @Test
  66. void getFieldValue() throws IOException {
  67. try (POIFSFileSystem fs = new POIFSFileSystem()) {
  68. PropertyTable actual = POITestCase.getFieldValue(POIFSFileSystem.class, fs, PropertyTable.class, "_property_table");
  69. assertNotNull(actual);
  70. }
  71. }
  72. }