@@ -65,15 +65,6 @@ public function testGetPathWithDownloadUrlAndNotRealDirectory(): void {
6565 $ service ->getPath ($ jsignParam );
6666 }
6767
68- public function testGetPathWithDownloadUrlAndEmptyJavaVersion (): void {
69- $ jsignParam = new JSignParam ();
70- $ service = new JavaRuntimeService ();
71- $ jsignParam ->setJavaVersion ('' );
72- $ this ->expectException (InvalidArgumentException::class);
73- $ this ->expectExceptionMessageMatches ('/Java version required/ ' );
74- $ service ->getPath ($ jsignParam );
75- }
76-
7768 public function testGetPathWithDownloadUrlWithInvalidUrl (): void {
7869 vfsStream::setup ('download ' );
7970 mkdir ('vfs://download/bin ' );
@@ -83,7 +74,6 @@ public function testGetPathWithDownloadUrlWithInvalidUrl(): void {
8374 $ service = new JavaRuntimeService ();
8475 $ jsignParam ->setJavaPath ('vfs://download/bin/java ' );
8576 $ jsignParam ->setJavaDownloadUrl ('invalid_url ' );
86- $ jsignParam ->setJavaVersion ('21.0.0 ' );
8777 $ this ->expectException (InvalidArgumentException::class);
8878 $ this ->expectExceptionMessageMatches ('/url.*invalid/ ' );
8979 $ service ->getPath ($ jsignParam );
@@ -98,7 +88,6 @@ public function testGetPathWithDownloadUrlWith4xxError(): void {
9888 $ service = new JavaRuntimeService ();
9989 $ jsignParam ->setJavaPath ('vfs://download/bin/java ' );
10090 $ jsignParam ->setJavaDownloadUrl ('https://404.domain ' );
101- $ jsignParam ->setJavaVersion ('21.0.0 ' );
10291 $ this ->expectException (InvalidArgumentException::class);
10392 $ this ->expectExceptionMessageMatches ('/Failure to download/ ' );
10493 $ service ->getPath ($ jsignParam );
@@ -125,7 +114,6 @@ public function testGetPathWithDownloadUrlWithInvalidGzipedFile(): void {
125114 $ url = $ server ->getServerRoot ();
126115 $ jsignParam ->setJavaDownloadUrl ($ url );
127116
128- $ jsignParam ->setJavaVersion ('21.0.0 ' );
129117 $ this ->expectException (InvalidArgumentException::class);
130118 $ this ->expectExceptionMessageMatches ('/cannot be extracted/ ' );
131119 $ service ->getPath ($ jsignParam );
@@ -153,12 +141,48 @@ public function testGetPathWithDownloadUrlWithInvalidJavaPackage(): void {
153141 $ url = $ server ->getServerRoot ();
154142 $ jsignParam ->setJavaDownloadUrl ($ url );
155143
156- $ jsignParam ->setJavaVersion ('21.0.0 ' );
157144 $ this ->expectException (InvalidArgumentException::class);
158145 $ this ->expectExceptionMessageMatches ('/Invalid tar content/ ' );
159146 $ service ->getPath ($ jsignParam );
160147 }
161148
149+ public function testGetPathWithDownloadUrlWithInvalidVersion (): void {
150+ $ jsignParam = new JSignParam ();
151+ $ service = new JavaRuntimeService ();
152+
153+ // When the version is invalid, will try to download the package
154+ $ server = new MockWebServer ();
155+ $ server ->start ();
156+ $ server ->setResponseOfPath (
157+ '/ ' ,
158+ new Response ('invalid response ' ),
159+ );
160+ $ baseUrl = $ server ->getServerRoot ();
161+ $ url = $ baseUrl . '/OpenJDK21U-jre_x64_linux_hotspot_21.0.8_9.tar.gz ' ;
162+ $ jsignParam ->setJavaDownloadUrl ($ url );
163+
164+ $ this ->expectException (InvalidArgumentException::class);
165+ $ this ->expectExceptionMessageMatches ('/cannot be extracted/ ' );
166+ $ service ->getPath ($ jsignParam );
167+ }
168+
169+ public function testGetPathWithDownloadUrlWithValidVersion (): void {
170+ $ jsignParam = new JSignParam ();
171+ $ service = new JavaRuntimeService ();
172+
173+ $ tarGzFilename = 'OpenJDK21U-jre_x64_linux_hotspot_21.0.8_9.tar.gz ' ;
174+ $ url = 'https://fake.url/ ' . $ tarGzFilename ;
175+ $ jsignParam ->setJavaDownloadUrl ($ url );
176+
177+ // When have a file with an expected name, will consider that the
178+ // downloaded java version is right
179+ touch ($ this ->testTmpDir . '/.java_version_ ' . $ tarGzFilename );
180+ $ jsignParam ->setJavaPath ($ this ->testTmpDir . '/bin/java ' );
181+
182+ $ javaPath = $ service ->getPath ($ jsignParam );
183+ $ this ->assertEquals ($ jsignParam ->getJavaPath (), $ javaPath );
184+ }
185+
162186 public function testGetPathWithoutJavaFallback (): void {
163187 mkdir ($ this ->testTmpDir . '/bin ' , 0755 , true );
164188
0 commit comments