|
23 | 23 |
|
24 | 24 | import java.nio.file.Path;
|
25 | 25 | import java.util.Map;
|
26 |
| - |
27 | 26 | import jdk.jpackage.test.Annotations.Parameter;
|
28 | 27 | import jdk.jpackage.test.Annotations.Test;
|
29 | 28 | import jdk.jpackage.test.FileAssociations;
|
| 29 | +import jdk.jpackage.test.JPackageCommand; |
| 30 | +import jdk.jpackage.test.JPackageStringBundle; |
30 | 31 | import jdk.jpackage.test.PackageTest;
|
31 | 32 | import jdk.jpackage.test.PackageType;
|
32 | 33 | import jdk.jpackage.test.TKit;
|
@@ -111,46 +112,42 @@ public static void test(boolean includeDescription) {
|
111 | 112 | public static void testNoMime() {
|
112 | 113 | final Path propFile = TKit.workDir().resolve("fa.properties");
|
113 | 114 |
|
114 |
| - PackageTest packageTest = new PackageTest().excludeTypes(PackageType.MAC); |
115 |
| - |
116 |
| - packageTest.configureHelloApp().addRunOnceInitializer(() -> { |
| 115 | + initPackageTest().addRunOnceInitializer(() -> { |
117 | 116 | TKit.createPropertiesFile(propFile, Map.of(
|
118 | 117 | "extension", "foo",
|
119 | 118 | "description", "bar"
|
120 | 119 | ));
|
121 | 120 | }).addInitializer(cmd -> {
|
122 |
| - cmd.addArguments("--file-associations", propFile).saveConsoleOutput(true); |
123 |
| - }).setExpectedExitCode(1).addBundleVerifier((cmd, result) -> { |
124 |
| - TKit.assertTextStream( |
125 |
| - "No MIME types were specified for File Association number 1") |
126 |
| - .apply(result.getOutput().stream()); |
127 |
| - TKit.assertTextStream( |
128 |
| - "Advice to fix: Specify MIME type for File Association number 1") |
129 |
| - .apply(result.getOutput().stream()); |
| 121 | + cmd.addArguments("--file-associations", propFile); |
| 122 | + cmd.validateOutput( |
| 123 | + JPackageStringBundle.MAIN.cannedFormattedString("error.no-content-types-for-file-association", 1), |
| 124 | + JPackageStringBundle.MAIN.cannedFormattedString("error.no-content-types-for-file-association.advice", 1)); |
130 | 125 | }).run();
|
131 | 126 | }
|
132 | 127 |
|
133 | 128 | @Test
|
134 | 129 | public static void testTooManyMimes() {
|
135 | 130 | final Path propFile = TKit.workDir().resolve("fa.properties");
|
136 | 131 |
|
137 |
| - PackageTest packageTest = new PackageTest().excludeTypes(PackageType.MAC); |
138 |
| - |
139 |
| - packageTest.configureHelloApp().addRunOnceInitializer(() -> { |
| 132 | + initPackageTest().addRunOnceInitializer(() -> { |
140 | 133 | TKit.createPropertiesFile(propFile, Map.of(
|
141 | 134 | "mime-type", "application/x-jpackage-foo, application/x-jpackage-bar",
|
142 | 135 | "extension", "foo",
|
143 | 136 | "description", "bar"
|
144 | 137 | ));
|
145 | 138 | }).addInitializer(cmd -> {
|
146 |
| - cmd.addArguments("--file-associations", propFile).saveConsoleOutput(true); |
147 |
| - }).setExpectedExitCode(1).addBundleVerifier((cmd, result) -> { |
148 |
| - TKit.assertTextStream( |
149 |
| - "More than one MIME types was specified for File Association number 1") |
150 |
| - .apply(result.getOutput().stream()); |
151 |
| - TKit.assertTextStream( |
152 |
| - "Advice to fix: Specify only one MIME type for File Association number 1") |
153 |
| - .apply(result.getOutput().stream()); |
| 139 | + cmd.addArguments("--file-associations", propFile); |
| 140 | + cmd.validateOutput( |
| 141 | + JPackageStringBundle.MAIN.cannedFormattedString("error.too-many-content-types-for-file-association", 1), |
| 142 | + JPackageStringBundle.MAIN.cannedFormattedString("error.too-many-content-types-for-file-association.advice", 1)); |
154 | 143 | }).run();
|
155 | 144 | }
|
| 145 | + |
| 146 | + private static PackageTest initPackageTest() { |
| 147 | + return new PackageTest() |
| 148 | + .excludeTypes(PackageType.MAC) |
| 149 | + .configureHelloApp() |
| 150 | + .addInitializer(JPackageCommand::setFakeRuntime) |
| 151 | + .setExpectedExitCode(1); |
| 152 | + } |
156 | 153 | }
|
0 commit comments