39
39
import jdk .jpackage .internal .util .function .ThrowingConsumer ;
40
40
import jdk .jpackage .test .Annotations .Parameters ;
41
41
import jdk .jpackage .test .Annotations .Test ;
42
+ import jdk .jpackage .test .CannedFormattedString ;
43
+ import jdk .jpackage .test .JPackageStringBundle ;
42
44
import jdk .jpackage .test .CfgFile ;
43
45
import jdk .jpackage .test .Executor ;
44
46
import jdk .jpackage .test .HelloApp ;
45
47
import jdk .jpackage .test .JPackageCommand ;
48
+ import static jdk .jpackage .test .JPackageCommand .cannedArgument ;
46
49
import jdk .jpackage .test .JavaAppDesc ;
47
50
import jdk .jpackage .test .JavaTool ;
48
51
import jdk .jpackage .test .TKit ;
@@ -87,8 +90,8 @@ Script withJarMainClass(MainClassType v) {
87
90
return this ;
88
91
}
89
92
90
- Script expectedErrorMessage (String v ) {
91
- expectedErrorMessage = v ;
93
+ Script expectedErrorMessage (String key , Object ... args ) {
94
+ expectedErrorMessage = JPackageStringBundle . MAIN . cannedFormattedString ( key , args ) ;
92
95
return this ;
93
96
}
94
97
@@ -131,7 +134,7 @@ public String toString() {
131
134
private boolean withJLink ;
132
135
private MainClassType mainClass ;
133
136
private MainClassType jarMainClass ;
134
- private String expectedErrorMessage ;
137
+ private CannedFormattedString expectedErrorMessage ;
135
138
}
136
139
137
140
public MainClassTest (Script script ) {
@@ -194,11 +197,12 @@ public static Collection<?> scripts() {
194
197
if (withMainClass .contains (jarMainClass )
195
198
|| withMainClass .contains (mainClass )) {
196
199
} else if (modular ) {
197
- script .expectedErrorMessage (
198
- "Error: Main application class is missing" );
200
+ script .expectedErrorMessage ("ERR_NoMainClass" );
199
201
} else {
200
202
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" ));
202
206
}
203
207
204
208
scripts .add (new Script []{script });
@@ -218,11 +222,7 @@ public void test() throws IOException {
218
222
if (script .expectedErrorMessage != null ) {
219
223
// This is the case when main class is not found nor in jar
220
224
// 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 );
226
226
return ;
227
227
}
228
228
0 commit comments