-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added tests for AccountClientImpl.getAccountBalance functionality #123
Conversation
@Lemeri123 you didn't sign off your commit. That you now pushed a commit already, you can run these commands to get them signed off
|
Signed-off-by: Lemeri123 <[email protected]>
Okay thank you @Ndacyayisenga-droid |
Thanks for your contribution @Lemeri123 . I added a few comments |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some changes are needed
@@ -44,7 +42,7 @@ public void deleteAccount(@NonNull Account account, @NonNull Account toAccount) | |||
|
|||
@NonNull | |||
@Override | |||
public Hbar getAccountBalance(@NonNull AccountId account) throws HieroException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change do not make sense to me. Can you please revert it.
hiero-enterprise-base/pom.xml
Outdated
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-core</artifactId> | ||
<version> 5.11.0</version> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We define the versions for all dependencies in the root pom. Please remove the version at this place and add it to the root pom.xml
@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"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is only one AccountId
on the classpath. Based on that I would favor to do a regular import instead of a full qualified class in code.
@Lemeri123 please have a look at my review |
Signed-off-by: Lemeri123 <[email protected]>
@Lemeri123 thank you for your contribution! |
import org.junit.jupiter.api.Test; | ||
import org.mockito.ArgumentMatchers; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the asterisk wildcard
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But if I remove it then I get errors since they set up the testing framework and mocking utilities for the test method
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.Mockito.*; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the asterisk wildcard
@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"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Lemeri123 I recommend importing AccountId
directly to simplify the code and enhance readability by eliminating the need for full qualifications. You can change the above line to something like
AccountId accountId = AccountId.fromString("0.0.12345");
|
||
@Test | ||
public void testGetAccountBalance_ZeroBalance() throws HieroException { | ||
com.hedera.hashgraph.sdk.AccountId accountId = com.hedera.hashgraph.sdk.AccountId.fromString("0.0.67890"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend importing AccountId directly to simplify the code and enhance readability by eliminating the need for full qualifications. You can change the above line to something like
AccountId accountId = AccountId.fromString("0.0.67890");
@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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same review as the above
@Test | ||
public void testGetAccountBalance_NullThrowsException() { | ||
assertThrows(NullPointerException.class, () -> { | ||
accountClientImpl.getAccountBalance((com.hedera.hashgraph.sdk.AccountId) null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just pass in the AccountId
not com.hedera.hashgraph.sdk.AccountId
|
||
@Test | ||
public void testGetAccountBalance_ProtocolLayerClientFails() throws HieroException { | ||
com.hedera.hashgraph.sdk.AccountId accountId = com.hedera.hashgraph.sdk.AccountId.fromString("0.0.12345"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use AccountId accountId = AccountId.fromString("0.0.12345");
not com.hedera.hashgraph.sdk.AccountId accountId = com.hedera.hashgraph.sdk.AccountId.fromString("0.0.12345");
@@ -1,6 +1,4 @@ | |||
package com.openelements.hiero.base.implementation; | |||
|
|||
import com.hedera.hashgraph.sdk.AccountId; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need this change
@@ -44,7 +42,7 @@ public void deleteAccount(@NonNull Account account, @NonNull Account toAccount) | |||
|
|||
@NonNull | |||
@Override | |||
public Hbar getAccountBalance(@NonNull AccountId account) throws HieroException { | |||
public Hbar getAccountBalance(com.hedera.hashgraph.sdk.AccountId account) throws HieroException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need this change as well
I created a new test file and added the necessary tests needed. #109