Skip to content

Commit e76f3f7

Browse files
committed
Improve code coverage for JDK Installer
Fix adds platform specific tests to JDK unit tests
1 parent 549d0b1 commit e76f3f7

2 files changed

Lines changed: 54 additions & 27 deletions

File tree

browser/model/jdk-install.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ class JdkInstall extends InstallableItem {
6060
this.selectedOption = 'detected';
6161
} else if(process.platform !== 'darwin') {
6262
this.selectedOption = 'install';
63-
} else {
64-
this.selectedOption = 'detected';
6563
}
6664
resolve(true);
6765
} else {
@@ -76,6 +74,8 @@ class JdkInstall extends InstallableItem {
7674
var t = locationRegex.exec(output);
7775
if(t.length > 1) {
7876
this.option['detected'].location = t[1];
77+
} else {
78+
this.selectedOption = 'install';
7979
}
8080
done();
8181
}).catch((error) => {

test/unit/model/jdk-install-test.js

Lines changed: 52 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import fs from 'fs-extra';
88
import path from 'path';
99
import rimraf from 'rimraf';
1010
import Logger from 'browser/services/logger';
11+
import Platform from 'browser/services/platform';
1112
import Downloader from 'browser/model/helpers/downloader';
1213
import Util from 'browser/model/helpers/util';
1314
import JdkInstall from 'browser/model/jdk-install';
@@ -133,26 +134,6 @@ describe('JDK installer', function() {
133134
});
134135
});
135136

136-
it('should select openjdk for installation if not java detected', function(done) {
137-
let jdk = new JdkInstall(installerDataSvc, 'url', 'file');
138-
mockDetectedJvm('');
139-
return jdk.detectExistingInstall(function() {
140-
expect(jdk.selectedOption).to.be.equal('install');
141-
expect(jdk.getLocation()).to.be.equal('');
142-
done();
143-
});
144-
});
145-
146-
it('should select openjdk for installation if newer than supported version detected', function(done) {
147-
let jdk = new JdkInstall(installerDataSvc, 'url', 'file');
148-
mockDetectedJvm('1.9.0_1');
149-
return jdk.detectExistingInstall(function() {
150-
expect(jdk.selectedOption).to.be.equal('install');
151-
expect(jdk.getLocation()).to.be.equal('');
152-
done();
153-
});
154-
});
155-
156137
it('should create deafult empty callback if not provided', function() {
157138
let jdk = new JdkInstall(installerDataSvc, 'url', 'file');
158139
mockDetectedJvm('1.8.0_1');
@@ -163,8 +144,31 @@ describe('JDK installer', function() {
163144
}
164145
});
165146

166-
if (process.platform !== 'darwin') {
167-
it('should check for available msi installtion on windows platform', function(done) {
147+
describe('on windows', function(){
148+
it('should select openjdk for installation if not java detected', function(done) {
149+
sandbox.stub(Platform,'getOS').returns('win32');
150+
let jdk = new JdkInstall(installerDataSvc, 'url', 'file');
151+
mockDetectedJvm('');
152+
return jdk.detectExistingInstall(function() {
153+
expect(jdk.selectedOption).to.be.equal('install');
154+
expect(jdk.getLocation()).to.be.equal('');
155+
done();
156+
});
157+
});
158+
159+
it('should select openjdk for installation if newer than supported version detected', function(done) {
160+
sandbox.stub(Platform,'getOS').returns('win32');
161+
let jdk = new JdkInstall(installerDataSvc, 'url', 'file');
162+
mockDetectedJvm('1.9.0_1');
163+
return jdk.detectExistingInstall(function() {
164+
expect(jdk.selectedOption).to.be.equal('install');
165+
expect(jdk.getLocation()).to.be.equal('');
166+
done();
167+
});
168+
});
169+
170+
it('should check for available msi installtion', function(done) {
171+
sandbox.stub(Platform,'getOS').returns('win32');
168172
mockDetectedJvm('1.8.0_1');
169173
let jdk = new JdkInstall(installerDataSvc, 'url', 'file');
170174
jdk.findMsiInstalledJava.restore();
@@ -174,8 +178,31 @@ describe('JDK installer', function() {
174178
done();
175179
});
176180
});
177-
} else {
178-
it('should not check for available msi installtion on none windows platforms', function(done) {
181+
});
182+
183+
describe('on macos', function() {
184+
it('should not select jdk for installation if not java detected', function(done) {
185+
sandbox.stub(Platform,'getOS').returns('darwin');
186+
let jdk = new JdkInstall(installerDataSvc, 'url', 'file');
187+
mockDetectedJvm('');
188+
return jdk.detectExistingInstall(function() {
189+
expect(jdk.selectedOption).to.be.equal('detected');
190+
done();
191+
});
192+
});
193+
194+
it('should not select openjdk for installation if newer than supported version detected', function(done) {
195+
sandbox.stub(Platform,'getOS').returns('darwin');
196+
let jdk = new JdkInstall(installerDataSvc, 'url', 'file');
197+
mockDetectedJvm('1.9.0_1');
198+
return jdk.detectExistingInstall(function() {
199+
expect(jdk.selectedOption).to.be.equal('detected');
200+
done();
201+
});
202+
});
203+
204+
it('should not check for available msi installtion', function(done) {
205+
sandbox.stub(Platform,'getOS').returns('darwin');
179206
mockDetectedJvm('1.8.0_1');
180207
let jdk = new JdkInstall(installerDataSvc, 'url', 'file');
181208
jdk.findMsiInstalledJava.restore();
@@ -185,7 +212,7 @@ describe('JDK installer', function() {
185212
done();
186213
});
187214
});
188-
}
215+
});
189216
});
190217

191218
describe('when downloading the jdk msi', function() {

0 commit comments

Comments
 (0)