Skip to content

Commit a95374f

Browse files
author
Alexey Semenyuk
committed
8343101: Rework BasicTest.testTemp test cases
Reviewed-by: almatvee
1 parent 00fe9f7 commit a95374f

File tree

2 files changed

+50
-33
lines changed

2 files changed

+50
-33
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: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -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;
@@ -265,49 +264,64 @@ public void testAddModules(String... addModulesArg) {
265264
cmd.executeAndAssertHelloAppImageCreated();
266265
}
267266

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

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

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

313327
@Test

0 commit comments

Comments
 (0)