| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-21 02:50:52 +01:00
										 |  |  | require "requirements/java_requirement" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe JavaRequirement do | 
					
						
							|  |  |  |   subject { described_class.new([]) } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  |   before do | 
					
						
							| 
									
										
										
										
											2017-02-21 02:50:52 +01:00
										 |  |  |     ENV["JAVA_HOME"] = nil | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "#message" do | 
					
						
							|  |  |  |     its(:message) { is_expected.to match(/Java is required to install this formula./) } | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "#inspect" do | 
					
						
							|  |  |  |     subject { described_class.new(%w[1.7+]) } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-19 16:38:41 +01:00
										 |  |  |     its(:inspect) { is_expected.to eq('#<JavaRequirement: [] version="1.7+">') } | 
					
						
							| 
									
										
										
										
											2017-02-21 02:50:52 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "#display_s" do | 
					
						
							|  |  |  |     context "without specific version" do | 
					
						
							|  |  |  |       its(:display_s) { is_expected.to eq("java") } | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     context "with version 1.8" do | 
					
						
							|  |  |  |       subject { described_class.new(%w[1.8]) } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-21 02:50:52 +01:00
										 |  |  |       its(:display_s) { is_expected.to eq("java = 1.8") } | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     context "with version 1.8+" do | 
					
						
							|  |  |  |       subject { described_class.new(%w[1.8+]) } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-21 02:50:52 +01:00
										 |  |  |       its(:display_s) { is_expected.to eq("java >= 1.8") } | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "#satisfied?" do | 
					
						
							|  |  |  |     subject { described_class.new(%w[1.8]) } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "returns false if no `java` executable can be found" do | 
					
						
							|  |  |  |       allow(File).to receive(:executable?).and_return(false) | 
					
						
							|  |  |  |       expect(subject).not_to be_satisfied | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "returns true if #preferred_java returns a path" do | 
					
						
							|  |  |  |       allow(subject).to receive(:preferred_java).and_return(Pathname.new("/usr/bin/java")) | 
					
						
							|  |  |  |       expect(subject).to be_satisfied | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     context "when #possible_javas contains paths" do | 
					
						
							| 
									
										
										
										
											2017-02-28 14:50:46 +01:00
										 |  |  |       let(:path) { mktmpdir } | 
					
						
							| 
									
										
										
										
											2017-02-21 02:50:52 +01:00
										 |  |  |       let(:java) { path/"java" } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def setup_java_with_version(version) | 
					
						
							| 
									
										
										
										
											2018-07-11 15:17:40 +02:00
										 |  |  |         IO.write java, <<~SH | 
					
						
							| 
									
										
										
										
											2017-02-21 02:50:52 +01:00
										 |  |  |           #!/bin/sh | 
					
						
							| 
									
										
										
										
											2018-08-29 19:56:32 +02:00
										 |  |  |           echo 'java version "#{version}"' 1>&2
 | 
					
						
							| 
									
										
										
										
											2018-07-11 15:17:40 +02:00
										 |  |  |         SH | 
					
						
							| 
									
										
										
										
											2017-02-21 02:50:52 +01:00
										 |  |  |         FileUtils.chmod "+x", java | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  |       before do | 
					
						
							| 
									
										
										
										
											2017-02-21 02:50:52 +01:00
										 |  |  |         allow(subject).to receive(:possible_javas).and_return([java]) | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "and 1.7 is required" do | 
					
						
							|  |  |  |         subject { described_class.new(%w[1.7]) } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         it "returns false if all are lower" do | 
					
						
							|  |  |  |           setup_java_with_version "1.6.0_5" | 
					
						
							|  |  |  |           expect(subject).not_to be_satisfied | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         it "returns true if one is equal" do | 
					
						
							|  |  |  |           setup_java_with_version "1.7.0_5" | 
					
						
							|  |  |  |           expect(subject).to be_satisfied | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         it "returns false if all are higher" do | 
					
						
							|  |  |  |           setup_java_with_version "1.8.0_5" | 
					
						
							|  |  |  |           expect(subject).not_to be_satisfied | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "and 1.7+ is required" do | 
					
						
							|  |  |  |         subject { described_class.new(%w[1.7+]) } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         it "returns false if all are lower" do | 
					
						
							|  |  |  |           setup_java_with_version "1.6.0_5" | 
					
						
							|  |  |  |           expect(subject).not_to be_satisfied | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         it "returns true if one is equal" do | 
					
						
							|  |  |  |           setup_java_with_version "1.7.0_5" | 
					
						
							|  |  |  |           expect(subject).to be_satisfied | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         it "returns true if one is higher" do | 
					
						
							|  |  |  |           setup_java_with_version "1.8.0_5" | 
					
						
							|  |  |  |           expect(subject).to be_satisfied | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2019-06-10 10:37:09 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   describe "#suggestion" do | 
					
						
							|  |  |  |     context "without specific version" do | 
					
						
							|  |  |  |       its(:suggestion) { is_expected.to match(/brew cask install adoptopenjdk/) } | 
					
						
							|  |  |  |       its(:cask) { is_expected.to eq("adoptopenjdk") } | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     context "with version 1.8" do | 
					
						
							|  |  |  |       subject { described_class.new(%w[1.8]) } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       its(:suggestion) { is_expected.to match(%r{brew cask install homebrew/cask-versions/adoptopenjdk8}) } | 
					
						
							|  |  |  |       its(:cask) { is_expected.to eq("homebrew/cask-versions/adoptopenjdk8") } | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     context "with version 1.8+" do | 
					
						
							|  |  |  |       subject { described_class.new(%w[1.8+]) } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       its(:suggestion) { is_expected.to match(/brew cask install adoptopenjdk/) } | 
					
						
							|  |  |  |       its(:cask) { is_expected.to eq("adoptopenjdk") } | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2017-02-21 02:50:52 +01:00
										 |  |  | end |