@@ -214,6 +214,93 @@ describe('setupJava', () => {
214214 ) ;
215215 } ) ;
216216
217+ it ( 'java is resolved from toolcache including Contents/Home on MacOS' , async ( ) => {
218+ const inputs = {
219+ version : actualJavaVersion ,
220+ architecture : 'x86' ,
221+ packageType : 'jdk' ,
222+ checkLatest : false
223+ } ;
224+ const jdkFile = 'not_existing_one' ;
225+ const expected = {
226+ version : actualJavaVersion ,
227+ path : path . join (
228+ 'Java_jdkfile_jdk' ,
229+ inputs . version ,
230+ inputs . architecture ,
231+ 'Contents' ,
232+ 'Home'
233+ )
234+ } ;
235+ const originalPlatform = process . platform ;
236+ Object . defineProperty ( process , 'platform' , {
237+ value : 'darwin'
238+ } ) ;
239+
240+ spyFsStat = jest . spyOn ( fs , 'existsSync' ) ;
241+ spyFsStat . mockImplementation ( ( file : string ) => {
242+ return file . endsWith ( 'Home' ) ;
243+ } ) ;
244+
245+ mockJavaBase = new LocalDistribution ( inputs , jdkFile ) ;
246+ await expect ( mockJavaBase . setupJava ( ) ) . resolves . toEqual ( expected ) ;
247+ expect ( spyGetToolcachePath ) . toHaveBeenCalled ( ) ;
248+ expect ( spyCoreInfo ) . toHaveBeenCalledWith (
249+ `Resolved Java ${ actualJavaVersion } from tool-cache`
250+ ) ;
251+ expect ( spyCoreInfo ) . not . toHaveBeenCalledWith (
252+ `Java ${ inputs . version } was not found in tool-cache. Trying to unpack JDK file...`
253+ ) ;
254+
255+ Object . defineProperty ( process , 'platform' , {
256+ value : originalPlatform
257+ } ) ;
258+ } ) ;
259+
260+ it ( 'java is unpacked from jdkfile including Contents/Home on MacOS' , async ( ) => {
261+ const inputs = {
262+ version : '11.0.289' ,
263+ architecture : 'x86' ,
264+ packageType : 'jdk' ,
265+ checkLatest : false
266+ } ;
267+ const jdkFile = expectedJdkFile ;
268+ const expected = {
269+ version : '11.0.289' ,
270+ path : path . join (
271+ 'Java_jdkfile_jdk' ,
272+ inputs . version ,
273+ inputs . architecture ,
274+ 'Contents' ,
275+ 'Home'
276+ )
277+ } ;
278+ const originalPlatform = process . platform ;
279+ Object . defineProperty ( process , 'platform' , {
280+ value : 'darwin'
281+ } ) ;
282+ spyFsStat = jest . spyOn ( fs , 'existsSync' ) ;
283+ spyFsStat . mockImplementation ( ( file : string ) => {
284+ return file . endsWith ( 'Home' ) ;
285+ } ) ;
286+
287+ mockJavaBase = new LocalDistribution ( inputs , jdkFile ) ;
288+ await expect ( mockJavaBase . setupJava ( ) ) . resolves . toEqual ( expected ) ;
289+ expect ( spyTcFindAllVersions ) . toHaveBeenCalled ( ) ;
290+ expect ( spyCoreInfo ) . not . toHaveBeenCalledWith (
291+ `Resolved Java ${ actualJavaVersion } from tool-cache`
292+ ) ;
293+ expect ( spyCoreInfo ) . toHaveBeenCalledWith (
294+ `Extracting Java from '${ jdkFile } '`
295+ ) ;
296+ expect ( spyCoreInfo ) . toHaveBeenCalledWith (
297+ `Java ${ inputs . version } was not found in tool-cache. Trying to unpack JDK file...`
298+ ) ;
299+ Object . defineProperty ( process , 'platform' , {
300+ value : originalPlatform
301+ } ) ;
302+ } ) ;
303+
217304 it . each ( [
218305 [
219306 {
0 commit comments