Skip to content

Commit

Permalink
issue #133 - couple finishing touches and factory for helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
tonowie committed Nov 29, 2019
1 parent fdb4fff commit 9c417dc
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 40 deletions.
9 changes: 9 additions & 0 deletions src/main/java/io/proximax/sdk/helpers/BaseHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
* <b>BLOCKING!</b> announce transaction and wait for it to be added to confirmed transactions
*
Expand Down
51 changes: 51 additions & 0 deletions src/main/java/io/proximax/sdk/helpers/HelperFactory.java
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);
}
}
3 changes: 1 addition & 2 deletions src/test/java/io/proximax/sdk/helpers/AccountHelperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
38 changes: 0 additions & 38 deletions src/test/java/io/proximax/sdk/helpers/BlockchainHelperTest.java

This file was deleted.

40 changes: 40 additions & 0 deletions src/test/java/io/proximax/sdk/helpers/HelperFactoryTest.java
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());
}
}

0 comments on commit 9c417dc

Please sign in to comment.