(address == null) throw new IllegalArgumentException(“…”); this.address = address; } public Address getAddress() { if (address == null) return new UnknownAddress(); return address; } public String getPhoneNumber() { return Optional.ofNullable(address) .map(Address::getPhoneNumber) .orElse("Phone number is not available"); } }
a_registration = Registration.new a_ticket_store = double("TicketStore") end it ‘tickets available' do expect(a_ticket_store).to receive(:tickets_available?). with(a_conference).and_return(true) expect(a_ticket_store).to receive(:remove).with(a_conference) a_registration.process(a_ticket_store) expect(a_registration.confirmed?).to eq(true) end it ‘run out of tickets' do expect(a_ticket_store).to receive(:tickets_available?). with(a_conference).and_return(false) a_registration.process(a_ticket_store) expect(a_registration.confirmed?).to eq(false) end end