PassengerProfileEnricher { public Passenger addProfileIfAvailable(Passenger passenger) { String ffNumber = passenger.getFrequentFlyerNumber(); if (ffNumber != null) { Profile profile = this.frequentFlyerService.lookupProfile(ffNumber); if (profile != null) { passenger.addProfile(profile); } } return passenger; } @Autowired  PassengerProfileEnricher(FrequentFlyerService ffService); Passenger addProfileIfAvailable(Passenger passenger);  }
@Test public void noFrequentFlyerNumberNoProfile() { FrequentFlyerService ffService = new StubFrequentFlyerService(); PassengerProfileEnricher enricher = new PassengerProfileEnricher(ffService); Passenger passenger = new Passenger(); assertNull(passenger.getProfile()); enricher.addProfileIfAvailable(passenger); assertNull(passenger.getProfile()); }
@Test public void frequentFlyerNumberProfileLookupSucceeds() { FrequentFlyerService ffService = new StubFrequentFlyerService(); PassengerProfileEnricher enricher = new PassengerProfileEnricher(ffService); Passenger passenger = new Passenger(); passenger.setFrequentFlyerNumber("123ABC"); assertNull(passenger.getProfile()); enricher.addProfileIfAvailable(passenger); assertNotNull(passenger.getProfile()); }