Skip to content

Commit fe9284a

Browse files
committed
8343101: Rework BasicTest.testTemp test cases
8343178: Test BasicTest.java javac compile fails cannot find symbol Reviewed-by: mdoerr Backport-of: a95374f588149d80068275a496ba4aa04b3bb4fd
1 parent 85e5a5c commit fe9284a

File tree

2 files changed

+51
-34
lines changed

2 files changed

+51
-34
lines changed

test/jdk/tools/jpackage/helpers/jdk/jpackage/test/TestBuilder.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,9 @@ private static Stream<MethodCall> toMethodCalls(Object[] ctorArgs, Method method
392392
}
393393

394394
private static Object fromString(String value, Class toType) {
395+
if (toType.isEnum()) {
396+
return Enum.valueOf(toType, value);
397+
}
395398
Function<String, Object> converter = conv.get(toType);
396399
if (converter == null) {
397400
throw new RuntimeException(String.format(

test/jdk/tools/jpackage/share/jdk/jpackage/tests/BasicTest.java

Lines changed: 48 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -30,7 +30,6 @@
3030
import java.util.ArrayList;
3131
import java.util.function.Function;
3232
import java.util.function.Predicate;
33-
import java.util.function.Supplier;
3433
import java.util.regex.Pattern;
3534
import java.util.stream.Stream;
3635
import jdk.jpackage.test.TKit;
@@ -264,49 +263,64 @@ public void testAddModules(String... addModulesArg) {
264263
cmd.executeAndAssertHelloAppImageCreated();
265264
}
266265

266+
public static enum TestTempType {
267+
TEMPDIR_EMPTY,
268+
TEMPDIR_NOT_EMPTY,
269+
TEMPDIR_NOT_EXIST,
270+
}
271+
267272
/**
268273
* Test --temp option. Doesn't make much sense for app image as temporary
269274
* directory is used only on Windows. Test it in packaging mode.
270-
* @throws IOException
271275
*/
272276
@Test
273-
@Parameter("true")
274-
@Parameter("false")
275-
public void testTemp(boolean withExistingTempDir) throws IOException {
277+
@Parameter("TEMPDIR_EMPTY")
278+
@Parameter("TEMPDIR_NOT_EMPTY")
279+
@Parameter("TEMPDIR_NOT_EXIST")
280+
public void testTemp(TestTempType type) throws IOException {
276281
final Path tempRoot = TKit.createTempDirectory("tmp");
277282

278-
Supplier<PackageTest> createTest = () -> {
279-
return new PackageTest()
280-
.configureHelloApp()
281-
// Force save of package bundle in test work directory.
282-
.addInitializer(JPackageCommand::setDefaultInputOutput)
283-
.addInitializer(cmd -> {
284-
Path tempDir = getTempDirectory(cmd, tempRoot);
285-
if (withExistingTempDir) {
286-
Files.createDirectories(tempDir);
287-
} else {
288-
Files.createDirectories(tempDir.getParent());
283+
var pkgTest = new PackageTest()
284+
.configureHelloApp()
285+
// Force save of package bundle in test work directory.
286+
.addInitializer(JPackageCommand::setDefaultInputOutput)
287+
.addInitializer(cmd -> {
288+
Path tempDir = getTempDirectory(cmd, tempRoot);
289+
switch (type) {
290+
case TEMPDIR_EMPTY -> Files.createDirectories(tempDir);
291+
case TEMPDIR_NOT_EXIST -> Files.createDirectories(tempDir.getParent());
292+
case TEMPDIR_NOT_EMPTY -> {
293+
Files.createDirectories(tempDir);
294+
TKit.createTextFile(tempDir.resolve("foo.txt"), List.of(
295+
"Hello Duke!"));
296+
}
289297
}
290298
cmd.addArguments("--temp", tempDir);
299+
}
300+
);
301+
302+
if (TestTempType.TEMPDIR_NOT_EMPTY.equals(type)) {
303+
pkgTest.setExpectedExitCode(1).addBundleVerifier(cmd -> {
304+
// Check jpackage didn't use the supplied directory.
305+
Path tempDir = getTempDirectory(cmd, tempRoot);
306+
String[] tempDirContents = tempDir.toFile().list();
307+
TKit.assertStringListEquals(List.of("foo.txt"), List.of(
308+
tempDirContents), String.format(
309+
"Check the contents of the supplied temporary directory [%s]",
310+
tempDir));
311+
TKit.assertStringListEquals(List.of("Hello Duke!"),
312+
Files.readAllLines(tempDir.resolve(tempDirContents[0])),
313+
"Check the contents of the file in the supplied temporary directory");
291314
});
292-
};
315+
} else {
316+
pkgTest.addBundleVerifier(cmd -> {
317+
// Check jpackage used the supplied directory.
318+
Path tempDir = getTempDirectory(cmd, tempRoot);
319+
TKit.assertDirectoryNotEmpty(tempDir);
320+
});
321+
}
293322

294-
createTest.get()
295-
.addBundleVerifier(cmd -> {
296-
// Check jpackage actually used the supplied directory.
297-
Path tempDir = getTempDirectory(cmd, tempRoot);
298-
TKit.assertNotEquals(0, tempDir.toFile().list().length,
299-
String.format(
300-
"Check jpackage wrote some data in the supplied temporary directory [%s]",
301-
tempDir));
302-
})
303-
.run(PackageTest.Action.CREATE);
304-
305-
createTest.get()
306-
// Temporary directory should not be empty,
307-
// jpackage should exit with error.
308-
.setExpectedExitCode(1)
309-
.run(PackageTest.Action.CREATE);
323+
pkgTest.run(PackageTest.Action.CREATE);
310324
}
311325

312326
@Test

0 commit comments

Comments
 (0)