22
33import com .openelements .hiero .base .implementation .AccountClientImpl ;
44import com .hedera .hashgraph .sdk .AccountId ;
5+ import com .openelements .hiero .base .data .Account ;
56import com .hedera .hashgraph .sdk .Hbar ;
67import com .openelements .hiero .base .HieroException ;
78import com .openelements .hiero .base .protocol .AccountBalanceRequest ;
89import com .openelements .hiero .base .protocol .AccountBalanceResponse ;
10+ import com .openelements .hiero .base .protocol .AccountCreateRequest ;
11+ import com .openelements .hiero .base .protocol .AccountCreateResult ;
912import com .openelements .hiero .base .protocol .ProtocolLayerClient ;
1013import org .junit .jupiter .api .BeforeEach ;
1114import org .junit .jupiter .api .Test ;
1215import org .mockito .ArgumentMatchers ;
1316
1417import static org .junit .jupiter .api .Assertions .*;
18+ import static org .mockito .ArgumentMatchers .any ;
1519import static org .mockito .Mockito .*;
1620
1721public class AccountClientImplTest {
@@ -92,4 +96,53 @@ public void testGetAccountBalance_ProtocolLayerClientFails() throws HieroExcepti
9296 accountClientImpl .getAccountBalance (accountId );
9397 });
9498 }
95- }
99+
100+ //tests for createAccount method
101+ @ Test
102+ void testCreateAccount_successful () throws HieroException {
103+ Hbar initialBalance = Hbar .from (100 );
104+
105+ AccountCreateResult mockResult = mock (AccountCreateResult .class );
106+ Account mockAccount = mock (Account .class );
107+
108+ when (mockAccount .accountId ()).thenReturn (AccountId .fromString ("0.0.12345" ));
109+ when (mockResult .newAccount ()).thenReturn (mockAccount );
110+ when (mockProtocolLayerClient .executeAccountCreateTransaction (any (AccountCreateRequest .class )))
111+ .thenReturn (mockResult );
112+
113+ Account result = accountClientImpl .createAccount (initialBalance );
114+
115+ assertNotNull (result );
116+ assertEquals (AccountId .fromString ("0.0.12345" ), result .accountId ());
117+ verify (mockProtocolLayerClient , times (1 ))
118+ .executeAccountCreateTransaction (any (AccountCreateRequest .class ));
119+ }
120+
121+ @ Test
122+ void testCreateAccount_invalidInitialBalance_null () {
123+ Hbar initialBalance = null ;
124+
125+ assertThrows (NullPointerException .class , () -> accountClientImpl .createAccount (initialBalance ));
126+ }
127+
128+ @ Test
129+ void testCreateAccount_invalidInitialBalance_negative () {
130+ Hbar initialBalance = Hbar .from (-100 );
131+ HieroException exception = assertThrows (HieroException .class ,
132+ () -> accountClientImpl .createAccount (initialBalance ));
133+
134+ assertTrue (exception .getMessage ().contains ("Invalid initial balance" ));
135+ }
136+
137+
138+ @ Test
139+ void testCreateAccount_hieroExceptionThrown () throws HieroException {
140+ Hbar initialBalance = Hbar .from (100 );
141+
142+ when (mockProtocolLayerClient .executeAccountCreateTransaction (any (AccountCreateRequest .class )))
143+ .thenThrow (new HieroException ("Transaction failed" ));
144+
145+ Exception exception = assertThrows (HieroException .class , () -> accountClientImpl .createAccount (initialBalance ));
146+ assertEquals ("Transaction failed" , exception .getMessage ());
147+ }
148+ }
0 commit comments