Skip to content

Commit aa7f613

Browse files
Better negative testing in MainClassTest
1 parent cfe5c09 commit aa7f613

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

test/jdk/tools/jpackage/share/MainClassTest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,13 @@
3939
import jdk.jpackage.internal.util.function.ThrowingConsumer;
4040
import jdk.jpackage.test.Annotations.Parameters;
4141
import jdk.jpackage.test.Annotations.Test;
42+
import jdk.jpackage.test.CannedFormattedString;
43+
import jdk.jpackage.test.JPackageStringBundle;
4244
import jdk.jpackage.test.CfgFile;
4345
import jdk.jpackage.test.Executor;
4446
import jdk.jpackage.test.HelloApp;
4547
import jdk.jpackage.test.JPackageCommand;
48+
import static jdk.jpackage.test.JPackageCommand.cannedArgument;
4649
import jdk.jpackage.test.JavaAppDesc;
4750
import jdk.jpackage.test.JavaTool;
4851
import jdk.jpackage.test.TKit;
@@ -87,8 +90,8 @@ Script withJarMainClass(MainClassType v) {
8790
return this;
8891
}
8992

90-
Script expectedErrorMessage(String v) {
91-
expectedErrorMessage = v;
93+
Script expectedErrorMessage(String key, Object... args) {
94+
expectedErrorMessage = JPackageStringBundle.MAIN.cannedFormattedString(key, args);
9295
return this;
9396
}
9497

@@ -131,7 +134,7 @@ public String toString() {
131134
private boolean withJLink;
132135
private MainClassType mainClass;
133136
private MainClassType jarMainClass;
134-
private String expectedErrorMessage;
137+
private CannedFormattedString expectedErrorMessage;
135138
}
136139

137140
public MainClassTest(Script script) {
@@ -194,11 +197,12 @@ public static Collection<?> scripts() {
194197
if (withMainClass.contains(jarMainClass)
195198
|| withMainClass.contains(mainClass)) {
196199
} else if (modular) {
197-
script.expectedErrorMessage(
198-
"Error: Main application class is missing");
200+
script.expectedErrorMessage("ERR_NoMainClass");
199201
} else {
200202
script.expectedErrorMessage(
201-
"A main class was not specified nor was one found in the jar");
203+
"error.no-main-class-with-main-jar", cannedArgument(cmd -> {
204+
return cmd.getArgumentValue("--main-jar");
205+
}, "MAIN-JAR"));
202206
}
203207

204208
scripts.add(new Script[]{script});
@@ -218,11 +222,7 @@ public void test() throws IOException {
218222
if (script.expectedErrorMessage != null) {
219223
// This is the case when main class is not found nor in jar
220224
// file nor on command line.
221-
List<String> output = cmd
222-
.saveConsoleOutput(true)
223-
.execute(1)
224-
.getOutput();
225-
TKit.assertTextStream(script.expectedErrorMessage).apply(output.stream());
225+
cmd.validateOutput(script.expectedErrorMessage).execute(1);
226226
return;
227227
}
228228

0 commit comments

Comments
 (0)