LgoStreamingAccountService implements StreamingAccountService { public Observable<Wallet> getWallet() { ensureSubscription(); return subscription.map(u -> Wallet.Builder.from(u.getWallet().values()).build()); } LgoStreamingAccountService(LgoStreamingService lgoStreamingService); @Override Observable<Balance> getBalanceChanges(Currency currency, Object... args); Observable<Wallet> getWallet();  }
@Test public void it_gives_initial_wallet_snapshot() throws IOException { JsonNode snapshot = TestUtils.getJsonContent("/account/balance-snapshot.json"); LgoStreamingService streamingService = mock(LgoStreamingService.class); LgoStreamingAccountService service = new LgoStreamingAccountService(streamingService); Observable<JsonNode> source = Observable.just(snapshot); when(streamingService.subscribeChannel(anyString())).thenReturn(source); TestObserver<Wallet> wallet = service.getWallet().test(); verify(streamingService).subscribeChannel("balance"); wallet.assertSubscribed(); wallet.assertValueCount(1); wallet .values() .contains( buildWallet( new Balance( Currency.BTC, new BigDecimal("2301.01329566"), new BigDecimal("2297.01329566"), new BigDecimal("4.00000000")), new Balance( Currency.USD, new BigDecimal("453616.3125"), new BigDecimal("453616.3125"), new BigDecimal("0.0000")))); }
@Test public void it_handles_update() throws IOException { JsonNode snapshot = TestUtils.getJsonContent("/account/balance-snapshot.json"); JsonNode update = TestUtils.getJsonContent("/account/balance-update.json"); LgoStreamingService streamingService = mock(LgoStreamingService.class); LgoStreamingAccountService service = new LgoStreamingAccountService(streamingService); Observable<JsonNode> source = Observable.just(snapshot, update); when(streamingService.subscribeChannel(anyString())).thenReturn(source); service.getWallet().subscribe(); TestObserver<Wallet> wallet = service.getWallet().test(); wallet.assertValueAt( 1, buildWallet( new Balance( Currency.BTC, new BigDecimal("2299.01329566"), new BigDecimal("2295.01329566"), new BigDecimal("4.00000000")), new Balance( Currency.USD, new BigDecimal("453616.3125"), new BigDecimal("453616.3125"), new BigDecimal("0.0000")))); verify(streamingService).subscribeChannel("balance"); }