1
1
package com .openelements .hiero .base .test ;
2
2
3
+ import com .hedera .hashgraph .sdk .*;
3
4
import com .openelements .hiero .base .implementation .AccountClientImpl ;
4
- import com .hedera .hashgraph .sdk .AccountId ;
5
5
import com .openelements .hiero .base .data .Account ;
6
- import com .hedera .hashgraph .sdk .Hbar ;
7
6
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 .*;
13
8
import com .openelements .hiero .base .protocol .ProtocolLayerClient ;
14
9
import org .junit .jupiter .api .BeforeEach ;
10
+ import org .junit .jupiter .api .DisplayName ;
15
11
import org .junit .jupiter .api .Test ;
12
+ import org .mockito .ArgumentCaptor ;
16
13
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 .*;
21
16
import static org .mockito .ArgumentMatchers .any ;
17
+ import static org .mockito .ArgumentMatchers .argThat ;
22
18
import static org .mockito .Mockito .mock ;
23
19
import static org .mockito .Mockito .when ;
24
20
import static org .mockito .Mockito .doThrow ;
@@ -153,42 +149,64 @@ void testCreateAccount_hieroExceptionThrown() throws HieroException {
153
149
154
150
155
151
@ 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 ));
165
154
}
166
155
156
+
167
157
@ Test
168
- void DeleteAccount_withSameFromAndToAccount_throwsIllegalArgumentException () {
169
- Account account = mock (Account .class );
158
+ void DeleteAccount_successful () throws HieroException {
159
+ Account mockAccount = mock (Account .class );
170
160
171
- IllegalArgumentException exception = assertThrows (IllegalArgumentException .class , () ->
172
- accountClientImpl .deleteAccount (account , account )
173
- );
161
+ accountClientImpl .deleteAccount (mockAccount );
174
162
175
- assertEquals ("transferFoundsToAccount must be different from toDelete" , exception .getMessage ());
163
+ verify (mockProtocolLayerClient , times (1 ))
164
+ .executeAccountDeleteTransaction (any ());
176
165
}
177
166
167
+
178
168
@ 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
+ });
181
175
}
182
176
183
177
@ 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)" );
187
185
}
188
186
189
187
@ 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 ());
193
211
}
194
212
}
0 commit comments