@@ -241,6 +241,31 @@ describe("SysInfo unit tests", () => {
241
241
assert . deepEqual ( execCommands , [ 'which javac' , '"javac" -version' ] ) ;
242
242
} ) ;
243
243
244
+ it ( "null when there is incorrect JAVA_HOME on non-Windows OS" , async ( ) => {
245
+ const originalJavaHome = process . env [ JavaHomeName ] ;
246
+ process . env [ JavaHomeName ] = "/some/invalid/dir/name/where/java/does/not/exist" ;
247
+
248
+ const result = await sysInfo . getJavaCompilerVersion ( ) ;
249
+
250
+ process . env [ JavaHomeName ] = originalJavaHome ;
251
+
252
+ assert . deepEqual ( result , null ) ;
253
+ assert . deepEqual ( execCommands , [ ] ) ;
254
+ } ) ;
255
+
256
+ it ( "null when there is incorrect JAVA_HOME on Window OS" , async ( ) => {
257
+ const originalJavaHome = process . env [ JavaHomeName ] ;
258
+ hostInfo . isWindows = true ;
259
+ process . env [ JavaHomeName ] = "C:\\Program Files\\Not existing dir" ;
260
+
261
+ const result = await sysInfo . getJavaCompilerVersion ( ) ;
262
+
263
+ process . env [ JavaHomeName ] = originalJavaHome ;
264
+
265
+ assert . deepEqual ( result , null ) ;
266
+ assert . deepEqual ( execCommands , [ ] ) ;
267
+ } ) ;
268
+
244
269
it ( "java compiler version when there is no JAVA_HOME on Window OS" , async ( ) => {
245
270
const originalJavaHome = process . env [ JavaHomeName ] ;
246
271
hostInfo . isWindows = true ;
0 commit comments