@Test public void testSimpleBalance() { TransferrableTokensParticle minted = mock(TransferrableTokensParticle.class); Hash hash = mock(Hash.class); when(minted.getAmount()).thenReturn(UInt256.TEN); when(minted.getGranularity()).thenReturn(UInt256.ONE); when(minted.getHash()).thenReturn(hash); RRI token = mock(RRI.class); when(minted.getTokenDefinitionReference()).thenReturn(token); TokenBalanceReducer reducer = new TokenBalanceReducer(); TokenBalanceState tokenBalance = reducer.reduce(new TokenBalanceState(), minted); BigDecimal tenSubunits = TokenUnitConversions.subunitsToUnits(UInt256.TEN); assertThat(tokenBalance.getBalance().get(token).compareTo(tenSubunits)).isEqualTo(0); }
@Override public TokenBalanceState reduce(TokenBalanceState state, Particle p) { if (p instanceof TransferrableTokensParticle) { return TokenBalanceState.merge(state, (TransferrableTokensParticle) p); } return state; }
TokenBalanceReducer implements ParticleReducer<TokenBalanceState> { @Override public TokenBalanceState reduce(TokenBalanceState state, Particle p) { if (p instanceof TransferrableTokensParticle) { return TokenBalanceState.merge(state, (TransferrableTokensParticle) p); } return state; } }
TokenBalanceReducer implements ParticleReducer<TokenBalanceState> { @Override public TokenBalanceState reduce(TokenBalanceState state, Particle p) { if (p instanceof TransferrableTokensParticle) { return TokenBalanceState.merge(state, (TransferrableTokensParticle) p); } return state; }  }
TokenBalanceReducer implements ParticleReducer<TokenBalanceState> { @Override public TokenBalanceState reduce(TokenBalanceState state, Particle p) { if (p instanceof TransferrableTokensParticle) { return TokenBalanceState.merge(state, (TransferrableTokensParticle) p); } return state; }  @Override Class<TokenBalanceState> stateClass(); @Override TokenBalanceState initialState(); @Override TokenBalanceState reduce(TokenBalanceState state, Particle p); @Override TokenBalanceState combine(TokenBalanceState state0, TokenBalanceState state1); }
TokenBalanceReducer implements ParticleReducer<TokenBalanceState> { @Override public TokenBalanceState reduce(TokenBalanceState state, Particle p) { if (p instanceof TransferrableTokensParticle) { return TokenBalanceState.merge(state, (TransferrableTokensParticle) p); } return state; }  @Override Class<TokenBalanceState> stateClass(); @Override TokenBalanceState initialState(); @Override TokenBalanceState reduce(TokenBalanceState state, Particle p); @Override TokenBalanceState combine(TokenBalanceState state0, TokenBalanceState state1);  }