CreateTokenToParticleGroupsMapper implements StatelessActionToParticleGroupsMapper<CreateTokenAction> { @Override public List<ParticleGroup> mapToParticleGroups(CreateTokenAction tokenCreation) { if (tokenCreation.getTokenSupplyType().equals(TokenSupplyType.FIXED)) { return createFixedSupplyToken(tokenCreation); } else if (tokenCreation.getTokenSupplyType().equals(TokenSupplyType.MUTABLE)) { return createVariableSupplyToken(tokenCreation); } else { throw new IllegalStateException("Unknown supply type: " + tokenCreation.getTokenSupplyType()); } }  @Override List<ParticleGroup> mapToParticleGroups(CreateTokenAction tokenCreation); List<ParticleGroup> createVariableSupplyToken(CreateTokenAction tokenCreation); List<ParticleGroup> createFixedSupplyToken(CreateTokenAction tokenCreation);  }
@Test public void testNormalMutableSupplyConstruction() { CreateTokenAction tokenCreation = mock(CreateTokenAction.class); RadixAddress address = mock(RadixAddress.class); when(address.euid()).thenReturn(mock(EUID.class)); ECPublicKey key = mock(ECPublicKey.class); when(address.getPublicKey()).thenReturn(key); when(tokenCreation.getRRI()).thenReturn(RRI.of(address, "ISO")); when(tokenCreation.getInitialSupply()).thenReturn(TokenUnitConversions.getMinimumGranularity()); when(tokenCreation.getGranularity()).thenReturn(TokenUnitConversions.getMinimumGranularity()); when(tokenCreation.getTokenSupplyType()).thenReturn(TokenSupplyType.MUTABLE); CreateTokenToParticleGroupsMapper createTokenToParticlesMapper = new CreateTokenToParticleGroupsMapper(); List<ParticleGroup> particleGroups = createTokenToParticlesMapper.mapToParticleGroups(tokenCreation); assertThat(particleGroups).anyMatch(hasInstanceOf(MutableSupplyTokenDefinitionParticle.class)); assertThat(particleGroups).anyMatch(hasInstanceOf(TransferrableTokensParticle.class)); assertThat(particleGroups).anyMatch(hasInstanceOf(UnallocatedTokensParticle.class)); assertThat(particleGroups).anyMatch(hasInstanceOf(RRIParticle.class)); assertThat(particleGroups.stream().flatMap(ParticleGroup::spunParticles).count()).isEqualTo(6); }
@Test public void testNormalFixedSupplyConstruction() { CreateTokenAction tokenCreation = mock(CreateTokenAction.class); RadixAddress address = mock(RadixAddress.class); when(address.euid()).thenReturn(mock(EUID.class)); ECPublicKey key = mock(ECPublicKey.class); when(address.getPublicKey()).thenReturn(key); when(tokenCreation.getRRI()).thenReturn(RRI.of(address, "ISO")); when(tokenCreation.getInitialSupply()).thenReturn(TokenUnitConversions.getMinimumGranularity()); when(tokenCreation.getGranularity()).thenReturn(TokenUnitConversions.getMinimumGranularity()); when(tokenCreation.getTokenSupplyType()).thenReturn(TokenSupplyType.FIXED); CreateTokenToParticleGroupsMapper createTokenToParticlesMapper = new CreateTokenToParticleGroupsMapper(); List<ParticleGroup> particleGroups = createTokenToParticlesMapper.mapToParticleGroups(tokenCreation); assertThat(particleGroups).anyMatch(hasInstanceOf(FixedSupplyTokenDefinitionParticle.class)); assertThat(particleGroups).anyMatch(hasInstanceOf(TransferrableTokensParticle.class)); assertThat(particleGroups).anyMatch(hasInstanceOf(RRIParticle.class)); assertThat(particleGroups.stream().flatMap(ParticleGroup::spunParticles).count()).isEqualTo(3); }