8387002: Test ManualTests/JPackage/JPKG001/JPKG001_004: CommonLicenseTest fails on Windows because the license agreement text is not displayed

Reviewed-by: almatvee
This commit is contained in:
Alexey Semenyuk 2026-06-23 17:32:34 +00:00
parent fe46d6b1e2
commit d3d560f756
3 changed files with 91 additions and 1 deletions

View File

@ -58,7 +58,7 @@ sealed interface RtfConverter {
}
static Optional<RtfConverter> createSimple(Path path) throws IOException {
if (isRtfFile(path)) {
if (!Files.isDirectory(path) && !isRtfFile(path)) {
return Optional.of(Details.Simple.VALUE);
} else {
return Optional.empty();

View File

@ -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));
}
}

View File

@ -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
*/