test/jdk/tools/jpackage/share/jdk/jpackage/tests/BasicTest.java
branchJDK-8200758-branch
changeset 58671 3b578a5976df
parent 58648 3bf53ffa9ae7
child 58762 0fe62353385b
--- a/test/jdk/tools/jpackage/share/jdk/jpackage/tests/BasicTest.java	Thu Oct 17 07:55:35 2019 -0400
+++ b/test/jdk/tools/jpackage/share/jdk/jpackage/tests/BasicTest.java	Thu Oct 17 08:00:37 2019 -0400
@@ -34,6 +34,7 @@
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 import jdk.jpackage.test.*;
+import jdk.jpackage.test.Functional.ThrowingConsumer;
 import jdk.jpackage.test.Annotations.*;
 
 /*
@@ -218,25 +219,37 @@
      */
     @Test
     public void testTemp() throws IOException {
-        JPackageCommand cmd = JPackageCommand.helloAppImage()
-                .removeArgumentWithValue("--package-type")
-                .addArguments("--verbose")
-                .setFakeRuntime();
+        TKit.withTempDirectory("temp-root", tempRoot -> {
+            Function<JPackageCommand, Path> getTempDir = cmd -> {
+                return tempRoot.resolve(cmd.outputBundle().getFileName());
+            };
 
-        TKit.withTempDirectory("temp-root", tempDir -> {
-            cmd.addArguments("--temp", tempDir);
+            ThrowingConsumer<JPackageCommand> addTempDir = cmd -> {
+                Path tempDir = getTempDir.apply(cmd);
+                Files.createDirectories(tempDir);
+                cmd.addArguments("--temp", tempDir);
+            };
 
-            cmd.execute().assertExitCodeIsZero();
+            new PackageTest().configureHelloApp().addInitializer(addTempDir)
+            .addBundleVerifier(cmd -> {
+                // Check jpackage actually used the supplied directory.
+                Path tempDir = getTempDir.apply(cmd);
+                TKit.assertNotEquals(0, tempDir.toFile().list().length,
+                        String.format(
+                                "Check jpackage wrote some data in the supplied temporary directory [%s]",
+                                tempDir));
+            })
+            .run();
 
-            // Check jpackage actually used the supplied directory.
-            TKit.assertNotEquals(0, tempDir.toFile().list().length,
-                    String.format(
-                            "Check jpackage wrote some data in the supplied temporary directory [%s]",
-                            tempDir));
-
+            new PackageTest().configureHelloApp().addInitializer(addTempDir)
+            .addInitializer(cmd -> {
+                // Clean output from the previus jpackage run.
+                Files.delete(cmd.outputBundle());
+            })
             // Temporary directory should not be empty,
             // jpackage should exit with error.
-            cmd.execute().assertExitCodeIs(1);
+            .setExpectedExitCode(1)
+            .run();
         });
     }