Skip to content

Commit abc64f0

Browse files
committed
remove unwanted test commits
Signed-off-by: Agaba Derrick <agabaderrick18@gmail.com>
1 parent a4e308c commit abc64f0

File tree

1 file changed

+52
-34
lines changed

1 file changed

+52
-34
lines changed

hiero-enterprise-base/src/test/java/com/openelements/hiero/base/test/AccountClientImplTest.java

Lines changed: 52 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
package com.openelements.hiero.base.test;
22

3+
import com.hedera.hashgraph.sdk.*;
34
import com.openelements.hiero.base.implementation.AccountClientImpl;
4-
import com.hedera.hashgraph.sdk.AccountId;
55
import com.openelements.hiero.base.data.Account;
6-
import com.hedera.hashgraph.sdk.Hbar;
76
import com.openelements.hiero.base.HieroException;
8-
import com.openelements.hiero.base.protocol.data.AccountCreateResult;
9-
import com.openelements.hiero.base.protocol.data.AccountCreateRequest;
10-
import com.openelements.hiero.base.protocol.data.AccountBalanceResponse;
11-
import com.openelements.hiero.base.protocol.data.AccountBalanceRequest;
12-
import com.openelements.hiero.base.protocol.data.AccountDeleteRequest;
7+
import com.openelements.hiero.base.protocol.data.*;
138
import com.openelements.hiero.base.protocol.ProtocolLayerClient;
149
import org.junit.jupiter.api.BeforeEach;
10+
import org.junit.jupiter.api.DisplayName;
1511
import org.junit.jupiter.api.Test;
12+
import org.mockito.ArgumentCaptor;
1613
import org.mockito.ArgumentMatchers;
17-
import static org.junit.jupiter.api.Assertions.assertEquals;
18-
import static org.junit.jupiter.api.Assertions.assertNotNull;
19-
import static org.junit.jupiter.api.Assertions.assertThrows;
20-
import static org.junit.jupiter.api.Assertions.assertTrue;
14+
15+
import static org.junit.jupiter.api.Assertions.*;
2116
import static org.mockito.ArgumentMatchers.any;
17+
import static org.mockito.ArgumentMatchers.argThat;
2218
import static org.mockito.Mockito.mock;
2319
import static org.mockito.Mockito.when;
2420
import static org.mockito.Mockito.doThrow;
@@ -153,42 +149,64 @@ void testCreateAccount_hieroExceptionThrown() throws HieroException {
153149

154150

155151
@Test
156-
void DeleteAccount_throwsHieroException() throws HieroException {
157-
Account mockAccount = mock(Account.class);
158-
159-
doThrow(new HieroException("Deletion failed")).when(mockProtocolLayerClient)
160-
.executeAccountDeleteTransaction(any(AccountDeleteRequest.class));
161-
162-
HieroException exception = assertThrows(HieroException.class,
163-
() -> accountClientImpl.deleteAccount(mockAccount));
164-
assertEquals("Deletion failed", exception.getMessage());
152+
void DeleteAccount_nullAccount_throwsNullPointerException() {
153+
assertThrows(NullPointerException.class, () -> accountClientImpl.deleteAccount(null));
165154
}
166155

156+
167157
@Test
168-
void DeleteAccount_withSameFromAndToAccount_throwsIllegalArgumentException() {
169-
Account account = mock(Account.class);
158+
void DeleteAccount_successful() throws HieroException {
159+
Account mockAccount = mock(Account.class);
170160

171-
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () ->
172-
accountClientImpl.deleteAccount(account, account)
173-
);
161+
accountClientImpl.deleteAccount(mockAccount);
174162

175-
assertEquals("transferFoundsToAccount must be different from toDelete", exception.getMessage());
163+
verify(mockProtocolLayerClient, times(1))
164+
.executeAccountDeleteTransaction(any());
176165
}
177166

167+
178168
@Test
179-
void DeleteAccount_nullAccount_throwsNullPointerException() {
180-
assertThrows(NullPointerException.class, () -> accountClientImpl.deleteAccount(null));
169+
void DeleteAccount_withTransfer_nullFromAccount_throwsException() {
170+
Account toAccount = mock(Account.class);
171+
172+
assertThrows(NullPointerException.class, () -> {
173+
accountClientImpl.deleteAccount(null, toAccount);
174+
});
181175
}
182176

183177
@Test
184-
void DeleteAccount_withTransfer_nullAccount_throwsNullPointerException() {
185-
Account toAccount = mock(Account.class);
186-
assertThrows(NullPointerException.class, () -> accountClientImpl.deleteAccount(null, toAccount));
178+
void deleteAccount_withNullToAccount_shouldNotThrow() {
179+
AccountId accountId = AccountId.fromString("0.0.123");
180+
PrivateKey privateKey = PrivateKey.generate();
181+
Account fromAccount = new Account(accountId, privateKey.getPublicKey(), privateKey);
182+
183+
assertDoesNotThrow(() -> accountClientImpl.deleteAccount(fromAccount, null),
184+
"deleteAccount should not throw when toAccount is null (should fallback to operator)");
187185
}
188186

189187
@Test
190-
void DeleteAccount_withSameAccount_throwsIllegalArgumentException() {
191-
Account account = mock(Account.class);
192-
assertThrows(IllegalArgumentException.class, () -> accountClientImpl.deleteAccount(account, account));
188+
void deleteAccount_withTransfer_throwsHieroException() throws HieroException {
189+
PrivateKey fromPrivateKey = PrivateKey.generate();
190+
PublicKey fromPublicKey = fromPrivateKey.getPublicKey();
191+
AccountId fromAccountId = AccountId.fromString("0.0.1234");
192+
193+
PrivateKey toPrivateKey = PrivateKey.generate();
194+
PublicKey toPublicKey = toPrivateKey.getPublicKey();
195+
AccountId toAccountId = AccountId.fromString("0.0.5678");
196+
197+
Account fromAccount = new Account(fromAccountId, fromPublicKey, fromPrivateKey);
198+
Account toAccount = new Account(toAccountId, toPublicKey, toPrivateKey);
199+
200+
doThrow(new HieroException("Transfer deletion failed"))
201+
.when(mockProtocolLayerClient)
202+
.executeAccountDeleteTransaction(any());
203+
204+
HieroException exception = assertThrows(HieroException.class, () ->
205+
accountClientImpl.deleteAccount(fromAccount, toAccount)
206+
);
207+
208+
assertEquals("Transfer deletion failed", exception.getMessage());
209+
210+
verify(mockProtocolLayerClient, times(1)).executeAccountDeleteTransaction(any());
193211
}
194212
}

0 commit comments

Comments
 (0)