diff --git a/src/main/java/io/proximax/sdk/helpers/BaseHelper.java b/src/main/java/io/proximax/sdk/helpers/BaseHelper.java index da115ff0..80566799 100644 --- a/src/main/java/io/proximax/sdk/helpers/BaseHelper.java +++ b/src/main/java/io/proximax/sdk/helpers/BaseHelper.java @@ -54,6 +54,15 @@ public BaseHelper(BlockchainApi api) { this.transact.setFeeCalculationStrategy(FeeCalculationStrategy.MEDIUM); } + /** + * get the blockchain API used by this helper instance + * + * @return the API instance + */ + public BlockchainApi getBlockchainApi() { + return api; + } + /** * BLOCKING! announce transaction and wait for it to be added to confirmed transactions * diff --git a/src/main/java/io/proximax/sdk/helpers/HelperFactory.java b/src/main/java/io/proximax/sdk/helpers/HelperFactory.java new file mode 100644 index 00000000..0332b4fc --- /dev/null +++ b/src/main/java/io/proximax/sdk/helpers/HelperFactory.java @@ -0,0 +1,51 @@ +/* + * Copyright 2019 ProximaX Limited. All rights reserved. + * Use of this source code is governed by the Apache 2.0 + * license that can be found in the LICENSE file. + */ +package io.proximax.sdk.helpers; + +import io.proximax.sdk.BlockchainApi; + +/** + * Factory class to simplify access to the helpers + */ +public class HelperFactory { + + private final BlockchainApi api; + + /** + * @param api blockchain API instance used by helpers + */ + public HelperFactory(BlockchainApi api) { + this.api = api; + } + + /** + * @return the API used by helpers + */ + public BlockchainApi getBlockchainApi() { + return api; + } + + /** + * @return helper for account related operations + */ + public AccountHelper account() { + return new AccountHelper(api); + } + + /** + * @return helper for blockchain related operations + */ + public BlockchainHelper blockchain() { + return new BlockchainHelper(api); + } + + /** + * @return helper for transfers + */ + public TransferHelper transfer() { + return new TransferHelper(api); + } +} diff --git a/src/test/java/io/proximax/sdk/helpers/AccountHelperTest.java b/src/test/java/io/proximax/sdk/helpers/AccountHelperTest.java index b90d5228..5ccaede5 100644 --- a/src/test/java/io/proximax/sdk/helpers/AccountHelperTest.java +++ b/src/test/java/io/proximax/sdk/helpers/AccountHelperTest.java @@ -18,12 +18,11 @@ import org.junit.jupiter.api.Test; import io.proximax.sdk.BlockchainApi; -import io.proximax.sdk.helpers.AccountHelper; import io.proximax.sdk.model.account.Account; import io.proximax.sdk.model.blockchain.NetworkType; /** - * TODO add proper description + * {@link AccountHelper} tests */ class AccountHelperTest { private BlockchainApi api; diff --git a/src/test/java/io/proximax/sdk/helpers/BlockchainHelperTest.java b/src/test/java/io/proximax/sdk/helpers/BlockchainHelperTest.java deleted file mode 100644 index 89e87fdb..00000000 --- a/src/test/java/io/proximax/sdk/helpers/BlockchainHelperTest.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2019 ProximaX Limited. All rights reserved. - * Use of this source code is governed by the Apache 2.0 - * license that can be found in the LICENSE file. - */ -package io.proximax.sdk.helpers; - -import java.net.MalformedURLException; -import java.net.URL; - -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; - -import io.proximax.sdk.BlockchainApi; -import io.proximax.sdk.helpers.BlockchainHelper; -import io.proximax.sdk.model.blockchain.NetworkType; - -/** - * TODO add proper description - */ -class BlockchainHelperTest { - private BlockchainApi api; - private BlockchainHelper helper; - - @BeforeEach - void init() throws MalformedURLException { - // specify both URL and network type so the network does not need to be accessed unless really needed - api = new BlockchainApi(new URL("http://localhost:3000"), NetworkType.MAIN_NET); - helper = new BlockchainHelper(api); - } - - @AfterEach - void cleanup() { - this.api = null; - this.helper = null; - } - -} diff --git a/src/test/java/io/proximax/sdk/helpers/HelperFactoryTest.java b/src/test/java/io/proximax/sdk/helpers/HelperFactoryTest.java new file mode 100644 index 00000000..56c7b7cd --- /dev/null +++ b/src/test/java/io/proximax/sdk/helpers/HelperFactoryTest.java @@ -0,0 +1,40 @@ +/* + * Copyright 2019 ProximaX Limited. All rights reserved. + * Use of this source code is governed by the Apache 2.0 + * license that can be found in the LICENSE file. + */ +package io.proximax.sdk.helpers; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +import io.proximax.sdk.BlockchainApi; +import io.proximax.sdk.model.transaction.builder.TransactionBuilderFactory; + +/** + * {@link HelperFactory} tests + */ +class HelperFactoryTest { + + @Test + void testConstructor() { + BlockchainApi api = Mockito.mock(BlockchainApi.class); + assertEquals(api, new HelperFactory(api).getBlockchainApi()); + } + + @Test + void testFacMethods() { + BlockchainApi api = Mockito.mock(BlockchainApi.class); + TransactionBuilderFactory transact = Mockito.mock(TransactionBuilderFactory.class); + + Mockito.when(api.transact()).thenReturn(transact); + + HelperFactory fac = new HelperFactory(api); + // make sure that API is passed to the helpers + assertEquals(api, fac.account().getBlockchainApi()); + assertEquals(api, fac.blockchain().getBlockchainApi()); + assertEquals(api, fac.transfer().getBlockchainApi()); + } +}