-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issue #133 - couple finishing touches and factory for helpers
- Loading branch information
Showing
5 changed files
with
101 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 0 additions & 38 deletions
38
src/test/java/io/proximax/sdk/helpers/BlockchainHelperTest.java
This file was deleted.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
src/test/java/io/proximax/sdk/helpers/HelperFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} |