Skip to content

Instantly share code, notes, and snippets.

@simcap
Created September 13, 2012 08:43
Show Gist options
  • Save simcap/3712955 to your computer and use it in GitHub Desktop.
Save simcap/3712955 to your computer and use it in GitHub Desktop.
Unit tests - Good & bad
public class SetCarrierServiceFacade {
@Autowired
private CarrierService carrierService;
@Autowired
private UserService userService;
@Autowired
private UserContactPointService userContactPointService;
@Autowired
private MessageService messageService;
@Autowired
private PreferenceService preferenceService;
@Transactional(propagation = Propagation.REQUIRED)
public void selectCarrier(Long carrierId, String msisdn, ApplicationEntity applicationEntity)
throws OnDoesNotExistsException {
final CarrierEntity carrier = carrierService.findById(carrierId);
Long userId = userService.findLegacyUserIdByValidatedContactPoint(msisdn);
UserEntity user = userService.findByIdWithCarrierPhoneNumbers(userId);
ArrayList<CarrierPhoneNumberEntity> oldNumbers = new ArrayList<CarrierPhoneNumberEntity>(
user.getCarrierPhoneNumbers());
Iterables.removeIf(user.getCarrierPhoneNumbers(), new Predicate<CarrierPhoneNumberEntity>() {
@Override
public boolean apply(CarrierPhoneNumberEntity cpn) {
return cpn.getCarrier().getId().equals(carrier.getId());
}
});
for (CarrierPhoneNumberType type : CarrierPhoneNumberType.values()) {
CarrierPhoneNumberEntity number = carrier.findLatestActivePhoneNumberMaxWeightIfNotInListAndExpired(type,
oldNumbers);
if (number == null) {
throw new IllegalStateException("No number of type " + type + " found for carrier " + carrier);
}
user.getCarrierPhoneNumbers().add(number);
}
userContactPointService.setCarrierForValidatedContactPoint(msisdn, carrier);
String password = preferenceService.getVmsAccessCode(user);
if (applicationEntity.getName().equals(ApplicationEntity.IPHONE_LIBON)) {
messageService.createOnSystemMessage(user, "#web#VOICEMAIL_BOX_CREATED_TEXT", password);
} else {
messageService.createOnSystemMessage(user, "#web#VOICEMAIL_BOX_CREATED_TEXT_VOICEFEED", password);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment