@@ -72,6 +72,15 @@ describe('JDK installer', function() {
7272 sandbox . restore ( ) ;
7373 } ) ;
7474
75+ function mockDetectedJvm ( version , location = 'java.home = /java/home\n' ) {
76+ sandbox . stub ( JdkInstall . prototype , 'findMsiInstalledJava' ) . returns ( Promise . resolve ( '' ) ) ;
77+ sandbox . stub ( Util , 'executeCommand' )
78+ . onFirstCall ( ) . returns ( Promise . resolve ( `version "${ version } "` ) )
79+ . onSecondCall ( ) . returns ( Promise . resolve ( location ) ) ;
80+ sandbox . stub ( Util , 'writeFile' ) . returns ( Promise . resolve ( true ) ) ;
81+ sandbox . stub ( Util , 'executeFile' ) . returns ( Promise . resolve ( true ) ) ;
82+ }
83+
7584 describe ( 'when instantiated' , function ( ) {
7685
7786 it ( 'should not download jdk when an installation exists' , function ( ) {
@@ -99,19 +108,12 @@ describe('JDK installer', function() {
99108 expect ( new JdkInstall ( installerDataSvc , 'url' , null ) . downloadedFile ) . to . equal (
100109 path . join ( 'tempDirectory' , 'jdk.msi' ) ) ;
101110 } ) ;
102-
103111 } ) ;
104112
113+ // FIXME expect calls in done callback does not report errors
114+ // because if expect fails it gets cought in catch() and then
115+ // function callback done called again
105116 describe ( 'when detecting existing installation' , function ( ) {
106- let writeFileStub , executeFileStub ;
107- function mockDetectedJvm ( version ) {
108- sandbox . stub ( JdkInstall . prototype , 'findMsiInstalledJava' ) . returns ( Promise . resolve ( '' ) ) ;
109- sandbox . stub ( Util , 'executeCommand' )
110- . onFirstCall ( ) . returns ( Promise . resolve ( `version "${ version } "` ) )
111- . onSecondCall ( ) . returns ( Promise . resolve ( 'java.home = /java/home\n' ) ) ;
112- writeFileStub = sandbox . stub ( Util , 'writeFile' ) . returns ( Promise . resolve ( true ) ) ;
113- executeFileStub = sandbox . stub ( Util , 'executeFile' ) . returns ( Promise . resolve ( true ) ) ;
114- }
115117
116118 it ( 'should detect java location if installed' , function ( done ) {
117119 let jdk = new JdkInstall ( installerDataSvc , 'url' , 'file' ) ;
@@ -124,16 +126,6 @@ describe('JDK installer', function() {
124126 } ) ;
125127 } ) ;
126128
127- it ( 'should select openjdk for installation if older than supported version detected' , function ( done ) {
128- let jdk = new JdkInstall ( installerDataSvc , 'url' , 'file' ) ;
129- mockDetectedJvm ( '1.7.0_111' ) ;
130- return jdk . detectExistingInstall ( function ( ) {
131- expect ( jdk . selectedOption ) . to . be . equal ( 'install' ) ;
132- expect ( jdk . getLocation ( ) ) . to . be . equal ( '' ) ;
133- done ( ) ;
134- } ) ;
135- } ) ;
136-
137129 it ( 'should create deafult empty callback if not provided' , function ( ) {
138130 let jdk = new JdkInstall ( installerDataSvc , 'url' , 'file' ) ;
139131 mockDetectedJvm ( '1.8.0_1' ) ;
@@ -144,8 +136,16 @@ describe('JDK installer', function() {
144136 }
145137 } ) ;
146138
139+ it ( 'should not fail if selected option is not present in available options' , function ( ) {
140+ let jdk = new JdkInstall ( installerDataSvc , 'url' , 'file' ) ;
141+ jdk . selectedOption = 'detected' ;
142+ jdk . validateVersion ( ) ;
143+ } ) ;
144+
145+
146+
147147 describe ( 'on windows' , function ( ) {
148- it ( 'should select openjdk for installation if not java detected' , function ( done ) {
148+ it ( 'should select openjdk for installation if no java detected' , function ( done ) {
149149 sandbox . stub ( Platform , 'getOS' ) . returns ( 'win32' ) ;
150150 let jdk = new JdkInstall ( installerDataSvc , 'url' , 'file' ) ;
151151 mockDetectedJvm ( '' ) ;
@@ -156,13 +156,34 @@ describe('JDK installer', function() {
156156 } ) ;
157157 } ) ;
158158
159- it ( 'should select openjdk for installation if newer than supported version detected' , function ( done ) {
159+
160+ // FIXME is not the case for JDK 9, because version has different format
161+ it ( 'should select openjdk for installation if newer than supported java version detected' , function ( done ) {
160162 sandbox . stub ( Platform , 'getOS' ) . returns ( 'win32' ) ;
161163 let jdk = new JdkInstall ( installerDataSvc , 'url' , 'file' ) ;
162164 mockDetectedJvm ( '1.9.0_1' ) ;
165+ return jdk . detectExistingInstall ( function ( ) {
166+ expect ( jdk . selectedOption ) . to . be . equal ( 'detected' ) ;
167+ done ( ) ;
168+ } ) ;
169+ } ) ;
170+
171+ it ( 'should select openjdk for installation if older than supported java version detected' , function ( done ) {
172+ sandbox . stub ( Platform , 'getOS' ) . returns ( 'win32' ) ;
173+ let jdk = new JdkInstall ( installerDataSvc , 'url' , 'file' ) ;
174+ mockDetectedJvm ( '1.7.0_1' ) ;
175+ return jdk . detectExistingInstall ( function ( ) {
176+ expect ( jdk . selectedOption ) . to . be . equal ( 'install' ) ;
177+ done ( ) ;
178+ } ) ;
179+ } ) ;
180+
181+ it ( 'should select openjdk for installation if location for java is not found' , function ( done ) {
182+ sandbox . stub ( Platform , 'getOS' ) . returns ( 'win32' ) ;
183+ let jdk = new JdkInstall ( installerDataSvc , 'url' , 'file' ) ;
184+ mockDetectedJvm ( '1.8.0_1' , '' ) ;
163185 return jdk . detectExistingInstall ( function ( ) {
164186 expect ( jdk . selectedOption ) . to . be . equal ( 'install' ) ;
165- expect ( jdk . getLocation ( ) ) . to . be . equal ( '' ) ;
166187 done ( ) ;
167188 } ) ;
168189 } ) ;
@@ -173,15 +194,15 @@ describe('JDK installer', function() {
173194 let jdk = new JdkInstall ( installerDataSvc , 'url' , 'file' ) ;
174195 jdk . findMsiInstalledJava . restore ( ) ;
175196 return jdk . detectExistingInstall ( function ( ) {
176- expect ( executeFileStub ) . to . have . been . calledOnce ;
177- expect ( writeFileStub ) . to . have . been . calledOnce ;
197+ expect ( Util . executeFile ) . to . have . been . calledOnce ;
198+ expect ( Util . writeFile ) . to . have . been . calledOnce ;
178199 done ( ) ;
179200 } ) ;
180201 } ) ;
181202 } ) ;
182203
183204 describe ( 'on macos' , function ( ) {
184- it ( 'should not select jdk for installation if not java detected' , function ( done ) {
205+ it ( 'should not select jdk for installation if no java detected' , function ( done ) {
185206 sandbox . stub ( Platform , 'getOS' ) . returns ( 'darwin' ) ;
186207 let jdk = new JdkInstall ( installerDataSvc , 'url' , 'file' ) ;
187208 mockDetectedJvm ( '' ) ;
@@ -191,7 +212,7 @@ describe('JDK installer', function() {
191212 } ) ;
192213 } ) ;
193214
194- it ( 'should not select openjdk for installation if newer than supported version detected' , function ( done ) {
215+ it ( 'should not select openjdk for installation if newer than supported supported version detected' , function ( done ) {
195216 sandbox . stub ( Platform , 'getOS' ) . returns ( 'darwin' ) ;
196217 let jdk = new JdkInstall ( installerDataSvc , 'url' , 'file' ) ;
197218 mockDetectedJvm ( '1.9.0_1' ) ;
@@ -201,14 +222,24 @@ describe('JDK installer', function() {
201222 } ) ;
202223 } ) ;
203224
225+ it ( 'should not select openjdk for installation if older than supported supported java version detected' , function ( done ) {
226+ sandbox . stub ( Platform , 'getOS' ) . returns ( 'darwin' ) ;
227+ let jdk = new JdkInstall ( installerDataSvc , 'url' , 'file' ) ;
228+ mockDetectedJvm ( '1.7.0_1' ) ;
229+ return jdk . detectExistingInstall ( function ( ) {
230+ expect ( jdk . selectedOption ) . to . be . equal ( 'detected' ) ;
231+ done ( ) ;
232+ } ) ;
233+ } ) ;
234+
204235 it ( 'should not check for available msi installtion' , function ( done ) {
205236 sandbox . stub ( Platform , 'getOS' ) . returns ( 'darwin' ) ;
206237 mockDetectedJvm ( '1.8.0_1' ) ;
207238 let jdk = new JdkInstall ( installerDataSvc , 'url' , 'file' ) ;
208239 jdk . findMsiInstalledJava . restore ( ) ;
209240 return jdk . detectExistingInstall ( function ( ) {
210- expect ( executeFileStub ) . to . have . not . been . called ;
211- expect ( writeFileStub ) . to . have . not . been . called ;
241+ expect ( Util . executeFile ) . to . have . not . been . called ;
242+ expect ( Util . writeFile ) . to . have . not . been . called ;
212243 done ( ) ;
213244 } ) ;
214245 } ) ;
@@ -335,6 +366,21 @@ describe('JDK installer', function() {
335366 expect ( calls ) . to . equal ( 1 ) ;
336367 } ) ;
337368
369+ it ( 'should not change installerDataSvc.jdkRoot if the same location found in install log' , function ( done ) {
370+ sandbox . stub ( require ( 'child_process' ) , 'execFile' ) . yields ( ) ;
371+ sandbox . stub ( Installer . prototype , 'execFile' ) . returns ( Promise . resolve ( true ) ) ;
372+ sandbox . stub ( Util , 'findText' ) . returns ( Promise . resolve ( 'Dir \(target\): Key: INSTALLDIR , Object: target/install' ) ) ;
373+ installer = new JdkInstall ( installerDataSvc , downloadUrl , null ) ;
374+ sandbox . stub ( installer , 'getLocation' ) . returns ( 'target/install' ) ;
375+ installerDataSvc . jdkRoot = 'install/jdk8' ;
376+ return installer . install ( fakeProgress , function ( ) {
377+ expect ( installerDataSvc . jdkRoot ) . to . be . equal ( 'install/jdk8' ) ;
378+ done ( ) ;
379+ } , function ( ) {
380+ expect . fail ( 'it should not fail' ) ;
381+ } ) ;
382+ } ) ;
383+
338384 describe ( 'files manipulation' , function ( ) {
339385 let err = new Error ( 'critical error' ) ;
340386
0 commit comments