private boolean isGreaterThenZero(Balance value) { return value.getAmount().compareTo(BigDecimal.ZERO) == 1; }
@VisibleForTesting void setBalance(final kin.core.Balance balanceObj) { Balance balanceTemp = balance.getValue(); // if the values are not equals so we need to update, // no need to update for equal values. if (balanceTemp.getAmount().compareTo(balanceObj.value()) != 0) { eventLogger.send(KinBalanceUpdated.create(balanceTemp.getAmount().doubleValue())); Logger.log(new Log().withTag(TAG).text("setBalance: Balance changed, should get update")); balanceTemp.setAmount(balanceObj.value()); balance.postValue(balanceTemp); local.setBalance(balanceObj.value().intValue()); } }
@Test public void purchase_Spend_Failed_Insufficient_Kin() throws Exception { final CountDownLatch countDownLatch = new CountDownLatch(1); when(remote.createExternalOrderSync(anyString())).thenReturn(openOrder); when(openOrder.getOfferType()).thenReturn(OfferType.SPEND); when(blockchainSource.getBalance()).thenReturn(new Balance(new BigDecimal(3))); orderRepository.purchase("generatedOfferJWT", new KinCallback<OrderConfirmation>() { @Override public void onResponse(OrderConfirmation response) { } @Override public void onFailure(KinEcosystemException exception) { countDownLatch.countDown(); assertTrue(exception instanceof BlockchainException); assertEquals(INSUFFICIENT_KIN, exception.getCode()); } }); Thread.sleep(500); ShadowLooper.runUiThreadTasks(); verify(remote).cancelOrderSync(anyString()); countDownLatch.await(500, TimeUnit.MICROSECONDS); }
@Before public void setUp() throws Exception { super.setUp(); MockitoAnnotations.initMocks(this); resetInstance(); when(offer.getId()).thenReturn(offerID); when(openOrder.getId()).thenReturn(orderID); when(openOrder.getOfferId()).thenReturn(offerID); when(openOrder.getAmount()).thenReturn(11); when(openOrder.getBlockchainData()).thenReturn(blockchainData); when(order.getOrderId()).thenReturn(orderID); when(order.getOfferId()).thenReturn(offerID); when(blockchainData.getRecipientAddress()).thenReturn("recipientAddress"); when(blockchainData.getSenderAddress()).thenReturn("senderAddress"); when(blockchainData.getTransactionId()).thenReturn("someTransactionHash"); when(payment.getOrderID()).thenReturn(orderID); when(payment.isSucceed()).thenReturn(true); when(payment.getTransactionID()).thenReturn("transactionID"); when(blockchainSource.getBalance()).thenReturn(new Balance(new BigDecimal(9999))); }
@Test public void test_Update_Balance() throws Exception { Balance balance = new Balance(); balanceObserverCaptor.getValue().onChanged(balance); verify(balanceView).updateBalance(0); balance.setAmount(new BigDecimal(30)); balanceObserverCaptor.getValue().onChanged(balance); verify(balanceView).updateBalance(30); }
private boolean isGreaterThenZero(Balance value) { return value.getAmount().compareTo(BigDecimal.ZERO) == 1; }
private void updateBalance(Balance balance) { int balanceValue = balance.getAmount().intValue(); if (view != null) { view.updateBalance(balanceValue); } }
return; int balance = blockchainSource.getBalance().getAmount().intValue(); final BigDecimal amount = new BigDecimal(offer.getAmount());
if (isSpendOrder(openOrder)) { Balance balance = blockchainSource.getBalance(); if (balance.getAmount().intValue() < openOrder.getAmount()) { orderRepository.cancelOrderSync(openOrder.getId()); runOnMainThread(new Runnable() {