-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Diffblue Cover created unit tests for module io.diffblue.corebanking:…
…CoreBanking
- Loading branch information
1 parent
431c08f
commit f25a1e3
Showing
17 changed files
with
1,486 additions
and
0 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
src/test/java/io/diffblue/corebanking/CoreBankingDiffblueTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package io.diffblue.corebanking; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertSame; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import io.diffblue.corebanking.account.Account; | ||
import io.diffblue.corebanking.client.Client; | ||
import io.diffblue.corebanking.datamanagement.ReadFromDB; | ||
import io.diffblue.corebanking.transaction.TransactionException; | ||
import java.util.List; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class CoreBankingDiffblueTest { | ||
/** | ||
* Method under test: {@link CoreBanking#purgeCoreBanking()} | ||
*/ | ||
@Test | ||
void testPurgeCoreBanking() throws TransactionException { | ||
// Arrange | ||
CoreBanking readFromDBResult = ReadFromDB.readFromDB(); | ||
|
||
// Act | ||
readFromDBResult.purgeCoreBanking(); | ||
|
||
// Assert | ||
assertTrue(readFromDBResult.getAccounts().isEmpty()); | ||
assertTrue(readFromDBResult.getClients().isEmpty()); | ||
} | ||
|
||
/** | ||
* Methods under test: | ||
* | ||
* <ul> | ||
* <li>default or parameterless constructor of {@link CoreBanking} | ||
* <li>{@link CoreBanking#getAccounts()} | ||
* <li>{@link CoreBanking#getClients()} | ||
* </ul> | ||
*/ | ||
@Test | ||
void testGettersAndSetters() { | ||
// Arrange and Act | ||
CoreBanking actualCoreBanking = new CoreBanking(); | ||
List<Account> actualAccounts = actualCoreBanking.getAccounts(); | ||
List<Client> actualClients = actualCoreBanking.getClients(); | ||
|
||
// Assert | ||
assertTrue(actualAccounts.isEmpty()); | ||
assertTrue(actualClients.isEmpty()); | ||
} | ||
|
||
/** | ||
* Method under test: {@link CoreBanking#openNewAccount(Client, long)} | ||
*/ | ||
@Test | ||
void testOpenNewAccount() throws TransactionException { | ||
// Arrange | ||
CoreBanking readFromDBResult = ReadFromDB.readFromDB(); | ||
|
||
// Act | ||
Account actualOpenNewAccountResult = readFromDBResult.openNewAccount(new Client("Dr Jane Doe"), 10L); | ||
|
||
// Assert | ||
assertEquals("Current", actualOpenNewAccountResult.getAccountName()); | ||
Client client = actualOpenNewAccountResult.getClient(); | ||
assertEquals("Dr Jane Doe", client.getClientName()); | ||
assertEquals(1, client.getAccounts().size()); | ||
assertEquals(10L, actualOpenNewAccountResult.getCurrentBalance()); | ||
assertEquals(7, readFromDBResult.getAccounts().size()); | ||
assertEquals(Account.AccountState.OPEN, actualOpenNewAccountResult.getAccountState()); | ||
assertTrue(actualOpenNewAccountResult.getAccountStatement().getTransactions().isEmpty()); | ||
} | ||
|
||
/** | ||
* Method under test: {@link CoreBanking#registerNewClient(Client)} | ||
*/ | ||
@Test | ||
void testRegisterNewClient() throws TransactionException { | ||
// Arrange | ||
CoreBanking readFromDBResult = ReadFromDB.readFromDB(); | ||
Client client = new Client("Dr Jane Doe"); | ||
|
||
// Act | ||
Client actualRegisterNewClientResult = readFromDBResult.registerNewClient(client); | ||
|
||
// Assert | ||
assertEquals(4, readFromDBResult.getClients().size()); | ||
assertSame(client, actualRegisterNewClientResult); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/test/java/io/diffblue/corebanking/CoreBankingExceptionDiffblueTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.diffblue.corebanking; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class CoreBankingExceptionDiffblueTest { | ||
/** | ||
* Method under test: {@link CoreBankingException#CoreBankingException(String)} | ||
*/ | ||
@Test | ||
void testNewCoreBankingException() { | ||
// Arrange and Act | ||
CoreBankingException actualCoreBankingException = new CoreBankingException("An error occurred"); | ||
|
||
// Assert | ||
assertEquals("An error occurred", actualCoreBankingException.getLocalizedMessage()); | ||
assertEquals("An error occurred", actualCoreBankingException.getMessage()); | ||
assertNull(actualCoreBankingException.getCause()); | ||
assertEquals(0, actualCoreBankingException.getSuppressed().length); | ||
} | ||
} |
266 changes: 266 additions & 0 deletions
266
src/test/java/io/diffblue/corebanking/account/AccountDiffblueTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,266 @@ | ||
package io.diffblue.corebanking.account; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
import static org.junit.jupiter.api.Assertions.assertSame; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.mockito.Mockito.mock; | ||
import io.diffblue.corebanking.client.Client; | ||
import io.diffblue.corebanking.transaction.CashTransaction; | ||
import io.diffblue.corebanking.transaction.Transaction; | ||
import java.time.LocalDate; | ||
import java.time.ZoneOffset; | ||
import java.util.Date; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class AccountDiffblueTest { | ||
/** | ||
* Methods under test: | ||
* | ||
* <ul> | ||
* <li>{@link Account.AccountStatement#AccountStatement(Account)} | ||
* <li>{@link Account.AccountStatement#getTransactions()} | ||
* </ul> | ||
*/ | ||
@Test | ||
void testAccountStatementGettersAndSetters() { | ||
// Arrange, Act and Assert | ||
assertTrue(((new Account(1234567890L, new Client("Dr Jane Doe"), 10L)).new AccountStatement()).getTransactions() | ||
.isEmpty()); | ||
} | ||
|
||
/** | ||
* Method under test: {@link Account.AccountStatement#toString()} | ||
*/ | ||
@Test | ||
void testAccountStatementToString() { | ||
// Arrange, Act and Assert | ||
assertEquals("Account statement empty.", | ||
((new Account(1234567890L, new Client("Dr Jane Doe"), 10L)).new AccountStatement()).toString()); | ||
} | ||
|
||
/** | ||
* Method under test: {@link Account#addToBalance(long)} | ||
*/ | ||
@Test | ||
void testAddToBalance() throws AccountException { | ||
// Arrange | ||
Account account = new Account(1234567890L, new Client("Dr Jane Doe"), 10L); | ||
|
||
// Act | ||
account.addToBalance(10L); | ||
|
||
// Assert | ||
assertEquals(20L, account.getCurrentBalance()); | ||
} | ||
|
||
/** | ||
* Method under test: {@link Account#takeFromBalance(long)} | ||
*/ | ||
@Test | ||
void testTakeFromBalance() throws AccountException { | ||
// Arrange | ||
Account account = new Account(1234567890L, new Client("Dr Jane Doe"), 10L); | ||
|
||
// Act | ||
account.takeFromBalance(10L); | ||
|
||
// Assert | ||
assertEquals(0L, account.getCurrentBalance()); | ||
} | ||
|
||
/** | ||
* Method under test: {@link Account#takeFromBalance(long)} | ||
*/ | ||
@Test | ||
void testTakeFromBalance2() throws AccountException { | ||
// Arrange, Act and Assert | ||
assertThrows(AccountException.class, | ||
() -> (new Account(1234567890L, new Client("Dr Jane Doe"), 1L)).takeFromBalance(10L)); | ||
} | ||
|
||
/** | ||
* Method under test: {@link Account#setAccountName(String)} | ||
*/ | ||
@Test | ||
void testSetAccountName() throws AccountException { | ||
// Arrange | ||
Account account = new Account(1234567890L, new Client("Dr Jane Doe"), 10L); | ||
|
||
// Act | ||
account.setAccountName("Dr Jane Doe"); | ||
|
||
// Assert | ||
assertEquals("Dr Jane Doe", account.getAccountName()); | ||
} | ||
|
||
/** | ||
* Method under test: {@link Account#closeAccount()} | ||
*/ | ||
@Test | ||
void testCloseAccount() throws AccountException { | ||
// Arrange | ||
Account account = new Account(1234567890L, new Client("Dr Jane Doe"), 10L); | ||
|
||
// Act | ||
account.closeAccount(); | ||
|
||
// Assert | ||
assertEquals(Account.AccountState.CLOSED, account.getAccountState()); | ||
} | ||
|
||
/** | ||
* Method under test: {@link Account#addTransaction(Transaction)} | ||
*/ | ||
@Test | ||
void testAddTransaction() throws AccountException { | ||
// Arrange | ||
Account account = new Account(1234567890L, new Client("Dr Jane Doe"), 10L); | ||
Date date = Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant()); | ||
|
||
// Act | ||
account.addTransaction(new CashTransaction(10L, date, new Account(1234567890L, new Client("Dr Jane Doe"), 10L))); | ||
|
||
// Assert | ||
assertEquals(1, account.getAccountStatement().getTransactions().size()); | ||
} | ||
|
||
/** | ||
* Method under test: {@link Account#addTransaction(Transaction)} | ||
*/ | ||
@Test | ||
void testAddTransaction2() throws AccountException { | ||
// Arrange | ||
Account account = new Account(1234567890L, new Client("Dr Jane Doe"), 10L); | ||
java.sql.Date date = mock(java.sql.Date.class); | ||
|
||
// Act | ||
account.addTransaction(new CashTransaction(10L, date, new Account(1234567890L, new Client("Dr Jane Doe"), 10L))); | ||
|
||
// Assert | ||
assertEquals(1, account.getAccountStatement().getTransactions().size()); | ||
} | ||
|
||
/** | ||
* Method under test: {@link Account#equals(Object)} | ||
*/ | ||
@Test | ||
void testEquals() { | ||
// Arrange, Act and Assert | ||
assertNotEquals(new Account(1234567890L, new Client("Dr Jane Doe"), 10L), null); | ||
assertNotEquals(new Account(1234567890L, new Client("Dr Jane Doe"), 10L), "Different type to Account"); | ||
} | ||
|
||
/** | ||
* Method under test: {@link Account#equals(Object)} | ||
*/ | ||
@Test | ||
void testEquals2() { | ||
// Arrange | ||
Account account = new Account(3L, new Client("Dr Jane Doe"), 10L); | ||
|
||
// Act and Assert | ||
assertNotEquals(account, new Account(1234567890L, new Client("Dr Jane Doe"), 10L)); | ||
} | ||
|
||
/** | ||
* Method under test: {@link Account#equals(Object)} | ||
*/ | ||
@Test | ||
void testEqualsAndHashCode() { | ||
// Arrange | ||
Account account = new Account(1234567890L, new Client("Dr Jane Doe"), 10L); | ||
|
||
// Act and Assert | ||
assertEquals(account, account); | ||
int expectedHashCodeResult = account.hashCode(); | ||
assertEquals(expectedHashCodeResult, account.hashCode()); | ||
} | ||
|
||
/** | ||
* Method under test: {@link Account#equals(Object)} | ||
*/ | ||
@Test | ||
void testEqualsAndHashCode2() { | ||
// Arrange | ||
Account account = new Account(1234567890L, new Client("Dr Jane Doe"), 10L); | ||
Account account2 = new Account(1234567890L, new Client("Dr Jane Doe"), 10L); | ||
|
||
// Act and Assert | ||
assertEquals(account, account2); | ||
int notExpectedHashCodeResult = account.hashCode(); | ||
assertNotEquals(notExpectedHashCodeResult, account2.hashCode()); | ||
} | ||
|
||
/** | ||
* Method under test: {@link Account#equals(Object)} | ||
*/ | ||
@Test | ||
void testEqualsAndHashCode3() { | ||
// Arrange | ||
Account account = new Account(1234567890L, mock(Client.class), 10L); | ||
Account account2 = new Account(1234567890L, new Client("Dr Jane Doe"), 10L); | ||
|
||
// Act and Assert | ||
assertEquals(account, account2); | ||
int notExpectedHashCodeResult = account.hashCode(); | ||
assertNotEquals(notExpectedHashCodeResult, account2.hashCode()); | ||
} | ||
|
||
/** | ||
* Methods under test: | ||
* | ||
* <ul> | ||
* <li>{@link Account#toString()} | ||
* <li>{@link Account#getAccountName()} | ||
* <li>{@link Account#getAccountNumber()} | ||
* <li>{@link Account#getAccountState()} | ||
* <li>{@link Account#getAccountStatement()} | ||
* <li>{@link Account#getClient()} | ||
* <li>{@link Account#getCurrentBalance()} | ||
* </ul> | ||
*/ | ||
@Test | ||
void testGettersAndSetters() { | ||
// Arrange | ||
Client client = new Client("Dr Jane Doe"); | ||
Account account = new Account(1234567890L, client, 10L); | ||
|
||
// Act | ||
String actualToStringResult = account.toString(); | ||
String actualAccountName = account.getAccountName(); | ||
long actualAccountNumber = account.getAccountNumber(); | ||
Account.AccountState actualAccountState = account.getAccountState(); | ||
account.getAccountStatement(); | ||
Client actualClient = account.getClient(); | ||
|
||
// Assert | ||
assertEquals( | ||
"Account: | Acc #: 1234567890\t | Acc name: Current\t | Acc holder: Dr Jane Doe\t | Acc balance: 10\t | Acc" | ||
+ " state: OPEN\t |\n" + "Account statement empty.", | ||
actualToStringResult); | ||
assertEquals("Current", actualAccountName); | ||
assertEquals(10L, account.getCurrentBalance()); | ||
assertEquals(1234567890L, actualAccountNumber); | ||
assertEquals(Account.AccountState.OPEN, actualAccountState); | ||
assertSame(client, actualClient); | ||
} | ||
|
||
/** | ||
* Method under test: {@link Account#Account(long, Client, long)} | ||
*/ | ||
@Test | ||
void testNewAccount() { | ||
// Arrange and Act | ||
Account actualAccount = new Account(1234567890L, new Client("Dr Jane Doe"), 10L); | ||
|
||
// Assert | ||
assertEquals("Current", actualAccount.getAccountName()); | ||
assertEquals("Dr Jane Doe", actualAccount.getClient().getClientName()); | ||
assertEquals(10L, actualAccount.getCurrentBalance()); | ||
assertEquals(1234567890L, actualAccount.getAccountNumber()); | ||
assertEquals(Account.AccountState.OPEN, actualAccount.getAccountState()); | ||
assertTrue(actualAccount.getAccountStatement().getTransactions().isEmpty()); | ||
} | ||
} |
Oops, something went wrong.