Skip to content

Commit

Permalink
Made changes
Browse files Browse the repository at this point in the history
Signed-off-by: Lemeri123 <[email protected]>
  • Loading branch information
Lemeri123 committed Dec 12, 2024
1 parent df81ee5 commit c7c2fd1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
1 change: 0 additions & 1 deletion hiero-enterprise-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version> 5.11.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package com.openelements.hiero.base.implementation;
import com.hedera.hashgraph.sdk.AccountId;
import com.hedera.hashgraph.sdk.Hbar;
import com.openelements.hiero.base.data.Account;
import com.openelements.hiero.base.AccountClient;
Expand Down Expand Up @@ -42,7 +43,7 @@ public void deleteAccount(@NonNull Account account, @NonNull Account toAccount)

@NonNull
@Override
public Hbar getAccountBalance(com.hedera.hashgraph.sdk.AccountId account) throws HieroException {
public Hbar getAccountBalance(@NonNull AccountId account) throws HieroException {
final AccountBalanceRequest request = AccountBalanceRequest.of(account);
final AccountBalanceResponse response = client.executeAccountBalanceQuery(request);
return response.hbars();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.openelements.hiero.base.test;

import com.openelements.hiero.base.implementation.AccountClientImpl;
import com.hedera.hashgraph.sdk.AccountId;
import com.hedera.hashgraph.sdk.Hbar;
import com.openelements.hiero.base.HieroException;
import com.openelements.hiero.base.protocol.AccountBalanceRequest;
Expand All @@ -25,8 +27,7 @@ public void setUp() {

@Test
public void testGetAccountBalance_ValidPositiveBalance() throws HieroException {
// Fully qualify AccountId to ensure no ambiguity
com.hedera.hashgraph.sdk.AccountId accountId = com.hedera.hashgraph.sdk.AccountId.fromString("0.0.12345");
AccountId accountId = AccountId.fromString("0.0.12345");
Hbar expectedBalance = new Hbar(10);

// Mock the response
Expand All @@ -37,15 +38,14 @@ public void testGetAccountBalance_ValidPositiveBalance() throws HieroException {
ArgumentMatchers.any(AccountBalanceRequest.class)
)).thenReturn(mockResponse);

// Explicit cast ensures we're calling the correct method
Hbar balance = accountClientImpl.getAccountBalance(accountId);

assertEquals(expectedBalance, balance);
}

@Test
public void testGetAccountBalance_ZeroBalance() throws HieroException {
com.hedera.hashgraph.sdk.AccountId accountId = com.hedera.hashgraph.sdk.AccountId.fromString("0.0.67890");
AccountId accountId = AccountId.fromString("0.0.67890");
Hbar expectedBalance = new Hbar(0);

AccountBalanceResponse mockResponse = mock(AccountBalanceResponse.class);
Expand All @@ -62,30 +62,27 @@ public void testGetAccountBalance_ZeroBalance() throws HieroException {

@Test
public void testGetAccountBalance_InvalidAccount_ThrowsException() throws HieroException {
// Use a valid but non-existing account ID to simulate invalid behavior
com.hedera.hashgraph.sdk.AccountId invalidAccountId = com.hedera.hashgraph.sdk.AccountId.fromString("0.0.9999999"); // Simulate invalid or non-existing account

AccountId invalidAccountId = AccountId.fromString("0.0.9999999");

when(mockProtocolLayerClient.executeAccountBalanceQuery(
ArgumentMatchers.any(AccountBalanceRequest.class)
)).thenThrow(new HieroException("Invalid account"));

assertThrows(HieroException.class, () -> {
accountClientImpl.getAccountBalance(invalidAccountId);
});
}


@Test
public void testGetAccountBalance_NullThrowsException() {
assertThrows(NullPointerException.class, () -> {
accountClientImpl.getAccountBalance((com.hedera.hashgraph.sdk.AccountId) null);
accountClientImpl.getAccountBalance((AccountId) null);
});
}


@Test
public void testGetAccountBalance_ProtocolLayerClientFails() throws HieroException {
com.hedera.hashgraph.sdk.AccountId accountId = com.hedera.hashgraph.sdk.AccountId.fromString("0.0.12345");
AccountId accountId = AccountId.fromString("0.0.12345");

when(mockProtocolLayerClient.executeAccountBalanceQuery(
ArgumentMatchers.any(AccountBalanceRequest.class)
Expand Down
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,10 @@
<artifactId>junit-jupiter</artifactId>
<version>${junit.version}</version>
</dependency>
<dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version> 5.11.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down

0 comments on commit c7c2fd1

Please sign in to comment.