Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/lib/JreSetupManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,13 @@ class JreSetupManager extends AsyncCreatable {
}

private async verifyJavaVersion(javaHome: string): Promise<void> {
const versionCommandOut = await this.fetchJavaVersion(javaHome);
let versionCommandOut: string;
try {
versionCommandOut = await this.fetchJavaVersion(javaHome);
} catch (e) {
const msg: string = e instanceof Error ? e.message : e as string;
throw new SfError(msg, 'CouldNotFindJavaVersion');
}

// We are using "java -version" below which has output that typically looks like:
// * (from MacOS): "openjdk version "11.0.6" 2020-01-14 LTS\nOpenJDK Runtime Environment Zulu11.37+17-CA (build 11.0.6+10-LTS)\nOpenJDK 64-Bit Server VM Zulu11.37+17-CA (build 11.0.6+10-LTS, mixed mode)\n"
Expand Down
24 changes: 24 additions & 0 deletions test/lib/JreSetupManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,30 @@ describe('JreSetupManager #verifyJreSetup', () => {
statStub.restore();
});

it('should fail when valid path is found, but Java version cannot be returned', async () => {
// More stubbing
Sinon.stub(Config.prototype, 'getJavaHome').returns(javaHomeValidPath);
// FileHandler claims the path is valid.
Sinon.stub(FileHandler.prototype, 'stats').resolves();
// Error indicates that version could not be retrieved.
Sinon.stub(childProcess, 'execFile').yields(error, emptyStdout, 'irrelevant');

// Execute and verify
let threw = false;
let name: string = '';
let message: string = '';
try {
await verifyJreSetup();
} catch (err) {
threw = true;
name = err.name;
message = err instanceof Error ? err.message : err as string;
}
expect(threw).equals(true);
expect(message).contains('Could not fetch Java version from path');
expect(name).equals('CouldNotFindJavaVersion');
});

it('should fail when valid path is found, but Java version is not acceptable', async () => {
// More stubbing
const configGetJavaHomeStub = Sinon.stub(Config.prototype, 'getJavaHome').returns(javaHomeValidPath);
Expand Down
Loading