Ejemplo n.º 1
0
  @Test
  public void testBothLocationsNullCollected() {
    PaymentRepository paymentRepository = createNiceMock(PaymentRepository.class);
    NotificationRepository notificationRepository = createNiceMock(NotificationRepository.class);
    UserRepository userRepository = createNiceMock(UserRepository.class);
    Payment payment = createNiceMock(Payment.class);
    User sender = createNiceMock(User.class);
    User recipient = createNiceMock(User.class);

    expect(paymentRepository.findOne("id")).andReturn(payment);
    expect(payment.getCollectionLocation()).andReturn(null);
    expect(payment.getInternalSenderId()).andReturn("123");
    expect(payment.getTransactionId()).andReturn("id");
    expect(payment.getInternalRecipientId()).andReturn("456");

    expect(userRepository.findByInternalUserIdAndUserIdType("123", UserIdType.EMAIL))
        .andReturn(sender);
    expect(userRepository.findByInternalUserIdAndUserIdType("456", UserIdType.EMAIL))
        .andReturn(recipient);

    replay(paymentRepository, userRepository, notificationRepository, payment, sender, recipient);

    MoneyCollectService service = new MoneyCollectService();
    service.paymentRepository = paymentRepository;
    service.notificationRepository = notificationRepository;
    service.userRepository = userRepository;

    MoneyCollect request = new MoneyCollect();
    request.setTransactionId("id");
    request.setCollectionCurrency("GBP");
    String result = service.collect(request);
    assertEquals(MoneyCollectService.COLLECTED, result);

    verify(paymentRepository, userRepository, notificationRepository, payment, sender, recipient);
  }
Ejemplo n.º 2
0
  @Test
  public void testLocationsDontMatch() {
    PaymentRepository paymentRepository = createNiceMock(PaymentRepository.class);
    NotificationRepository notificationRepository = createNiceMock(NotificationRepository.class);
    UserRepository userRepository = createNiceMock(UserRepository.class);
    Payment payment = createNiceMock(Payment.class);

    expect(paymentRepository.findOne("id")).andReturn(payment);
    expect(payment.getCollectionLocation()).andReturn("Paris").atLeastOnce();

    replay(paymentRepository, userRepository, notificationRepository, payment);

    MoneyCollectService service = new MoneyCollectService();
    service.paymentRepository = paymentRepository;
    service.notificationRepository = notificationRepository;
    service.userRepository = userRepository;

    MoneyCollect request = new MoneyCollect();
    request.setTransactionId("id");
    request.setCollectionLocation("london");
    String result = service.collect(request);
    assertEquals(MoneyCollectService.COLLECTION_LOCATION_INCORRECT, result);

    verify(paymentRepository, userRepository, notificationRepository, payment);
  }