From f25a1e34b9a299659119c4f41ccc4173b80e8001 Mon Sep 17 00:00:00 2001 From: Diffblue CI Date: Thu, 21 Mar 2024 22:05:31 +0000 Subject: [PATCH] Diffblue Cover created unit tests for module io.diffblue.corebanking:CoreBanking --- .../corebanking/CoreBankingDiffblueTest.java | 89 ++++++ .../CoreBankingExceptionDiffblueTest.java | 22 ++ .../account/AccountDiffblueTest.java | 266 ++++++++++++++++++ .../account/AccountExceptionDiffblueTest.java | 22 ++ .../client/ClientDiffblueTest.java | 84 ++++++ ...BalanceAboveOrEqualToZeroDiffblueTest.java | 59 ++++ .../rules/ComplianceRuleDiffblueTest.java | 123 ++++++++ .../ReadFromDBDiffblueTest.java | 59 ++++ .../BankTransactionDiffblueTest.java | 170 +++++++++++ .../CashTransactionDiffblueTest.java | 222 +++++++++++++++ .../transaction/TransactionDiffblueTest.java | 166 +++++++++++ .../TransactionExceptionDiffblueTest.java | 22 ++ .../ui/menu/AccountsMenuDiffblueTest.java | 38 +++ .../ui/menu/ClientsMenuDiffblueTest.java | 38 +++ .../ui/menu/ComplianceMenuDiffblueTest.java | 38 +++ ...BankingDataManagementMenuDiffblueTest.java | 50 ++++ .../ui/menu/MainMenuDiffblueTest.java | 18 ++ 17 files changed, 1486 insertions(+) create mode 100644 src/test/java/io/diffblue/corebanking/CoreBankingDiffblueTest.java create mode 100644 src/test/java/io/diffblue/corebanking/CoreBankingExceptionDiffblueTest.java create mode 100644 src/test/java/io/diffblue/corebanking/account/AccountDiffblueTest.java create mode 100644 src/test/java/io/diffblue/corebanking/account/AccountExceptionDiffblueTest.java create mode 100644 src/test/java/io/diffblue/corebanking/client/ClientDiffblueTest.java create mode 100644 src/test/java/io/diffblue/corebanking/compliance/rules/ComplianceRuleBalanceAboveOrEqualToZeroDiffblueTest.java create mode 100644 src/test/java/io/diffblue/corebanking/compliance/rules/ComplianceRuleDiffblueTest.java create mode 100644 src/test/java/io/diffblue/corebanking/datamanagement/ReadFromDBDiffblueTest.java create mode 100644 src/test/java/io/diffblue/corebanking/transaction/BankTransactionDiffblueTest.java create mode 100644 src/test/java/io/diffblue/corebanking/transaction/CashTransactionDiffblueTest.java create mode 100644 src/test/java/io/diffblue/corebanking/transaction/TransactionDiffblueTest.java create mode 100644 src/test/java/io/diffblue/corebanking/transaction/TransactionExceptionDiffblueTest.java create mode 100644 src/test/java/io/diffblue/corebanking/ui/menu/AccountsMenuDiffblueTest.java create mode 100644 src/test/java/io/diffblue/corebanking/ui/menu/ClientsMenuDiffblueTest.java create mode 100644 src/test/java/io/diffblue/corebanking/ui/menu/ComplianceMenuDiffblueTest.java create mode 100644 src/test/java/io/diffblue/corebanking/ui/menu/CoreBankingDataManagementMenuDiffblueTest.java create mode 100644 src/test/java/io/diffblue/corebanking/ui/menu/MainMenuDiffblueTest.java diff --git a/src/test/java/io/diffblue/corebanking/CoreBankingDiffblueTest.java b/src/test/java/io/diffblue/corebanking/CoreBankingDiffblueTest.java new file mode 100644 index 0000000..1a7d9fc --- /dev/null +++ b/src/test/java/io/diffblue/corebanking/CoreBankingDiffblueTest.java @@ -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: + * + * + */ + @Test + void testGettersAndSetters() { + // Arrange and Act + CoreBanking actualCoreBanking = new CoreBanking(); + List actualAccounts = actualCoreBanking.getAccounts(); + List 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); + } +} diff --git a/src/test/java/io/diffblue/corebanking/CoreBankingExceptionDiffblueTest.java b/src/test/java/io/diffblue/corebanking/CoreBankingExceptionDiffblueTest.java new file mode 100644 index 0000000..abc9571 --- /dev/null +++ b/src/test/java/io/diffblue/corebanking/CoreBankingExceptionDiffblueTest.java @@ -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); + } +} diff --git a/src/test/java/io/diffblue/corebanking/account/AccountDiffblueTest.java b/src/test/java/io/diffblue/corebanking/account/AccountDiffblueTest.java new file mode 100644 index 0000000..fe5ef1e --- /dev/null +++ b/src/test/java/io/diffblue/corebanking/account/AccountDiffblueTest.java @@ -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: + * + *
    + *
  • {@link Account.AccountStatement#AccountStatement(Account)} + *
  • {@link Account.AccountStatement#getTransactions()} + *
+ */ + @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: + * + *
    + *
  • {@link Account#toString()} + *
  • {@link Account#getAccountName()} + *
  • {@link Account#getAccountNumber()} + *
  • {@link Account#getAccountState()} + *
  • {@link Account#getAccountStatement()} + *
  • {@link Account#getClient()} + *
  • {@link Account#getCurrentBalance()} + *
+ */ + @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()); + } +} diff --git a/src/test/java/io/diffblue/corebanking/account/AccountExceptionDiffblueTest.java b/src/test/java/io/diffblue/corebanking/account/AccountExceptionDiffblueTest.java new file mode 100644 index 0000000..abf0ae0 --- /dev/null +++ b/src/test/java/io/diffblue/corebanking/account/AccountExceptionDiffblueTest.java @@ -0,0 +1,22 @@ +package io.diffblue.corebanking.account; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import org.junit.jupiter.api.Test; + +class AccountExceptionDiffblueTest { + /** + * Method under test: {@link AccountException#AccountException(String)} + */ + @Test + void testNewAccountException() { + // Arrange and Act + AccountException actualAccountException = new AccountException("An error occurred"); + + // Assert + assertEquals("An error occurred", actualAccountException.getLocalizedMessage()); + assertEquals("An error occurred", actualAccountException.getMessage()); + assertNull(actualAccountException.getCause()); + assertEquals(0, actualAccountException.getSuppressed().length); + } +} diff --git a/src/test/java/io/diffblue/corebanking/client/ClientDiffblueTest.java b/src/test/java/io/diffblue/corebanking/client/ClientDiffblueTest.java new file mode 100644 index 0000000..1b9f316 --- /dev/null +++ b/src/test/java/io/diffblue/corebanking/client/ClientDiffblueTest.java @@ -0,0 +1,84 @@ +package io.diffblue.corebanking.client; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import io.diffblue.corebanking.account.Account; +import io.diffblue.corebanking.account.AccountException; +import org.junit.jupiter.api.Test; + +class ClientDiffblueTest { + /** + * Method under test: {@link Client#addAccount(Account)} + */ + @Test + void testAddAccount() { + // Arrange + Client client = new Client("Dr Jane Doe"); + + // Act + client.addAccount(new Account(1234567890L, new Client("Dr Jane Doe"), 10L)); + + // Assert + assertEquals(1, client.getAccounts().size()); + } + + /** + * Method under test: {@link Client#toString()} + */ + @Test + void testToString() { + // Arrange, Act and Assert + assertEquals("Client name: Dr Jane Doe\n", (new Client("Dr Jane Doe")).toString()); + } + + /** + * Method under test: {@link Client#toString()} + */ + @Test + void testToString2() { + // Arrange + Client client = new Client("Dr Jane Doe"); + client.addAccount(new Account(1234567890L, new Client("Dr Jane Doe"), 10L)); + + // Act and Assert + assertEquals("Client name: Dr Jane Doe\n" + + "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.\n", client.toString()); + } + + /** + * Method under test: {@link Client#toString()} + */ + @Test + void testToString3() throws AccountException { + // Arrange + Account account = new Account(1234567890L, new Client("Dr Jane Doe"), 10L); + account.addTransaction(null); + + Client client = new Client("Dr Jane Doe"); + client.addAccount(account); + + // Act and Assert + assertEquals("Client name: Dr Jane Doe\n" + + "Account: | Acc #: 1234567890\t | Acc name: Current\t | Acc holder: Dr Jane Doe\t | Acc balance: 10\t | Acc" + + " state: OPEN\t |\n" + "null\n" + "\n", client.toString()); + } + + /** + * Methods under test: + * + *
    + *
  • {@link Client#Client(String)} + *
  • {@link Client#getAccounts()} + *
  • {@link Client#getClientName()} + *
+ */ + @Test + void testGettersAndSetters() { + // Arrange and Act + Client actualClient = new Client("Dr Jane Doe"); + actualClient.getAccounts(); + + // Assert + assertEquals("Dr Jane Doe", actualClient.getClientName()); + } +} diff --git a/src/test/java/io/diffblue/corebanking/compliance/rules/ComplianceRuleBalanceAboveOrEqualToZeroDiffblueTest.java b/src/test/java/io/diffblue/corebanking/compliance/rules/ComplianceRuleBalanceAboveOrEqualToZeroDiffblueTest.java new file mode 100644 index 0000000..e765068 --- /dev/null +++ b/src/test/java/io/diffblue/corebanking/compliance/rules/ComplianceRuleBalanceAboveOrEqualToZeroDiffblueTest.java @@ -0,0 +1,59 @@ +package io.diffblue.corebanking.compliance.rules; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import io.diffblue.corebanking.account.Account; +import io.diffblue.corebanking.client.Client; +import org.junit.jupiter.api.Test; + +class ComplianceRuleBalanceAboveOrEqualToZeroDiffblueTest { + /** + * Method under test: default or parameterless constructor of + * {@link ComplianceRuleBalanceAboveOrEqualToZero} + */ + @Test + void testNewComplianceRuleBalanceAboveOrEqualToZero() { + // Arrange and Act + ComplianceRuleBalanceAboveOrEqualToZero actualComplianceRuleBalanceAboveOrEqualToZero = new ComplianceRuleBalanceAboveOrEqualToZero(); + + // Assert + assertTrue(actualComplianceRuleBalanceAboveOrEqualToZero.getCompliantAccounts().isEmpty()); + assertTrue(actualComplianceRuleBalanceAboveOrEqualToZero.getNonCompliantAccounts().isEmpty()); + } + + /** + * Method under test: + * {@link ComplianceRuleBalanceAboveOrEqualToZero#validateAccountCompliance(Account)} + */ + @Test + void testValidateAccountCompliance() { + // Arrange + ComplianceRuleBalanceAboveOrEqualToZero complianceRuleBalanceAboveOrEqualToZero = new ComplianceRuleBalanceAboveOrEqualToZero(); + + // Act + complianceRuleBalanceAboveOrEqualToZero + .validateAccountCompliance(new Account(1234567890L, new Client("Dr Jane Doe"), 10L)); + + // Assert + assertEquals(1, complianceRuleBalanceAboveOrEqualToZero.getCompliantAccounts().size()); + assertTrue(complianceRuleBalanceAboveOrEqualToZero.getNonCompliantAccounts().isEmpty()); + } + + /** + * Method under test: + * {@link ComplianceRuleBalanceAboveOrEqualToZero#validateAccountCompliance(Account)} + */ + @Test + void testValidateAccountCompliance2() { + // Arrange + ComplianceRuleBalanceAboveOrEqualToZero complianceRuleBalanceAboveOrEqualToZero = new ComplianceRuleBalanceAboveOrEqualToZero(); + + // Act + complianceRuleBalanceAboveOrEqualToZero + .validateAccountCompliance(new Account(1234567890L, new Client("Dr Jane Doe"), -1L)); + + // Assert + assertEquals(1, complianceRuleBalanceAboveOrEqualToZero.getNonCompliantAccounts().size()); + assertTrue(complianceRuleBalanceAboveOrEqualToZero.getCompliantAccounts().isEmpty()); + } +} diff --git a/src/test/java/io/diffblue/corebanking/compliance/rules/ComplianceRuleDiffblueTest.java b/src/test/java/io/diffblue/corebanking/compliance/rules/ComplianceRuleDiffblueTest.java new file mode 100644 index 0000000..e196782 --- /dev/null +++ b/src/test/java/io/diffblue/corebanking/compliance/rules/ComplianceRuleDiffblueTest.java @@ -0,0 +1,123 @@ +package io.diffblue.corebanking.compliance.rules; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import io.diffblue.corebanking.account.Account; +import io.diffblue.corebanking.client.Client; +import org.junit.jupiter.api.Test; + +class ComplianceRuleDiffblueTest { + /** + * Method under test: {@link ComplianceRule#addToNonCompliantAccounts(Account)} + */ + @Test + void testAddToNonCompliantAccounts() { + // Arrange + ComplianceRuleBalanceAboveOrEqualToZero complianceRuleBalanceAboveOrEqualToZero = new ComplianceRuleBalanceAboveOrEqualToZero(); + + // Act + complianceRuleBalanceAboveOrEqualToZero + .addToNonCompliantAccounts(new Account(1234567890L, new Client("Dr Jane Doe"), 10L)); + + // Assert + assertEquals(1, complianceRuleBalanceAboveOrEqualToZero.getNonCompliantAccounts().size()); + } + + /** + * Method under test: {@link ComplianceRule#addToNonCompliantAccounts(Account)} + */ + @Test + void testAddToNonCompliantAccounts2() { + // Arrange + ComplianceRuleBalanceAboveOrEqualToZero complianceRuleBalanceAboveOrEqualToZero = new ComplianceRuleBalanceAboveOrEqualToZero(); + complianceRuleBalanceAboveOrEqualToZero + .addToNonCompliantAccounts(new Account(1234567890L, new Client("Dr Jane Doe"), 10L)); + + // Act and Assert + assertThrows(IllegalStateException.class, () -> complianceRuleBalanceAboveOrEqualToZero + .addToNonCompliantAccounts(new Account(1234567890L, new Client("Dr Jane Doe"), 10L))); + } + + /** + * Method under test: {@link ComplianceRule#addToCompliantAccounts(Account)} + */ + @Test + void testAddToCompliantAccounts() { + // Arrange + ComplianceRuleBalanceAboveOrEqualToZero complianceRuleBalanceAboveOrEqualToZero = new ComplianceRuleBalanceAboveOrEqualToZero(); + + // Act + complianceRuleBalanceAboveOrEqualToZero + .addToCompliantAccounts(new Account(1234567890L, new Client("Dr Jane Doe"), 10L)); + + // Assert + assertEquals(1, complianceRuleBalanceAboveOrEqualToZero.getCompliantAccounts().size()); + } + + /** + * Method under test: {@link ComplianceRule#addToCompliantAccounts(Account)} + */ + @Test + void testAddToCompliantAccounts2() { + // Arrange + ComplianceRuleBalanceAboveOrEqualToZero complianceRuleBalanceAboveOrEqualToZero = new ComplianceRuleBalanceAboveOrEqualToZero(); + complianceRuleBalanceAboveOrEqualToZero + .addToCompliantAccounts(new Account(1234567890L, new Client("Dr Jane Doe"), 10L)); + + // Act and Assert + assertThrows(IllegalStateException.class, () -> complianceRuleBalanceAboveOrEqualToZero + .addToCompliantAccounts(new Account(1234567890L, new Client("Dr Jane Doe"), 10L))); + } + + /** + * Method under test: {@link ComplianceRule#removeFromComplianceLists(Account)} + */ + @Test + void testRemoveFromComplianceLists() { + // Arrange + ComplianceRuleBalanceAboveOrEqualToZero complianceRuleBalanceAboveOrEqualToZero = new ComplianceRuleBalanceAboveOrEqualToZero(); + + // Act + complianceRuleBalanceAboveOrEqualToZero + .removeFromComplianceLists(new Account(1234567890L, new Client("Dr Jane Doe"), 10L)); + + // Assert + assertTrue(complianceRuleBalanceAboveOrEqualToZero.getCompliantAccounts().isEmpty()); + assertTrue(complianceRuleBalanceAboveOrEqualToZero.getNonCompliantAccounts().isEmpty()); + } + + /** + * Method under test: {@link ComplianceRule#getNonCompliantAccounts()} + */ + @Test + void testGetNonCompliantAccounts() { + // Arrange, Act and Assert + assertTrue((new ComplianceRuleBalanceAboveOrEqualToZero()).getNonCompliantAccounts().isEmpty()); + } + + /** + * Method under test: {@link ComplianceRule#getCompliantAccounts()} + */ + @Test + void testGetCompliantAccounts() { + // Arrange, Act and Assert + assertTrue((new ComplianceRuleBalanceAboveOrEqualToZero()).getCompliantAccounts().isEmpty()); + } + + /** + * Method under test: {@link ComplianceRule#purgeAccounts()} + */ + @Test + void testPurgeAccounts() { + // Arrange + ComplianceRuleBalanceAboveOrEqualToZero complianceRuleBalanceAboveOrEqualToZero = new ComplianceRuleBalanceAboveOrEqualToZero(); + + // Act + complianceRuleBalanceAboveOrEqualToZero.purgeAccounts(); + + // Assert + assertTrue(complianceRuleBalanceAboveOrEqualToZero.getCompliantAccounts().isEmpty()); + assertTrue(complianceRuleBalanceAboveOrEqualToZero.getNonCompliantAccounts().isEmpty()); + } +} diff --git a/src/test/java/io/diffblue/corebanking/datamanagement/ReadFromDBDiffblueTest.java b/src/test/java/io/diffblue/corebanking/datamanagement/ReadFromDBDiffblueTest.java new file mode 100644 index 0000000..5d812b6 --- /dev/null +++ b/src/test/java/io/diffblue/corebanking/datamanagement/ReadFromDBDiffblueTest.java @@ -0,0 +1,59 @@ +package io.diffblue.corebanking.datamanagement; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import io.diffblue.corebanking.CoreBanking; +import io.diffblue.corebanking.client.Client; +import io.diffblue.corebanking.transaction.TransactionException; +import java.util.List; +import org.junit.jupiter.api.Test; + +class ReadFromDBDiffblueTest { + /** + * Method under test: {@link ReadFromDB#readFromDB()} + */ + @Test + void testReadFromDB() throws TransactionException { + // Arrange and Act + CoreBanking actualReadFromDBResult = ReadFromDB.readFromDB(); + + // Assert + List clients = actualReadFromDBResult.getClients(); + assertEquals(3, clients.size()); + Client getResult = clients.get(2); + assertEquals("Emily Simmons", getResult.getClientName()); + Client getResult2 = clients.get(1); + assertEquals("Jane Robbins", getResult2.getClientName()); + Client getResult3 = clients.get(0); + assertEquals("John Field", getResult3.getClientName()); + assertEquals(1, getResult.getAccounts().size()); + assertEquals(2, getResult2.getAccounts().size()); + assertEquals(3, getResult3.getAccounts().size()); + assertEquals(6, actualReadFromDBResult.getAccounts().size()); + } + + /** + * Method under test: {@link ReadFromDB#readFromDB(CoreBanking)} + */ + @Test + void testReadFromDB2() throws TransactionException { + // Arrange + CoreBanking coreBanking = ReadFromDB.readFromDB(); + + // Act + ReadFromDB.readFromDB(coreBanking); + + // Assert + List clients = coreBanking.getClients(); + assertEquals(3, clients.size()); + Client getResult = clients.get(2); + assertEquals("Emily Simmons", getResult.getClientName()); + Client getResult2 = clients.get(1); + assertEquals("Jane Robbins", getResult2.getClientName()); + Client getResult3 = clients.get(0); + assertEquals("John Field", getResult3.getClientName()); + assertEquals(1, getResult.getAccounts().size()); + assertEquals(2, getResult2.getAccounts().size()); + assertEquals(3, getResult3.getAccounts().size()); + assertEquals(6, coreBanking.getAccounts().size()); + } +} diff --git a/src/test/java/io/diffblue/corebanking/transaction/BankTransactionDiffblueTest.java b/src/test/java/io/diffblue/corebanking/transaction/BankTransactionDiffblueTest.java new file mode 100644 index 0000000..16e8e23 --- /dev/null +++ b/src/test/java/io/diffblue/corebanking/transaction/BankTransactionDiffblueTest.java @@ -0,0 +1,170 @@ +package io.diffblue.corebanking.transaction; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.Mockito.mock; +import io.diffblue.corebanking.account.Account; +import io.diffblue.corebanking.client.Client; +import java.time.LocalDate; +import java.time.ZoneOffset; +import java.util.Date; +import org.junit.jupiter.api.Test; + +class BankTransactionDiffblueTest { + /** + * Method under test: {@link BankTransaction#getSource()} + */ + @Test + void testGetSource() { + // Arrange + Date date = Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant()); + Account sourceAcc = new Account(1234567890L, new Client("Dr Jane Doe"), 10L); + + // Act and Assert + assertEquals("1234567890", + (new BankTransaction(10L, date, sourceAcc, new Account(1234567890L, new Client("Dr Jane Doe"), 10L))) + .getSource()); + } + + /** + * Method under test: {@link BankTransaction#getSource()} + */ + @Test + void testGetSource2() { + // Arrange + java.sql.Date date = mock(java.sql.Date.class); + Account sourceAcc = new Account(1234567890L, new Client("Dr Jane Doe"), 10L); + + // Act and Assert + assertEquals("1234567890", + (new BankTransaction(10L, date, sourceAcc, new Account(1234567890L, new Client("Dr Jane Doe"), 10L))) + .getSource()); + } + + /** + * Method under test: {@link BankTransaction#getTarget()} + */ + @Test + void testGetTarget() { + // Arrange + Date date = Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant()); + Account sourceAcc = new Account(1234567890L, new Client("Dr Jane Doe"), 10L); + + // Act and Assert + assertEquals("1234567890", + (new BankTransaction(10L, date, sourceAcc, new Account(1234567890L, new Client("Dr Jane Doe"), 10L))) + .getTarget()); + } + + /** + * Method under test: {@link BankTransaction#getTarget()} + */ + @Test + void testGetTarget2() { + // Arrange + java.sql.Date date = mock(java.sql.Date.class); + Account sourceAcc = new Account(1234567890L, new Client("Dr Jane Doe"), 10L); + + // Act and Assert + assertEquals("1234567890", + (new BankTransaction(10L, date, sourceAcc, new Account(1234567890L, new Client("Dr Jane Doe"), 10L))) + .getTarget()); + } + + /** + * Method under test: {@link BankTransaction#executeTransaction()} + */ + @Test + void testExecuteTransaction() throws TransactionException { + // Arrange + Date date = Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant()); + Account sourceAcc = new Account(1234567890L, new Client("Dr Jane Doe"), 10L); + + BankTransaction bankTransaction = new BankTransaction(10L, date, sourceAcc, + new Account(1234567890L, new Client("Dr Jane Doe"), 10L)); + + // Act + bankTransaction.executeTransaction(); + + // Assert + assertEquals(Transaction.TransactionState.EXECUTED, bankTransaction.getTransactionState()); + } + + /** + * Method under test: {@link BankTransaction#executeTransaction()} + */ + @Test + void testExecuteTransaction2() throws TransactionException { + // Arrange + Date date = Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant()); + Account sourceAcc = new Account(1234567890L, new Client("Dr Jane Doe"), 10L); + + // Act and Assert + assertThrows(TransactionException.class, () -> (new BankTransaction(Long.MAX_VALUE, date, sourceAcc, + new Account(1234567890L, new Client("Dr Jane Doe"), 10L))).executeTransaction()); + } + + /** + * Method under test: {@link BankTransaction#executeTransaction()} + */ + @Test + void testExecuteTransaction3() throws TransactionException { + // Arrange + java.sql.Date date = mock(java.sql.Date.class); + Account sourceAcc = new Account(1234567890L, new Client("Dr Jane Doe"), 10L); + + BankTransaction bankTransaction = new BankTransaction(10L, date, sourceAcc, + new Account(1234567890L, new Client("Dr Jane Doe"), 10L)); + + // Act + bankTransaction.executeTransaction(); + + // Assert + assertEquals(Transaction.TransactionState.EXECUTED, bankTransaction.getTransactionState()); + } + + /** + * Method under test: + * {@link BankTransaction#BankTransaction(long, Date, Account, Account)} + */ + @Test + void testNewBankTransaction() { + // Arrange + Date date = Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant()); + Account sourceAcc = new Account(1234567890L, new Client("Dr Jane Doe"), 10L); + + // Act + BankTransaction actualBankTransaction = new BankTransaction(10L, date, sourceAcc, + new Account(1234567890L, new Client("Dr Jane Doe"), 10L)); + + // Assert + assertEquals("1234567890", actualBankTransaction.getSource()); + assertEquals("1234567890", actualBankTransaction.getTarget()); + assertEquals(10L, actualBankTransaction.getTransactionAmount()); + assertEquals(Transaction.TransactionState.NOT_EXECUTED_YET, actualBankTransaction.getTransactionState()); + assertSame(date, actualBankTransaction.getTransactionDate()); + } + + /** + * Method under test: + * {@link BankTransaction#BankTransaction(long, java.util.Date, Account, Account)} + */ + @Test + void testNewBankTransaction2() { + // Arrange + java.sql.Date date = mock(java.sql.Date.class); + Account sourceAcc = new Account(1234567890L, new Client("Dr Jane Doe"), 10L); + + // Act + BankTransaction actualBankTransaction = new BankTransaction(10L, date, sourceAcc, + new Account(1234567890L, new Client("Dr Jane Doe"), 10L)); + + // Assert + assertEquals("1234567890", actualBankTransaction.getSource()); + assertEquals("1234567890", actualBankTransaction.getTarget()); + assertEquals(10L, actualBankTransaction.getTransactionAmount()); + assertEquals(Transaction.TransactionState.NOT_EXECUTED_YET, actualBankTransaction.getTransactionState()); + assertSame(date, actualBankTransaction.getTransactionDate()); + } +} diff --git a/src/test/java/io/diffblue/corebanking/transaction/CashTransactionDiffblueTest.java b/src/test/java/io/diffblue/corebanking/transaction/CashTransactionDiffblueTest.java new file mode 100644 index 0000000..4a4a213 --- /dev/null +++ b/src/test/java/io/diffblue/corebanking/transaction/CashTransactionDiffblueTest.java @@ -0,0 +1,222 @@ +package io.diffblue.corebanking.transaction; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.mockito.Mockito.mock; +import io.diffblue.corebanking.account.Account; +import io.diffblue.corebanking.client.Client; +import java.time.LocalDate; +import java.time.ZoneOffset; +import java.util.Date; +import org.junit.jupiter.api.Test; + +class CashTransactionDiffblueTest { + /** + * Method under test: {@link CashTransaction#getSource()} + */ + @Test + void testGetSource() { + // Arrange + Date date = Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant()); + + // Act and Assert + assertEquals("CASH", + (new CashTransaction(10L, date, new Account(1234567890L, new Client("Dr Jane Doe"), 10L))).getSource()); + } + + /** + * Method under test: {@link CashTransaction#getSource()} + */ + @Test + void testGetSource2() { + // Arrange + Date date = Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant()); + + // Act and Assert + assertEquals("1234567890", + (new CashTransaction(-1L, date, new Account(1234567890L, new Client("Dr Jane Doe"), 10L))).getSource()); + } + + /** + * Method under test: {@link CashTransaction#getSource()} + */ + @Test + void testGetSource3() { + // Arrange + java.sql.Date date = mock(java.sql.Date.class); + + // Act and Assert + assertEquals("CASH", + (new CashTransaction(10L, date, new Account(1234567890L, new Client("Dr Jane Doe"), 10L))).getSource()); + } + + /** + * Method under test: {@link CashTransaction#getTarget()} + */ + @Test + void testGetTarget() { + // Arrange + Date date = Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant()); + + // Act and Assert + assertEquals("1234567890", + (new CashTransaction(10L, date, new Account(1234567890L, new Client("Dr Jane Doe"), 10L))).getTarget()); + } + + /** + * Method under test: {@link CashTransaction#getTarget()} + */ + @Test + void testGetTarget2() { + // Arrange + Date date = Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant()); + + // Act and Assert + assertEquals("CASH", + (new CashTransaction(-1L, date, new Account(1234567890L, new Client("Dr Jane Doe"), 10L))).getTarget()); + } + + /** + * Method under test: {@link CashTransaction#getTarget()} + */ + @Test + void testGetTarget3() { + // Arrange + java.sql.Date date = mock(java.sql.Date.class); + + // Act and Assert + assertEquals("1234567890", + (new CashTransaction(10L, date, new Account(1234567890L, new Client("Dr Jane Doe"), 10L))).getTarget()); + } + + /** + * Method under test: {@link CashTransaction#executeTransaction()} + */ + @Test + void testExecuteTransaction() throws TransactionException { + // Arrange + Date date = Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant()); + CashTransaction cashTransaction = new CashTransaction(10L, date, + new Account(1234567890L, new Client("Dr Jane Doe"), 10L)); + + // Act + cashTransaction.executeTransaction(); + + // Assert + assertEquals(Transaction.TransactionState.EXECUTED, cashTransaction.getTransactionState()); + } + + /** + * Method under test: {@link CashTransaction#executeTransaction()} + */ + @Test + void testExecuteTransaction2() throws TransactionException { + // Arrange + Date date = Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant()); + CashTransaction cashTransaction = new CashTransaction(-1L, date, + new Account(1234567890L, new Client("Dr Jane Doe"), 10L)); + + // Act + cashTransaction.executeTransaction(); + + // Assert + assertEquals(Transaction.TransactionState.EXECUTED, cashTransaction.getTransactionState()); + } + + /** + * Method under test: {@link CashTransaction#executeTransaction()} + */ + @Test + void testExecuteTransaction3() throws TransactionException { + // Arrange + Date date = Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant()); + CashTransaction cashTransaction = new CashTransaction(Long.MIN_VALUE, date, + new Account(1234567890L, new Client("Dr Jane Doe"), 10L)); + + // Act + cashTransaction.executeTransaction(); + + // Assert + assertEquals(Transaction.TransactionState.FAILED, cashTransaction.getTransactionState()); + } + + /** + * Method under test: {@link CashTransaction#executeTransaction()} + */ + @Test + void testExecuteTransaction4() throws TransactionException { + // Arrange + java.sql.Date date = mock(java.sql.Date.class); + CashTransaction cashTransaction = new CashTransaction(10L, date, + new Account(1234567890L, new Client("Dr Jane Doe"), 10L)); + + // Act + cashTransaction.executeTransaction(); + + // Assert + assertEquals(Transaction.TransactionState.EXECUTED, cashTransaction.getTransactionState()); + } + + /** + * Method under test: + * {@link CashTransaction#CashTransaction(long, Date, Account)} + */ + @Test + void testNewCashTransaction() { + // Arrange + Date date = Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant()); + + // Act + CashTransaction actualCashTransaction = new CashTransaction(10L, date, + new Account(1234567890L, new Client("Dr Jane Doe"), 10L)); + + // Assert + assertEquals("1234567890", actualCashTransaction.getTarget()); + assertEquals("CASH", actualCashTransaction.getSource()); + assertEquals(10L, actualCashTransaction.getTransactionAmount()); + assertEquals(Transaction.TransactionState.NOT_EXECUTED_YET, actualCashTransaction.getTransactionState()); + assertSame(date, actualCashTransaction.getTransactionDate()); + } + + /** + * Method under test: + * {@link CashTransaction#CashTransaction(long, Date, Account)} + */ + @Test + void testNewCashTransaction2() { + // Arrange + Date date = Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant()); + + // Act + CashTransaction actualCashTransaction = new CashTransaction(-1L, date, + new Account(1234567890L, new Client("Dr Jane Doe"), 10L)); + + // Assert + assertEquals("1234567890", actualCashTransaction.getSource()); + assertEquals("CASH", actualCashTransaction.getTarget()); + assertEquals(-1L, actualCashTransaction.getTransactionAmount()); + assertEquals(Transaction.TransactionState.NOT_EXECUTED_YET, actualCashTransaction.getTransactionState()); + assertSame(date, actualCashTransaction.getTransactionDate()); + } + + /** + * Method under test: + * {@link CashTransaction#CashTransaction(long, java.util.Date, Account)} + */ + @Test + void testNewCashTransaction3() { + // Arrange + java.sql.Date date = mock(java.sql.Date.class); + + // Act + CashTransaction actualCashTransaction = new CashTransaction(10L, date, + new Account(1234567890L, new Client("Dr Jane Doe"), 10L)); + + // Assert + assertEquals("1234567890", actualCashTransaction.getTarget()); + assertEquals("CASH", actualCashTransaction.getSource()); + assertEquals(10L, actualCashTransaction.getTransactionAmount()); + assertEquals(Transaction.TransactionState.NOT_EXECUTED_YET, actualCashTransaction.getTransactionState()); + assertSame(date, actualCashTransaction.getTransactionDate()); + } +} diff --git a/src/test/java/io/diffblue/corebanking/transaction/TransactionDiffblueTest.java b/src/test/java/io/diffblue/corebanking/transaction/TransactionDiffblueTest.java new file mode 100644 index 0000000..a76f2c6 --- /dev/null +++ b/src/test/java/io/diffblue/corebanking/transaction/TransactionDiffblueTest.java @@ -0,0 +1,166 @@ +package io.diffblue.corebanking.transaction; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import io.diffblue.corebanking.account.Account; +import io.diffblue.corebanking.client.Client; +import java.time.LocalDate; +import java.time.ZoneOffset; +import java.util.Date; +import org.junit.jupiter.api.Test; + +class TransactionDiffblueTest { + /** + * Method under test: {@link Transaction#getTransactionAmount()} + */ + @Test + void testGetTransactionAmount() { + // Arrange + Date date = Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant()); + + // Act and Assert + assertEquals(10L, (new CashTransaction(10L, date, new Account(1234567890L, new Client("Dr Jane Doe"), 10L))) + .getTransactionAmount()); + } + + /** + * Method under test: {@link Transaction#getTransactionAmount()} + */ + @Test + void testGetTransactionAmount2() { + // Arrange + java.sql.Date date = mock(java.sql.Date.class); + + // Act and Assert + assertEquals(10L, (new CashTransaction(10L, date, new Account(1234567890L, new Client("Dr Jane Doe"), 10L))) + .getTransactionAmount()); + } + + /** + * Method under test: {@link Transaction#getTransactionDate()} + */ + @Test + void testGetTransactionDate() { + // Arrange + Date date = Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant()); + + // Act and Assert + assertSame(date, (new CashTransaction(10L, date, new Account(1234567890L, new Client("Dr Jane Doe"), 10L))) + .getTransactionDate()); + } + + /** + * Method under test: {@link Transaction#getTransactionState()} + */ + @Test + void testGetTransactionState() { + // Arrange + Date date = Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant()); + + // Act and Assert + assertEquals(Transaction.TransactionState.NOT_EXECUTED_YET, + (new CashTransaction(10L, date, new Account(1234567890L, new Client("Dr Jane Doe"), 10L))) + .getTransactionState()); + } + + /** + * Method under test: {@link Transaction#getTransactionState()} + */ + @Test + void testGetTransactionState2() { + // Arrange + java.sql.Date date = mock(java.sql.Date.class); + + // Act and Assert + assertEquals(Transaction.TransactionState.NOT_EXECUTED_YET, + (new CashTransaction(10L, date, new Account(1234567890L, new Client("Dr Jane Doe"), 10L))) + .getTransactionState()); + } + + /** + * Method under test: {@link Transaction#setCurrentStateFailed()} + */ + @Test + void testSetCurrentStateFailed() throws TransactionException { + // Arrange + Date date = Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant()); + CashTransaction cashTransaction = new CashTransaction(10L, date, + new Account(1234567890L, new Client("Dr Jane Doe"), 10L)); + + // Act + cashTransaction.setCurrentStateFailed(); + + // Assert + assertEquals(Transaction.TransactionState.FAILED, cashTransaction.getTransactionState()); + } + + /** + * Method under test: {@link Transaction#setCurrentStateFailed()} + */ + @Test + void testSetCurrentStateFailed2() throws TransactionException { + // Arrange + java.sql.Date date = mock(java.sql.Date.class); + CashTransaction cashTransaction = new CashTransaction(10L, date, + new Account(1234567890L, new Client("Dr Jane Doe"), 10L)); + + // Act + cashTransaction.setCurrentStateFailed(); + + // Assert + assertEquals(Transaction.TransactionState.FAILED, cashTransaction.getTransactionState()); + } + + /** + * Method under test: {@link Transaction#markTransactionAsExecuted()} + */ + @Test + void testMarkTransactionAsExecuted() { + // Arrange + Date date = Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant()); + CashTransaction cashTransaction = new CashTransaction(10L, date, + new Account(1234567890L, new Client("Dr Jane Doe"), 10L)); + + // Act + cashTransaction.markTransactionAsExecuted(); + + // Assert + assertEquals(Transaction.TransactionState.EXECUTED, cashTransaction.getTransactionState()); + } + + /** + * Method under test: {@link Transaction#markTransactionAsExecuted()} + */ + @Test + void testMarkTransactionAsExecuted2() { + // Arrange + java.sql.Date date = mock(java.sql.Date.class); + CashTransaction cashTransaction = new CashTransaction(10L, date, + new Account(1234567890L, new Client("Dr Jane Doe"), 10L)); + + // Act + cashTransaction.markTransactionAsExecuted(); + + // Assert + assertEquals(Transaction.TransactionState.EXECUTED, cashTransaction.getTransactionState()); + } + + /** + * Method under test: {@link Transaction#toString()} + */ + @Test + void testToString() { + // Arrange + java.sql.Date date = mock(java.sql.Date.class); + when(date.getTime()).thenReturn(10L); + + // Act + (new CashTransaction(10L, date, new Account(1234567890L, new Client("Dr Jane Doe"), 10L))).toString(); + + // Assert + verify(date).getTime(); + } +} diff --git a/src/test/java/io/diffblue/corebanking/transaction/TransactionExceptionDiffblueTest.java b/src/test/java/io/diffblue/corebanking/transaction/TransactionExceptionDiffblueTest.java new file mode 100644 index 0000000..f459c29 --- /dev/null +++ b/src/test/java/io/diffblue/corebanking/transaction/TransactionExceptionDiffblueTest.java @@ -0,0 +1,22 @@ +package io.diffblue.corebanking.transaction; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import org.junit.jupiter.api.Test; + +class TransactionExceptionDiffblueTest { + /** + * Method under test: {@link TransactionException#TransactionException(String)} + */ + @Test + void testNewTransactionException() { + // Arrange and Act + TransactionException actualTransactionException = new TransactionException("An error occurred"); + + // Assert + assertEquals("An error occurred", actualTransactionException.getLocalizedMessage()); + assertEquals("An error occurred", actualTransactionException.getMessage()); + assertNull(actualTransactionException.getCause()); + assertEquals(0, actualTransactionException.getSuppressed().length); + } +} diff --git a/src/test/java/io/diffblue/corebanking/ui/menu/AccountsMenuDiffblueTest.java b/src/test/java/io/diffblue/corebanking/ui/menu/AccountsMenuDiffblueTest.java new file mode 100644 index 0000000..08d5cc3 --- /dev/null +++ b/src/test/java/io/diffblue/corebanking/ui/menu/AccountsMenuDiffblueTest.java @@ -0,0 +1,38 @@ +package io.diffblue.corebanking.ui.menu; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import io.diffblue.corebanking.CoreBanking; +import io.diffblue.corebanking.datamanagement.ReadFromDB; +import io.diffblue.corebanking.transaction.TransactionException; +import java.util.ArrayList; +import org.junit.jupiter.api.Test; + +class AccountsMenuDiffblueTest { + /** + * Method under test: {@link AccountsMenu#executeMenuOption(int)} + */ + @Test + void testExecuteMenuOption() { + // Arrange + CoreBanking coreBanking = mock(CoreBanking.class); + when(coreBanking.getAccounts()).thenReturn(new ArrayList<>()); + + // Act + (new AccountsMenu(coreBanking)).executeMenuOption(1); + + // Assert + verify(coreBanking).getAccounts(); + } + + /** + * Method under test: {@link AccountsMenu#AccountsMenu(CoreBanking)} + */ + @Test + void testNewAccountsMenu() throws TransactionException { + // Arrange, Act and Assert + assertEquals(6, (new AccountsMenu(ReadFromDB.readFromDB())).coreBanking.getAccounts().size()); + } +} diff --git a/src/test/java/io/diffblue/corebanking/ui/menu/ClientsMenuDiffblueTest.java b/src/test/java/io/diffblue/corebanking/ui/menu/ClientsMenuDiffblueTest.java new file mode 100644 index 0000000..e34df7f --- /dev/null +++ b/src/test/java/io/diffblue/corebanking/ui/menu/ClientsMenuDiffblueTest.java @@ -0,0 +1,38 @@ +package io.diffblue.corebanking.ui.menu; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import io.diffblue.corebanking.CoreBanking; +import io.diffblue.corebanking.datamanagement.ReadFromDB; +import io.diffblue.corebanking.transaction.TransactionException; +import java.util.ArrayList; +import org.junit.jupiter.api.Test; + +class ClientsMenuDiffblueTest { + /** + * Method under test: {@link ClientsMenu#executeMenuOption(int)} + */ + @Test + void testExecuteMenuOption() { + // Arrange + CoreBanking coreBanking = mock(CoreBanking.class); + when(coreBanking.getClients()).thenReturn(new ArrayList<>()); + + // Act + (new ClientsMenu(coreBanking)).executeMenuOption(1); + + // Assert + verify(coreBanking).getClients(); + } + + /** + * Method under test: {@link ClientsMenu#ClientsMenu(CoreBanking)} + */ + @Test + void testNewClientsMenu() throws TransactionException { + // Arrange, Act and Assert + assertEquals(6, (new ClientsMenu(ReadFromDB.readFromDB())).coreBanking.getAccounts().size()); + } +} diff --git a/src/test/java/io/diffblue/corebanking/ui/menu/ComplianceMenuDiffblueTest.java b/src/test/java/io/diffblue/corebanking/ui/menu/ComplianceMenuDiffblueTest.java new file mode 100644 index 0000000..6cb9279 --- /dev/null +++ b/src/test/java/io/diffblue/corebanking/ui/menu/ComplianceMenuDiffblueTest.java @@ -0,0 +1,38 @@ +package io.diffblue.corebanking.ui.menu; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import io.diffblue.corebanking.CoreBanking; +import io.diffblue.corebanking.datamanagement.ReadFromDB; +import io.diffblue.corebanking.transaction.TransactionException; +import java.util.ArrayList; +import org.junit.jupiter.api.Test; + +class ComplianceMenuDiffblueTest { + /** + * Method under test: {@link ComplianceMenu#executeMenuOption(int)} + */ + @Test + void testExecuteMenuOption() { + // Arrange + CoreBanking coreBanking = mock(CoreBanking.class); + when(coreBanking.getAccounts()).thenReturn(new ArrayList<>()); + + // Act + (new ComplianceMenu(coreBanking)).executeMenuOption(1); + + // Assert + verify(coreBanking).getAccounts(); + } + + /** + * Method under test: {@link ComplianceMenu#ComplianceMenu(CoreBanking)} + */ + @Test + void testNewComplianceMenu() throws TransactionException { + // Arrange, Act and Assert + assertEquals(6, (new ComplianceMenu(ReadFromDB.readFromDB())).coreBanking.getAccounts().size()); + } +} diff --git a/src/test/java/io/diffblue/corebanking/ui/menu/CoreBankingDataManagementMenuDiffblueTest.java b/src/test/java/io/diffblue/corebanking/ui/menu/CoreBankingDataManagementMenuDiffblueTest.java new file mode 100644 index 0000000..111d72b --- /dev/null +++ b/src/test/java/io/diffblue/corebanking/ui/menu/CoreBankingDataManagementMenuDiffblueTest.java @@ -0,0 +1,50 @@ +package io.diffblue.corebanking.ui.menu; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import io.diffblue.corebanking.CoreBanking; +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 CoreBankingDataManagementMenuDiffblueTest { + /** + * Method under test: + * {@link CoreBankingDataManagementMenu#executeMenuOption(int)} + */ + @Test + void testExecuteMenuOption() throws TransactionException { + // Arrange + CoreBankingDataManagementMenu coreBankingDataManagementMenu = new CoreBankingDataManagementMenu( + ReadFromDB.readFromDB()); + + // Act + coreBankingDataManagementMenu.executeMenuOption(2); + + // Assert + CoreBanking coreBanking = coreBankingDataManagementMenu.coreBanking; + List clients = coreBanking.getClients(); + assertEquals(3, clients.size()); + Client getResult = clients.get(2); + assertEquals("Emily Simmons", getResult.getClientName()); + Client getResult2 = clients.get(1); + assertEquals("Jane Robbins", getResult2.getClientName()); + Client getResult3 = clients.get(0); + assertEquals("John Field", getResult3.getClientName()); + assertEquals(1, getResult.getAccounts().size()); + assertEquals(2, getResult2.getAccounts().size()); + assertEquals(3, getResult3.getAccounts().size()); + assertEquals(6, coreBanking.getAccounts().size()); + } + + /** + * Method under test: + * {@link CoreBankingDataManagementMenu#CoreBankingDataManagementMenu(CoreBanking)} + */ + @Test + void testNewCoreBankingDataManagementMenu() throws TransactionException { + // Arrange, Act and Assert + assertEquals(6, (new CoreBankingDataManagementMenu(ReadFromDB.readFromDB())).coreBanking.getAccounts().size()); + } +} diff --git a/src/test/java/io/diffblue/corebanking/ui/menu/MainMenuDiffblueTest.java b/src/test/java/io/diffblue/corebanking/ui/menu/MainMenuDiffblueTest.java new file mode 100644 index 0000000..3919115 --- /dev/null +++ b/src/test/java/io/diffblue/corebanking/ui/menu/MainMenuDiffblueTest.java @@ -0,0 +1,18 @@ +package io.diffblue.corebanking.ui.menu; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import io.diffblue.corebanking.CoreBanking; +import io.diffblue.corebanking.datamanagement.ReadFromDB; +import io.diffblue.corebanking.transaction.TransactionException; +import org.junit.jupiter.api.Test; + +class MainMenuDiffblueTest { + /** + * Method under test: {@link MainMenu#MainMenu(CoreBanking)} + */ + @Test + void testNewMainMenu() throws TransactionException { + // Arrange, Act and Assert + assertEquals(6, (new MainMenu(ReadFromDB.readFromDB())).coreBanking.getAccounts().size()); + } +}