コード例 #1
0
  @Test
  public void testDisallowed() throws Exception {
    final InvocationContext context = mock(InvocationContext.class);

    final Invocation invocation = mock(Invocation.class);
    when(invocation.getInvocationContext()).thenReturn(context);

    CashRepository cashRepository = mock(CashRepository.class);
    final CoinReceiveCash cash1 = new CoinReceiveCash();
    cash1.confirm(BigMoney.of(CurrencyUnit.of("BTC"), BigDecimal.TEN), new Date());
    final CoinReceiveCash cash2 = new CoinReceiveCash();
    cash2.confirm(BigMoney.of(CurrencyUnit.of("BTC"), BigDecimal.ONE), new Date());
    when(cashRepository.findByDueDate(any(Date.class))).thenReturn(ImmutableList.of(cash1, cash2));

    DueDateService dateService = mock(DueDateService.class);

    final GlobalMaxAmountPerDayExecutingInterceptor interceptor =
        new GlobalMaxAmountPerDayExecutingInterceptor("BTC 10");
    interceptor.setCashRepository(cashRepository);
    interceptor.setService(dateService);

    final ValidationCode validationCode = interceptor.intercept(invocation);

    assertThat(validationCode, is(ValidationCode.EXCEEDED_GLOBAL_MAX_AMOUNT_PER_DAY));

    verify(dateService).computeDueDate(any(Date.class));
    verify(invocation, never()).invoke();
  }
コード例 #2
0
  @Test
  public void testAllowed() throws Exception {
    final InvocationContext context = mock(InvocationContext.class);

    final Invocation invocation = mock(Invocation.class);
    when(invocation.getInvocationContext()).thenReturn(context);

    CashRepository cashRepository = mock(CashRepository.class);
    final CoinReceiveCash cash1 = new CoinReceiveCash();
    cash1.confirm(BigMoney.of(CurrencyUnit.of("BTC"), BigDecimal.TEN), new Date());
    final CoinReceiveCash cash2 = new CoinReceiveCash();
    cash2.confirm(BigMoney.of(CurrencyUnit.of("BTC"), BigDecimal.ONE), new Date());
    when(cashRepository.findByDueDate(any(Date.class)))
        .thenReturn(ImmutableList.of(cash1), ImmutableList.of(cash2));

    DueDateService dateService = mock(DueDateService.class);

    final GlobalMaxAmountPerDayExecutingInterceptor interceptor =
        new GlobalMaxAmountPerDayExecutingInterceptor("BTC 10");
    interceptor.setCashRepository(cashRepository);
    interceptor.setService(dateService);

    final ValidationCode validationCode1 = interceptor.intercept(invocation);
    final ValidationCode validationCode2 = interceptor.intercept(invocation);

    assertThat(validationCode1, anyOf(nullValue(), is(ValidationCode.SUCCESSFUL)));
    assertThat(validationCode2, anyOf(nullValue(), is(ValidationCode.SUCCESSFUL)));

    verify(invocation, times(2)).invoke();
    verify(dateService, times(2)).computeDueDate(any(Date.class));
    verify(invocation, times(2)).invoke();
  }