From 66c9343b191933d02063cb208eecef933d76a614 Mon Sep 17 00:00:00 2001 From: skytin1004 Date: Sun, 6 Sep 2026 12:17:16 +0900 Subject: [PATCH 1/2] fix: default null scientific format option to false --- .../sheet/metadata/format/DataFormatter.java | 2 +- .../metadata/format/DataFormatterTest.java | 60 +++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 fesod-sheet/src/test/java/org/apache/fesod/sheet/metadata/format/DataFormatterTest.java diff --git a/fesod-sheet/src/main/java/org/apache/fesod/sheet/metadata/format/DataFormatter.java b/fesod-sheet/src/main/java/org/apache/fesod/sheet/metadata/format/DataFormatter.java index fe8bc6406..cb392ce01 100644 --- a/fesod-sheet/src/main/java/org/apache/fesod/sheet/metadata/format/DataFormatter.java +++ b/fesod-sheet/src/main/java/org/apache/fesod/sheet/metadata/format/DataFormatter.java @@ -187,7 +187,7 @@ public DataFormatter(Boolean use1904windowing, Locale locale, Boolean useScienti this.locale = locale; } - if (use1904windowing == null) { + if (useScientificFormat == null) { this.useScientificFormat = Boolean.FALSE; } else { this.useScientificFormat = useScientificFormat; diff --git a/fesod-sheet/src/test/java/org/apache/fesod/sheet/metadata/format/DataFormatterTest.java b/fesod-sheet/src/test/java/org/apache/fesod/sheet/metadata/format/DataFormatterTest.java new file mode 100644 index 000000000..d7c29c594 --- /dev/null +++ b/fesod-sheet/src/test/java/org/apache/fesod/sheet/metadata/format/DataFormatterTest.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.fesod.sheet.metadata.format; + +import java.math.BigDecimal; +import java.util.Locale; +import org.apache.fesod.sheet.testkit.Tags; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +@Tag(Tags.UNIT) +class DataFormatterTest { + + private static final BigDecimal LARGE_NUMBER = new BigDecimal("100000000000"); + + @Test + void test_format_defaultsNullScientificFormatToFalse() { + DataFormatter formatter = new DataFormatter(false, Locale.US, null); + + String result = formatter.format(LARGE_NUMBER, null, "General"); + + Assertions.assertEquals("100000000000", result); + } + + @Test + void test_format_honorsScientificFormatWhenWindowingIsNull() { + DataFormatter formatter = new DataFormatter(null, Locale.US, true); + + String result = formatter.format(LARGE_NUMBER, null, "General"); + + Assertions.assertEquals("1E+11", result); + } + + @Test + void test_format_honorsDisabledScientificFormatWhenWindowingIsNull() { + DataFormatter formatter = new DataFormatter(null, Locale.US, false); + + String result = formatter.format(LARGE_NUMBER, null, "General"); + + Assertions.assertEquals("100000000000", result); + } +} From 6f2a9e44bb73dd9045eb359010978d032821996e Mon Sep 17 00:00:00 2001 From: skytin1004 Date: Tue, 8 Sep 2026 10:28:09 +0900 Subject: [PATCH 2/2] test: parameterize scientific format constructor cases --- .../metadata/format/DataFormatterTest.java | 33 ++++++------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/fesod-sheet/src/test/java/org/apache/fesod/sheet/metadata/format/DataFormatterTest.java b/fesod-sheet/src/test/java/org/apache/fesod/sheet/metadata/format/DataFormatterTest.java index d7c29c594..b45ee356b 100644 --- a/fesod-sheet/src/test/java/org/apache/fesod/sheet/metadata/format/DataFormatterTest.java +++ b/fesod-sheet/src/test/java/org/apache/fesod/sheet/metadata/format/DataFormatterTest.java @@ -24,37 +24,24 @@ import org.apache.fesod.sheet.testkit.Tags; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; @Tag(Tags.UNIT) class DataFormatterTest { private static final BigDecimal LARGE_NUMBER = new BigDecimal("100000000000"); - @Test - void test_format_defaultsNullScientificFormatToFalse() { - DataFormatter formatter = new DataFormatter(false, Locale.US, null); + @ParameterizedTest(name = "windowing={0}, scientific={1} -> {2}") + @CsvSource( + nullValues = "null", + value = {"false, null, 100000000000", "null, true, 1E+11", "null, false, 100000000000"}) + void test_format_honorsScientificFormatWithNullableOptions( + Boolean use1904windowing, Boolean useScientificFormat, String expected) { + DataFormatter formatter = new DataFormatter(use1904windowing, Locale.US, useScientificFormat); String result = formatter.format(LARGE_NUMBER, null, "General"); - Assertions.assertEquals("100000000000", result); - } - - @Test - void test_format_honorsScientificFormatWhenWindowingIsNull() { - DataFormatter formatter = new DataFormatter(null, Locale.US, true); - - String result = formatter.format(LARGE_NUMBER, null, "General"); - - Assertions.assertEquals("1E+11", result); - } - - @Test - void test_format_honorsDisabledScientificFormatWhenWindowingIsNull() { - DataFormatter formatter = new DataFormatter(null, Locale.US, false); - - String result = formatter.format(LARGE_NUMBER, null, "General"); - - Assertions.assertEquals("100000000000", result); + Assertions.assertEquals(expected, result); } }