From d3d560f756082aec24fbbcb7a44d94346fcf9e23 Mon Sep 17 00:00:00 2001 From: Alexey Semenyuk Date: Tue, 23 Jun 2026 17:32:34 +0000 Subject: [PATCH] 8387002: Test ManualTests/JPackage/JPKG001/JPKG001_004: CommonLicenseTest fails on Windows because the license agreement text is not displayed Reviewed-by: almatvee --- .../jdk/jpackage/internal/RtfConverter.java | 2 +- .../jpackage/internal/RtfConverterTest.java | 82 +++++++++++++++++++ .../tools/jpackage/junit/windows/junit.java | 8 ++ 3 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 test/jdk/tools/jpackage/junit/windows/jdk.jpackage/jdk/jpackage/internal/RtfConverterTest.java diff --git a/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/RtfConverter.java b/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/RtfConverter.java index 8886afc7918..a0ff70066b9 100644 --- a/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/RtfConverter.java +++ b/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/RtfConverter.java @@ -58,7 +58,7 @@ sealed interface RtfConverter { } static Optional createSimple(Path path) throws IOException { - if (isRtfFile(path)) { + if (!Files.isDirectory(path) && !isRtfFile(path)) { return Optional.of(Details.Simple.VALUE); } else { return Optional.empty(); diff --git a/test/jdk/tools/jpackage/junit/windows/jdk.jpackage/jdk/jpackage/internal/RtfConverterTest.java b/test/jdk/tools/jpackage/junit/windows/jdk.jpackage/jdk/jpackage/internal/RtfConverterTest.java new file mode 100644 index 00000000000..0943f6c9733 --- /dev/null +++ b/test/jdk/tools/jpackage/junit/windows/jdk.jpackage/jdk/jpackage/internal/RtfConverterTest.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.jpackage.internal; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Optional; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + + +class RtfConverterTest { + + @Test + void test_createSimple_dir(@TempDir Path workDir) throws IOException { + + assertEquals(Optional.empty(), RtfConverter.createSimple(workDir)); + } + + @ParameterizedTest + @ValueSource(strings = { + // Empty value to exercise the case when the file's content is shorter than the RTF's header + "", + // Value to exercise the case when the file's content is shorter than the RTF's header + "Hello", + "Hello Duke!", + }) + void test_createSimple_text_file(String text, @TempDir Path workDir) throws IOException { + + final var licenseFile = workDir.resolve("license"); + + Files.writeString(licenseFile, text); + + final var conv = RtfConverter.createSimple(licenseFile); + + assertTrue(conv.isPresent()); + + conv.orElseThrow().convert(licenseFile); + + assertEquals(Optional.empty(), RtfConverter.createSimple(licenseFile)); + } + + @ParameterizedTest + @ValueSource(strings = { + "{\\rtf1\\ansi\\deff0{\\fonttbl{\\f0 Arial;}}\\f0\\fs24 Hello, Duke!}", + }) + void test_createSimple_rtf_file(String text, @TempDir Path workDir) throws IOException { + + final var licenseFile = workDir.resolve("license"); + + Files.writeString(licenseFile, text); + + assertEquals(Optional.empty(), RtfConverter.createSimple(workDir)); + } +} diff --git a/test/jdk/tools/jpackage/junit/windows/junit.java b/test/jdk/tools/jpackage/junit/windows/junit.java index 8c290c2c87f..c046589a363 100644 --- a/test/jdk/tools/jpackage/junit/windows/junit.java +++ b/test/jdk/tools/jpackage/junit/windows/junit.java @@ -57,3 +57,11 @@ * jdk/jpackage/internal/WixToolTest.java * @run junit jdk.jpackage/jdk.jpackage.internal.WixToolTest */ + +/* @test + * @summary RtfConverter unit tests + * @requires (os.family == "windows") + * @compile/module=jdk.jpackage -Xlint:all -Werror + * jdk/jpackage/internal/RtfConverterTest.java + * @run junit jdk.jpackage/jdk.jpackage.internal.RtfConverterTest + */