@Test public void testStartWithInvalidAddress() throws Exception { PayCoinScheduler scheduler = new PayCoinScheduler(); final Random random = new Random(); PendingCashRepository cashRepository = mock(PendingCashRepository.class); CoinPayCash cash = mock(CoinPayCash.class); when(cashRepository.findPending(any(Date.class), anyInt(), anyInt())) .thenReturn(ImmutableList.of(cash, cash, cash, cash)); when(cash.isApproved()).thenAnswer(new Answer<Boolean>() { @Override public Boolean answer(InvocationOnMock invocation) throws Throwable { int rand = random.nextInt(2); switch (rand) { case 0: APPROVED_STATUS_COUNT++; return true; default: return false; } } }); when(cash.getStatus()).thenAnswer(new Answer<CashStatus>() { @Override public CashStatus answer(InvocationOnMock invocation) throws Throwable { int rand = random.nextInt(2); switch (rand) { case 0: return CashStatus.CANCELLED; default: CREATED_STATUS_COUNT++; return CashStatus.CREATED; } } }); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { CONFIRMED_COUNT++; return null; } }).when(cash).confirm(eq("paid123"), any(Date.class)); Repository<PaidFee> paidFeeRepository = mock(Repository.class); PaidFee fee = mock(PaidFee.class); when(fee.isOffseted()).thenReturn(true); when(fee.isPending()).thenReturn(true); when(paidFeeRepository.load(anyString())).thenReturn(fee); BitcoinRpcOperations operations = mock(BitcoinRpcOperations.class); final ValidateAddressResponse response = createResponse(false); when(operations.validateAddress(anyString())).thenReturn(response); scheduler.setPendingCashRepository(cashRepository); scheduler.setPaidFeeRepository(paidFeeRepository); scheduler.setOperations(operations); scheduler.start(); TimeUnit.SECONDS.sleep(5); scheduler.stop(); assertThat(CONFIRMED_COUNT, lessThan(APPROVED_STATUS_COUNT)); assertThat(CONFIRMED_COUNT, lessThan(CREATED_STATUS_COUNT)); verify(cashRepository, never()).save(any(Cash.class)); verify(fee, never()).confirm(anyString(), any(Date.class)); verify(fee).cancel(eq(CancelledReason.INVALID_ADDRESS), any(Date.class)); verify(cash, never()).confirm(anyString(), any(Date.class)); }
@SuppressWarnings("SpringJavaAutowiringInspection") @Autowired public void setOperations(BitcoinRpcOperations operations) { this.operations = operations; }
PayCoinScheduler extends PayScheduler<CoinPayCash> { @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired public void setOperations(BitcoinRpcOperations operations) { this.operations = operations; } }
PayCoinScheduler extends PayScheduler<CoinPayCash> { @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired public void setOperations(BitcoinRpcOperations operations) { this.operations = operations; }  }
PayCoinScheduler extends PayScheduler<CoinPayCash> { @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired public void setOperations(BitcoinRpcOperations operations) { this.operations = operations; }  @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setOperations(BitcoinRpcOperations operations); void setMinConfirmations(int minConfirmations); void setUserQueryRepository(UserQueryRepository userQueryRepository); @SuppressWarnings("SpringJavaAutowiringInspection") @Resource(name = "coinTransferringInCashValidator") void setCashValidator(CashValidator cashValidator); }
PayCoinScheduler extends PayScheduler<CoinPayCash> { @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired public void setOperations(BitcoinRpcOperations operations) { this.operations = operations; }  @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setOperations(BitcoinRpcOperations operations); void setMinConfirmations(int minConfirmations); void setUserQueryRepository(UserQueryRepository userQueryRepository); @SuppressWarnings("SpringJavaAutowiringInspection") @Resource(name = "coinTransferringInCashValidator") void setCashValidator(CashValidator cashValidator);  }