From a12fac44a93921e6b9fca2814acddf0e38e732c0 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Tue, 18 Feb 2020 20:20:13 +0100 Subject: [PATCH 001/120] modification of current date type for LocalDateTime --- .../java/fr/unantes/software/construction/Account.java | 5 +++-- .../unantes/software/construction/DepositOperation.java | 6 ++++-- .../java/fr/unantes/software/construction/Operation.java | 8 +++++--- .../unantes/software/construction/WithdrawOperation.java | 6 ++++-- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/Account.java b/src/main/java/fr/unantes/software/construction/Account.java index cf6ef413..96fd9610 100755 --- a/src/main/java/fr/unantes/software/construction/Account.java +++ b/src/main/java/fr/unantes/software/construction/Account.java @@ -1,6 +1,7 @@ package fr.unantes.software.construction; import java.io.InvalidClassException; +import java.time.LocalDateTime; import java.util.Collection; import java.util.Vector; import java.util.Iterator; @@ -45,13 +46,13 @@ public class Account { float newBalance = balance - amount; if (newBalance > 0){ balance = newBalance; - Operation o = new WithdrawOperation(amount, (int)System.currentTimeMillis()); + Operation o = new WithdrawOperation(amount, LocalDateTime.now()); addHistory(o); } else{ if ((Math.abs(newBalance)) <= overdraft){ balance = newBalance; - Operation o = new WithdrawOperation(amount,(int)System.currentTimeMillis()); + Operation o = new WithdrawOperation(amount,LocalDateTime.now()); addHistory(o); throw new Exception("Warning: the balance is negative: "+balance); } diff --git a/src/main/java/fr/unantes/software/construction/DepositOperation.java b/src/main/java/fr/unantes/software/construction/DepositOperation.java index a77f9405..bd2de044 100755 --- a/src/main/java/fr/unantes/software/construction/DepositOperation.java +++ b/src/main/java/fr/unantes/software/construction/DepositOperation.java @@ -1,13 +1,15 @@ package fr.unantes.software.construction; +import java.time.LocalDateTime; + public class DepositOperation extends Operation { /** * Calls the constructor of super class with the parameter amount */ - public DepositOperation(float amount, int i) { - super(amount, i); + public DepositOperation(float amount, LocalDateTime dateTime) { + super(amount, dateTime); } /** diff --git a/src/main/java/fr/unantes/software/construction/Operation.java b/src/main/java/fr/unantes/software/construction/Operation.java index 6c889331..76a241b0 100755 --- a/src/main/java/fr/unantes/software/construction/Operation.java +++ b/src/main/java/fr/unantes/software/construction/Operation.java @@ -1,9 +1,11 @@ package fr.unantes.software.construction; +import java.time.LocalDateTime; + public abstract class Operation { public Account account; - private int time; + private LocalDateTime dateTime; /** * @@ -33,9 +35,9 @@ public abstract class Operation { /** * Sets the amount with the parameter */ - public Operation(float amount, int i) { + public Operation(float amount, LocalDateTime dateTime) { this.amount = amount; - this.time = i; + this.dateTime = dateTime; } /** diff --git a/src/main/java/fr/unantes/software/construction/WithdrawOperation.java b/src/main/java/fr/unantes/software/construction/WithdrawOperation.java index e6a9a64b..d4a16f01 100755 --- a/src/main/java/fr/unantes/software/construction/WithdrawOperation.java +++ b/src/main/java/fr/unantes/software/construction/WithdrawOperation.java @@ -1,13 +1,15 @@ package fr.unantes.software.construction; +import java.time.LocalDateTime; + public class WithdrawOperation extends Operation { /** * calls the super constructor with the amount */ - public WithdrawOperation(float amount, int i) { - super(amount, i); + public WithdrawOperation(float amount, LocalDateTime dateTime) { + super(amount, dateTime); } /** -- GitLab From 0f226189fdfe3f265a98bc468190416787567134 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Wed, 19 Feb 2020 07:43:56 +0100 Subject: [PATCH 002/120] modified date type to LocalDateTime --- .../java/fr/unantes/software/construction/Account.java | 5 +++-- .../unantes/software/construction/DepositOperation.java | 6 ++++-- .../java/fr/unantes/software/construction/Operation.java | 8 +++++--- .../unantes/software/construction/WithdrawOperation.java | 6 ++++-- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/Account.java b/src/main/java/fr/unantes/software/construction/Account.java index cf6ef413..96fd9610 100755 --- a/src/main/java/fr/unantes/software/construction/Account.java +++ b/src/main/java/fr/unantes/software/construction/Account.java @@ -1,6 +1,7 @@ package fr.unantes.software.construction; import java.io.InvalidClassException; +import java.time.LocalDateTime; import java.util.Collection; import java.util.Vector; import java.util.Iterator; @@ -45,13 +46,13 @@ public class Account { float newBalance = balance - amount; if (newBalance > 0){ balance = newBalance; - Operation o = new WithdrawOperation(amount, (int)System.currentTimeMillis()); + Operation o = new WithdrawOperation(amount, LocalDateTime.now()); addHistory(o); } else{ if ((Math.abs(newBalance)) <= overdraft){ balance = newBalance; - Operation o = new WithdrawOperation(amount,(int)System.currentTimeMillis()); + Operation o = new WithdrawOperation(amount,LocalDateTime.now()); addHistory(o); throw new Exception("Warning: the balance is negative: "+balance); } diff --git a/src/main/java/fr/unantes/software/construction/DepositOperation.java b/src/main/java/fr/unantes/software/construction/DepositOperation.java index a77f9405..bd2de044 100755 --- a/src/main/java/fr/unantes/software/construction/DepositOperation.java +++ b/src/main/java/fr/unantes/software/construction/DepositOperation.java @@ -1,13 +1,15 @@ package fr.unantes.software.construction; +import java.time.LocalDateTime; + public class DepositOperation extends Operation { /** * Calls the constructor of super class with the parameter amount */ - public DepositOperation(float amount, int i) { - super(amount, i); + public DepositOperation(float amount, LocalDateTime dateTime) { + super(amount, dateTime); } /** diff --git a/src/main/java/fr/unantes/software/construction/Operation.java b/src/main/java/fr/unantes/software/construction/Operation.java index 6c889331..76a241b0 100755 --- a/src/main/java/fr/unantes/software/construction/Operation.java +++ b/src/main/java/fr/unantes/software/construction/Operation.java @@ -1,9 +1,11 @@ package fr.unantes.software.construction; +import java.time.LocalDateTime; + public abstract class Operation { public Account account; - private int time; + private LocalDateTime dateTime; /** * @@ -33,9 +35,9 @@ public abstract class Operation { /** * Sets the amount with the parameter */ - public Operation(float amount, int i) { + public Operation(float amount, LocalDateTime dateTime) { this.amount = amount; - this.time = i; + this.dateTime = dateTime; } /** diff --git a/src/main/java/fr/unantes/software/construction/WithdrawOperation.java b/src/main/java/fr/unantes/software/construction/WithdrawOperation.java index e6a9a64b..d4a16f01 100755 --- a/src/main/java/fr/unantes/software/construction/WithdrawOperation.java +++ b/src/main/java/fr/unantes/software/construction/WithdrawOperation.java @@ -1,13 +1,15 @@ package fr.unantes.software.construction; +import java.time.LocalDateTime; + public class WithdrawOperation extends Operation { /** * calls the super constructor with the amount */ - public WithdrawOperation(float amount, int i) { - super(amount, i); + public WithdrawOperation(float amount, LocalDateTime dateTime) { + super(amount, dateTime); } /** -- GitLab From 74449c2db1c98c38d434a1a51f4e35d754c33e8c Mon Sep 17 00:00:00 2001 From: Gries Robin Date: Wed, 19 Feb 2020 10:50:42 +0100 Subject: [PATCH 003/120] Update source and target compiler version in maven file --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 4907c460..c8b4cae8 100644 --- a/pom.xml +++ b/pom.xml @@ -10,8 +10,8 @@ Bank - 1.4 - 1.4 + 1.8 + 1.8 UTF-8 -- GitLab From c96c9f054ad8d95ff10f6664950e6b344b5254d2 Mon Sep 17 00:00:00 2001 From: Gries Robin Date: Wed, 19 Feb 2020 11:10:47 +0100 Subject: [PATCH 004/120] Fix issue #2 : attributes visibility from'public' to 'private' --- .../software/construction/Account.java | 22 +++++++++---------- .../unantes/software/construction/Bank.java | 4 ++-- .../software/construction/Operation.java | 2 +- .../software/construction/address/Card.java | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/Account.java b/src/main/java/fr/unantes/software/construction/Account.java index cf6ef413..88227b8b 100755 --- a/src/main/java/fr/unantes/software/construction/Account.java +++ b/src/main/java/fr/unantes/software/construction/Account.java @@ -6,9 +6,17 @@ import java.util.Vector; import java.util.Iterator; public class Account { - public Vector Operation; - public String type; - + private Vector Operation; + private String type; + + /** + * + * @uml.property name="owner" + * @uml.associationEnd inverse="accounts:fr.unantes.software.construction.Client" multiplicity="(0 1)" + * + */ + private Client owner; + /** * Initializes the owner, amount, overdraft and the account number with parameters * The method also initializes the history with a new empty Vector @@ -233,14 +241,6 @@ public class Account { this.number = number; } - /** - * - * @uml.property name="owner" - * @uml.associationEnd inverse="accounts:fr.unantes.software.construction.Client" multiplicity="(0 1)" - * - */ - public Client owner; - /** * * @uml.property name="owner" diff --git a/src/main/java/fr/unantes/software/construction/Bank.java b/src/main/java/fr/unantes/software/construction/Bank.java index 8a30e6a3..ffa44114 100755 --- a/src/main/java/fr/unantes/software/construction/Bank.java +++ b/src/main/java/fr/unantes/software/construction/Bank.java @@ -7,7 +7,7 @@ import java.util.Iterator; import java.util.Vector; public class Bank { - public AddressBook ab; + private AddressBook ab; /** * this constructor initializes the attributes : accountNumbers is initially 0, @@ -171,7 +171,7 @@ public class Bank { public void closeAccount(int accountNumber) throws Exception { Account a=getAccount(accountNumber); if (a!=null){ - a.owner.removeAccounts(a); + a.getOwner().removeAccounts(a); this.removeAccounts(a); } else{ diff --git a/src/main/java/fr/unantes/software/construction/Operation.java b/src/main/java/fr/unantes/software/construction/Operation.java index 6c889331..bd4b566e 100755 --- a/src/main/java/fr/unantes/software/construction/Operation.java +++ b/src/main/java/fr/unantes/software/construction/Operation.java @@ -2,7 +2,7 @@ package fr.unantes.software.construction; public abstract class Operation { - public Account account; + private Account account; private int time; /** diff --git a/src/main/java/fr/unantes/software/construction/address/Card.java b/src/main/java/fr/unantes/software/construction/address/Card.java index 7309bf87..5dfe26f5 100755 --- a/src/main/java/fr/unantes/software/construction/address/Card.java +++ b/src/main/java/fr/unantes/software/construction/address/Card.java @@ -15,7 +15,7 @@ public abstract class Card { protected AddressList _ad = new AddressList(); protected PhoneList _tel= new PhoneList(); protected MailList _mail = new MailList(); - public Client client; + private Client client; /** * Constructeur sans parametres -- GitLab From da3c78b36ed34b638af0ad77588226135c1e2530 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Wed, 26 Feb 2020 08:37:17 +0100 Subject: [PATCH 005/120] Generated empty test for Operation subclasses --- .../construction/DepositOperationTest.java | 29 +++++++++++++++++++ .../construction/WithdrawOperationTest.java | 29 +++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 src/main/test/fr/unantes/software/construction/DepositOperationTest.java create mode 100644 src/main/test/fr/unantes/software/construction/WithdrawOperationTest.java diff --git a/src/main/test/fr/unantes/software/construction/DepositOperationTest.java b/src/main/test/fr/unantes/software/construction/DepositOperationTest.java new file mode 100644 index 00000000..a2d0d0fc --- /dev/null +++ b/src/main/test/fr/unantes/software/construction/DepositOperationTest.java @@ -0,0 +1,29 @@ +package fr.unantes.software.construction; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class DepositOperationTest { + + @BeforeEach + void setUp() { + } + + @Test + void getAmount() { + } + + @Test + void setAmount() { + } + + @Test + void set_account() { + } + + @Test + void getOperationType() { + } +} \ No newline at end of file diff --git a/src/main/test/fr/unantes/software/construction/WithdrawOperationTest.java b/src/main/test/fr/unantes/software/construction/WithdrawOperationTest.java new file mode 100644 index 00000000..ad3827ee --- /dev/null +++ b/src/main/test/fr/unantes/software/construction/WithdrawOperationTest.java @@ -0,0 +1,29 @@ +package fr.unantes.software.construction; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class WithdrawOperationTest { + + @BeforeEach + void setUp() { + } + + @Test + void getAmount() { + } + + @Test + void setAmount() { + } + + @Test + void set_account() { + } + + @Test + void getOperationType() { + } +} \ No newline at end of file -- GitLab From bcb4d0980ffabf2ae6a7bf58032bb6815b4cce48 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Wed, 26 Feb 2020 10:33:36 +0100 Subject: [PATCH 006/120] Extract History class from Account values --- .../software/construction/History.java | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 src/main/java/fr/unantes/software/construction/History.java diff --git a/src/main/java/fr/unantes/software/construction/History.java b/src/main/java/fr/unantes/software/construction/History.java new file mode 100644 index 00000000..a9a906d4 --- /dev/null +++ b/src/main/java/fr/unantes/software/construction/History.java @@ -0,0 +1,92 @@ +package fr.unantes.software.construction; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +public class History { + + /** + * @uml.property name="history" + * @uml.associationEnd inverse="compte:fr.unantes.software.construction.Operation" multiplicity="(0 -1)" + */ + private List history = new ArrayList<>(); + + /** + * @uml.property name="history" + */ + public List getHistory() { + return history; + } + + /** + * @uml.property name="history" + */ + public void setHistory(List value) { + history = value; + } + + /** + * @uml.property name="history" + */ + public Iterator historyIterator() { + return history.iterator(); + } + + /** + * @uml.property name="history" + */ + public boolean addHistory(T element) { + return history.add(element); + } + + /** + * @uml.property name="history" + */ + public boolean removeHistory(T element) { + return history.remove(element); + } + + /** + * @uml.property name="history" + */ + public boolean isHistoryEmpty() { + return history.isEmpty(); + } + + /** + * @uml.property name="history" + */ + public void clearHistory() { + history.clear(); + } + + /** + * @uml.property name="history" + */ + public boolean containsHistory(Operation element) { + return history.contains(element); + } + + /** + * @uml.property name="history" + */ + public boolean containsAllHistory(List elements) { + return history.containsAll(elements); + } + + /** + * @uml.property name="history" + */ + public int historySize() { + return history.size(); + } + + /** + * @uml.property name="history" + */ + public Operation[] historyToArray() { + return (Operation[]) history + .toArray(new Operation[history.size()]); + } +} -- GitLab From b2fc96ff5a528371a1ea1c718cccfec2407fbb03 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Fri, 28 Feb 2020 10:52:54 +0100 Subject: [PATCH 007/120] Added tests to Account class --- .../software/construction/AccountTest.java | 143 ++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 src/main/test/fr/unantes/software/construction/AccountTest.java diff --git a/src/main/test/fr/unantes/software/construction/AccountTest.java b/src/main/test/fr/unantes/software/construction/AccountTest.java new file mode 100644 index 00000000..58e87a35 --- /dev/null +++ b/src/main/test/fr/unantes/software/construction/AccountTest.java @@ -0,0 +1,143 @@ +package fr.unantes.software.construction; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.InvalidClassException; +import java.security.InvalidParameterException; +import java.time.LocalDateTime; + +import static org.junit.jupiter.api.Assertions.*; + +class AccountTest { + + private Account account, accOverdraft; + + @BeforeEach + void setUp() throws InvalidClassException { + account = new Account(new Client("John","private"),100,0,0,"private"); + accOverdraft = new Account(new Client("Meg","private"),-100,-150,1,"private"); + } + + @Test + void testCompleteHandshake() throws InvalidClassException { + Account acc2 = new Account(new Client("Marco","private"),100,0,2,"private"); + + Operation[] deposits = {new DepositOperation(50, LocalDateTime.now()), + new DepositOperation(25, LocalDateTime.now()), + new DepositOperation(25, LocalDateTime.now()), + new DepositOperation(0.99f, LocalDateTime.now())}; + + for(Operation each : deposits) { + account.addOperation(each); + } + + for(Operation each : deposits) { + acc2.addOperation(each); + } + + for(Operation each : deposits) { + assertFalse(account.getHistory().containsHistory(each)); + assertEquals(acc2, each.getAccount()); + } + } + + @Test + void testBidirectionalAdd() { + Operation[] deposits = {new DepositOperation(50, LocalDateTime.now()), + new DepositOperation(25, LocalDateTime.now()), + new DepositOperation(25, LocalDateTime.now()), + new DepositOperation(0.99f, LocalDateTime.now())}; + + for(Operation each : deposits) { + account.addOperation(each); + } + + for(Operation each : deposits) { + assertTrue(account.getHistory().containsHistory(each)); + assertEquals(account, each.getAccount()); + } + } + + @Test + void testDeposit_positiveAmount_addMoneyToAccount() { + float oldBalance = account.getBalance(); + account.deposit(50.25f); + assertTrue(account.getBalance()>oldBalance); + assertEquals(account.getBalance(),oldBalance+50.25f); + } + @Test + void testDeposit_negativeAmount_ExceptionThrown() { + float oldBalance = account.getBalance(); + assertThrows(Exception.class,()->account.deposit(-50.25f)); + assertFalse(account.getBalance() accOverdraft.withdraw(50.25f)); + assertFalse(accOverdraft.getBalance()oldBalance); + assertEquals(account. getBalance(),oldBalance); + } + + @Test + void setOverdraft_overCurrentBalance_Succeed() { + float oldOverdraft = account.getOverdraft(); + account.setOverdraft(-50); + assertNotEquals(account.getOverdraft(), oldOverdraft); + } + + @Test + void setOverdraft_belowCurrentBalance_ExceptionThrown() { + float oldOverdraft = accOverdraft.getOverdraft(); + assertThrows(Exception.class, () -> accOverdraft.setOverdraft(-50)); + assertEquals(accOverdraft.getOverdraft(), oldOverdraft); + assertFalse(accOverdraft.getOverdraft()> accOverdraft.getBalance()); + } + + @Test + void setBalance_overOverdraft_Suceed() { + account.setBalance(50); + assertEquals(account.getBalance(),50); + assertTrue(accOverdraft.getBalance() > accOverdraft.getOverdraft()); + } + @Test + void setBalance_belowOverdraft_ExceptionThrown() { + float oldBalance = accOverdraft.getBalance(); + assertThrows(Exception.class, () ->accOverdraft.setBalance(-350)); + assertEquals(accOverdraft.getBalance(),oldBalance); + assertTrue(accOverdraft.getBalance() > accOverdraft.getOverdraft()); + } + + @Test + void setOwner() throws InvalidClassException { + Client oldClient = account.getOwner(); + Client newClient = new Client("Timmy", "private"); + assertNotEquals(account.getOwner(), newClient); + assertEquals(account.getOwner(), oldClient); + + account.setOwner(newClient); + + assertNotEquals(account.getOwner(), oldClient); + assertEquals(account.getOwner(), newClient); + + } +} \ No newline at end of file -- GitLab From a7521e45569c4640f14d0b0052c0953a6ebdbf73 Mon Sep 17 00:00:00 2001 From: e092106q Date: Wed, 4 Mar 2020 12:14:00 +0100 Subject: [PATCH 008/120] Added some test for Bank class --- .../unantes/software/construction/Bank.java | 8 ++- .../software/construction/BankTest.java | 56 +++++++++++++++++++ 2 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 src/main/test/fr/unantes/software/construction/BankTest.java diff --git a/src/main/java/fr/unantes/software/construction/Bank.java b/src/main/java/fr/unantes/software/construction/Bank.java index ffa44114..351d9d1d 100755 --- a/src/main/java/fr/unantes/software/construction/Bank.java +++ b/src/main/java/fr/unantes/software/construction/Bank.java @@ -144,8 +144,10 @@ public class Bank { /** * Creates an account for the person named name. - * If no client has this name, a new client object is created and is added to the list of clients, then the account is created - * If the client exists the account is created, added to the bank's and the client's list of accounts + * If no client has this name, a new client object is created and + * is added to the list of clients, then the account is created + * If the client exists the account is created, added to the bank's + * and the client's list of accounts */ public int addAccount(String name, float amount, float overdraft, String type) { Client p = getClient(name); @@ -159,7 +161,7 @@ public class Bank { } p.addAccounts(a); this.addAccounts(a); - }; + } return accountNumbers; } diff --git a/src/main/test/fr/unantes/software/construction/BankTest.java b/src/main/test/fr/unantes/software/construction/BankTest.java new file mode 100644 index 00000000..a30c422e --- /dev/null +++ b/src/main/test/fr/unantes/software/construction/BankTest.java @@ -0,0 +1,56 @@ +package fr.unantes.software.construction; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.BeforeEach; + + +import java.io.InvalidClassException; + +import static org.junit.jupiter.api.Assertions.*; + +class BankTest { + + private Bank bank; + private Client client; + + @BeforeEach + void setup() throws InvalidClassException{ + bank = new Bank(); + Client client = new Client("ComLtd","private"); + + } + + @Test + void test_AddClients() { + bank.addClients(client); + assertFalse(bank.isClientsEmpty()); + assertTrue(bank.getClients().size() == 1); + assertTrue(bank.containsClients(client)); + } + + @Test + void test_addAccount_WhenDoesNotExist() throws InvalidClassException{ + int a = bank.addAccount("Martin", 15026.33f, 0.0f, "private" ); + + assertTrue(bank.containsClients(new Client("Martin", "private"))); + assertNotNull(bank.getAccountsOfClient("Martin")); + assertEquals(bank.getAccountsOfClient("Martin")[0].getBalance(), 15026.33f); + } + + @Test + void test_addAccount_WhenAlreadyExist() throws InvalidClassException{ + int a = bank.addAccount("Martin", 15026.33f, 0.0f, "private" ); + int b = bank.addAccount("Martin", 42.00f, 0.0f, "private" ); + + assertTrue(bank.containsClients(new Client("Martin", "private"))); + assertNotNull(bank.getAccountsOfClient("Martin")); + assertEquals(bank.getAccountsOfClient("Martin").length, 2); + assertNotEquals(bank.getAccount(a), bank.getAccount(b)); + + } + + @Test + void test_closeAccount_WhenDoesNotExist() { + + } +} \ No newline at end of file -- GitLab From 15d6200afac16218a6a365161e965793b3b407fb Mon Sep 17 00:00:00 2001 From: e092106q Date: Wed, 4 Mar 2020 12:14:00 +0100 Subject: [PATCH 009/120] Added some test for Bank class --- .../unantes/software/construction/Bank.java | 8 ++- .../software/construction/BankTest.java | 56 +++++++++++++++++++ 2 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 src/main/test/fr/unantes/software/construction/BankTest.java diff --git a/src/main/java/fr/unantes/software/construction/Bank.java b/src/main/java/fr/unantes/software/construction/Bank.java index ffa44114..351d9d1d 100755 --- a/src/main/java/fr/unantes/software/construction/Bank.java +++ b/src/main/java/fr/unantes/software/construction/Bank.java @@ -144,8 +144,10 @@ public class Bank { /** * Creates an account for the person named name. - * If no client has this name, a new client object is created and is added to the list of clients, then the account is created - * If the client exists the account is created, added to the bank's and the client's list of accounts + * If no client has this name, a new client object is created and + * is added to the list of clients, then the account is created + * If the client exists the account is created, added to the bank's + * and the client's list of accounts */ public int addAccount(String name, float amount, float overdraft, String type) { Client p = getClient(name); @@ -159,7 +161,7 @@ public class Bank { } p.addAccounts(a); this.addAccounts(a); - }; + } return accountNumbers; } diff --git a/src/main/test/fr/unantes/software/construction/BankTest.java b/src/main/test/fr/unantes/software/construction/BankTest.java new file mode 100644 index 00000000..11c4a6c9 --- /dev/null +++ b/src/main/test/fr/unantes/software/construction/BankTest.java @@ -0,0 +1,56 @@ +package fr.unantes.software.construction; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.BeforeEach; + + +import java.io.InvalidClassException; + +import static org.junit.jupiter.api.Assertions.*; + +public class BankTest { + + private Bank bank; + private Client client; + + @BeforeEach + void setup() throws InvalidClassException{ + bank = new Bank(); + Client client = new Client("ComLtd","private"); + + } + + @Test + void test_AddClients() { + bank.addClients(client); + assertFalse(bank.isClientsEmpty()); + assertTrue(bank.getClients().size() == 1); + assertTrue(bank.containsClients(client)); + } + + @Test + void test_addAccount_WhenDoesNotExist() throws InvalidClassException{ + int a = bank.addAccount("Martin", 15026.33f, 0.0f, "private" ); + + assertTrue(bank.containsClients(new Client("Martin", "private"))); + assertNotNull(bank.getAccountsOfClient("Martin")); + assertEquals(bank.getAccountsOfClient("Martin")[0].getBalance(), 15026.33f); + } + + @Test + void test_addAccount_WhenAlreadyExist() throws InvalidClassException{ + int a = bank.addAccount("Martin", 15026.33f, 0.0f, "private" ); + int b = bank.addAccount("Martin", 42.00f, 0.0f, "private" ); + + assertTrue(bank.containsClients(new Client("Martin", "private"))); + assertNotNull(bank.getAccountsOfClient("Martin")); + assertEquals(bank.getAccountsOfClient("Martin").length, 2); + assertNotEquals(bank.getAccount(a), bank.getAccount(b)); + + } + + @Test + void test_closeAccount_WhenDoesNotExist() { + + } +} \ No newline at end of file -- GitLab From efed659ce2cb92caf1c6e54f8486c30f4a02dcce Mon Sep 17 00:00:00 2001 From: Gries Robin Date: Mon, 9 Mar 2020 13:59:01 +0100 Subject: [PATCH 010/120] Impl. OneToOneReference, tests not implemented yet --- src/main/java/OneToOneReference.java | 46 ++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/main/java/OneToOneReference.java diff --git a/src/main/java/OneToOneReference.java b/src/main/java/OneToOneReference.java new file mode 100644 index 00000000..95620e5d --- /dev/null +++ b/src/main/java/OneToOneReference.java @@ -0,0 +1,46 @@ +public abstract class OneToOneReference { + + private T target; + private final C container; + + + public OneToOneReference(C c) { + this.container = c; + } + + public T get(){ + return target; + } + + + public boolean isSet(){ + return target != null; + } + + public void basicUnset(){ + target = null; + } + + public void basicSet(T newTarget){ + target = newTarget; + } + + public void unset(){ + if (isSet()) return; + else { + this.oppositeFor(target).unset(); + this.basicUnset(); + oppositeFor(target).basicSet(container); + } + } + + public void set(T newTarget){ + this.unset(); + oppositeFor(target).unset(); + this.basicUnset(); + //oppositeFor(target).basicUnset(container); + oppositeFor(target).basicUnset(); + } + + public abstract OneToOneReference oppositeFor(T target); +} -- GitLab From 4aa69250f8dc1ba33e4e3075d61e3f37c980aef8 Mon Sep 17 00:00:00 2001 From: Gries Robin Date: Mon, 9 Mar 2020 22:21:33 +0100 Subject: [PATCH 011/120] Impl half abstract class for 1<->N references --- .../construction/ref/ManyToOneReference.java | 56 +++++++++++++++++++ .../construction/ref/OneToManyReference.java | 37 ++++++++++++ .../construction/ref}/OneToOneReference.java | 8 +-- 3 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 src/main/java/fr/unantes/software/construction/ref/ManyToOneReference.java create mode 100644 src/main/java/fr/unantes/software/construction/ref/OneToManyReference.java rename src/main/java/{ => fr/unantes/software/construction/ref}/OneToOneReference.java (90%) diff --git a/src/main/java/fr/unantes/software/construction/ref/ManyToOneReference.java b/src/main/java/fr/unantes/software/construction/ref/ManyToOneReference.java new file mode 100644 index 00000000..5656fb8f --- /dev/null +++ b/src/main/java/fr/unantes/software/construction/ref/ManyToOneReference.java @@ -0,0 +1,56 @@ +package fr.unantes.software.construction.ref; + +import java.util.ArrayList; +import java.util.List; +import org.apache.commons.lang3.Validate; + +public abstract class ManyToOneReference { + + private final C container; + private List targets = new ArrayList<>(); + + + public ManyToOneReference(C c){ + this.container = c; + } + + public C getContainer(){ return container; } + + public List getTargets(){ return targets; } + + public boolean isEmpty(){ return targets.isEmpty(); } + + public boolean contains(T elt){ + Validate.notEmpty(targets); + return targets.contains(elt); + } + + public void basicRemove(T elt){ + targets.remove(elt); + } + + public void basicAdd(T newTarget){ + targets.add(newTarget); + } + + public void remove(T elt){ + if (isEmpty()) return; + else { + this.oppositeFor(elt).unset(); + this.basicRemove(elt); + oppositeFor(elt).basicSet(container); + //TODO check if these last 2 line should be swapped + } + } + + public void add(T newElt){ + if (oppositeFor(newElt).isSet()) { + oppositeFor(newElt).unset(); + } + oppositeFor(newElt).basicSet(container); + this.basicAdd(newElt); + } + + public abstract OneToManyReference oppositeFor(T target); + +} diff --git a/src/main/java/fr/unantes/software/construction/ref/OneToManyReference.java b/src/main/java/fr/unantes/software/construction/ref/OneToManyReference.java new file mode 100644 index 00000000..098aefc3 --- /dev/null +++ b/src/main/java/fr/unantes/software/construction/ref/OneToManyReference.java @@ -0,0 +1,37 @@ +package fr.unantes.software.construction.ref; + +import org.apache.commons.lang3.Validate; + +public abstract class OneToManyReference { + + private final C container; + private T target; + + public OneToManyReference(C c) { + this.container = c; + } + + public T getTarget() { return target; } + + public C getContainer() { + Validate.notNull(container); + return container; + } + + + public boolean isSet() { return target != null; } + + public void basicUnset() { target = null; } + + public void basicSet(T newTarget) { + Validate.notNull(container); + target = newTarget; + } + + //TODO + public void unset() {} + public void set(C c) {} + + + public abstract ManyToOneReference oppositeFor(T target); +} diff --git a/src/main/java/OneToOneReference.java b/src/main/java/fr/unantes/software/construction/ref/OneToOneReference.java similarity index 90% rename from src/main/java/OneToOneReference.java rename to src/main/java/fr/unantes/software/construction/ref/OneToOneReference.java index 95620e5d..2cfbae23 100644 --- a/src/main/java/OneToOneReference.java +++ b/src/main/java/fr/unantes/software/construction/ref/OneToOneReference.java @@ -1,7 +1,9 @@ +package fr.unantes.software.construction.ref; + public abstract class OneToOneReference { - private T target; private final C container; + private T target; public OneToOneReference(C c) { @@ -12,7 +14,6 @@ public abstract class OneToOneReference { return target; } - public boolean isSet(){ return target != null; } @@ -37,8 +38,7 @@ public abstract class OneToOneReference { public void set(T newTarget){ this.unset(); oppositeFor(target).unset(); - this.basicUnset(); - //oppositeFor(target).basicUnset(container); + this.basicSet(newTarget); oppositeFor(target).basicUnset(); } -- GitLab From a7de48da6d0ec71e3691a9b82271164e6e9384b2 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Tue, 10 Mar 2020 17:16:00 +0100 Subject: [PATCH 012/120] Moved historyToArray --- .../software/construction/Account.java | 445 +++++++----------- .../software/construction/History.java | 7 - 2 files changed, 170 insertions(+), 282 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/Account.java b/src/main/java/fr/unantes/software/construction/Account.java index 96fd9610..af01bd7a 100755 --- a/src/main/java/fr/unantes/software/construction/Account.java +++ b/src/main/java/fr/unantes/software/construction/Account.java @@ -1,275 +1,170 @@ -package fr.unantes.software.construction; - -import java.io.InvalidClassException; -import java.time.LocalDateTime; -import java.util.Collection; -import java.util.Vector; -import java.util.Iterator; - -public class Account { - public Vector Operation; - public String type; - - /** - * Initializes the owner, amount, overdraft and the account number with parameters - * The method also initializes the history with a new empty Vector - */ - public Account(Client p, float amount, float overdraft, int n, String type) throws InvalidClassException { - this.owner = p; - this.balance = amount; - this.history = new Vector(); - this.number = n; - Operation = new Vector(); - this.type = type; - if (!type.equals("private") && !type.equals("company")) { - throw new InvalidClassException("Invalid type supplied. An account can only be private or company"); - } - } - - /** - * Adds the amount to the current balance - * Adds this operation in the history - */ - public void deposit(float amount) { - balance = balance + amount; - //Operation o = new DepositOperation(amount); - } - - /** - * If the amount is greater or equal to the balance, withdraws the amount - * If the amount is lower than the balance and greater than the overdraft, - * withdraws the amount and throws an exception to warn that the balance is negative - * If the amount is lower than the overdraft, - *the amount is not withdrawn and exception is thrown to indicate that there is not enough credit. - */ - public void withdraw(float amount) throws Exception { - float newBalance = balance - amount; - if (newBalance > 0){ - balance = newBalance; - Operation o = new WithdrawOperation(amount, LocalDateTime.now()); - addHistory(o); - } - else{ - if ((Math.abs(newBalance)) <= overdraft){ - balance = newBalance; - Operation o = new WithdrawOperation(amount,LocalDateTime.now()); - addHistory(o); - throw new Exception("Warning: the balance is negative: "+balance); - } - else{ - throw new Exception("Could not proceed withdrawal. Not enough credit."); - } - } - } - - /** - * - * This attribute memorizes the current balance of the account - * - */ - private float balance; - - /** - * - * this is the maximum overdraft authorized for this account - * - */ - private float overdraft; - - /** - * - * @uml.property name="history" - * @uml.associationEnd inverse="compte:fr.unantes.software.construction.Operation" multiplicity="(0 -1)" - * - */ - private Collection history; - - /** - * - * @uml.property name="history" - */ - public java.util.Collection getHistory() { - return history; - } - - /** - * - * @uml.property name="history" - */ - public void setHistory(java.util.Collection value) { - history = value; - } - - /** - * - * @uml.property name="history" - */ - public Iterator historyIterator() { - return history.iterator(); - } - - /** - * - * @uml.property name="history" - */ - public boolean addHistory(Operation element) { - return history.add(element); - } - - /** - * - * @uml.property name="history" - */ - public boolean removeHistory(Operation element) { - return history.remove(element); - } - - /** - * - * @uml.property name="history" - */ - public boolean isHistoryEmpty() { - return history.isEmpty(); - } - - /** - * - * @uml.property name="history" - */ - public void clearHistory() { - history.clear(); - } - - /** - * - * @uml.property name="history" - */ - public boolean containsHistory(Operation element) { - return history.contains(element); - } - - /** - * - * @uml.property name="history" - */ - public boolean containsAllHistory(Collection elements) { - return history.containsAll(elements); - } - - /** - * - * @uml.property name="history" - */ - public int historySize() { - return history.size(); - } - - /** - * - * @uml.property name="history" - */ - public Operation[] historyToArray() { - return (Operation[]) history - .toArray(new Operation[history.size()]); - } - - /** - * - * @uml.property name="overdraft" - * - */ - public float getOverdraft() { - return overdraft; - } - - /** - * - * @uml.property name="overdraft" - * - */ - public void setOverdraft(float overdraft) { - this.overdraft = overdraft; - } - - /** - * - * @uml.property name="balance" - * - */ - public float getBalance() { - return balance; - } - - /** - * - * @uml.property name="balance" - * - */ - public void setBalance(float balance) { - this.balance = balance; - } - - /** - * - * this is the number of the account - * - */ - private int number; - - /** - * - * @uml.property name="number" - * - */ - public int getNumber() { - return number; - } - - /** - * - * @uml.property name="number" - * - */ - public void setNumber(int number) { - this.number = number; - } - - /** - * - * @uml.property name="owner" - * @uml.associationEnd inverse="accounts:fr.unantes.software.construction.Client" multiplicity="(0 1)" - * - */ - public Client owner; - - /** - * - * @uml.property name="owner" - * - */ - public Client getOwner() { - return owner; - } - - /** - * - * @uml.property name="owner" - * - */ - public void setOwner(Client owner) { - if (owner.role == "private" & this.type != "private") return; - if (owner.role == "company" & this.type != "company") return; - this.owner = owner; - } - - public void addOperation(Operation o) { - Operation.add(o); - try { - o.set_account((Account)this.clone()); - } catch (CloneNotSupportedException e) { - e.printStackTrace(); - } - } - -} - +package fr.unantes.software.construction; + +import java.io.InvalidClassException; +import java.time.LocalDateTime; +import java.util.Vector; + +public class Account { + private final Integer id; + public Vector operation; + public String type; + private float balance; + private float overdraft; + private History history = new History<>(); + + /** + * Initializes the owner, amount, overdraft and the account id with parameters + * The method also initializes the history with a new empty Vector + */ + public Account(Client p, float amount, float overdraft, Integer id, String type) throws InvalidClassException { + this.owner = p; + this.balance = amount; + this.id = id; + this.overdraft = overdraft; + operation = new Vector(); + this.type = type; + if (!type.equals("private") && !type.equals("company")) { + throw new InvalidClassException("Invalid type supplied. An account can only be private or company"); + } + } + + /** + * Adds the amount to the current balance + * Adds this operation in the history + */ + public void deposit(float amount) { + balance = balance + amount; + //Operation o = new DepositOperation(amount); + } + + /** + * If the amount is greater or equal to the balance, withdraws the amount + * If the amount is lower than the balance and greater than the overdraft, + * withdraws the amount and throws an exception to warn that the balance is negative + * If the amount is lower than the overdraft, + *the amount is not withdrawn and exception is thrown to indicate that there is not enough credit. + */ + public void withdraw(float amount) throws Exception { + float newBalance = balance - amount; + if (newBalance > 0){ + balance = newBalance; + Operation o = new WithdrawOperation(amount, LocalDateTime.now()); + history.addHistory(o); + } + else{ + if ((Math.abs(newBalance)) <= overdraft){ + balance = newBalance; + Operation o = new WithdrawOperation(amount,LocalDateTime.now()); + history.addHistory(o); + throw new Exception("Warning: the balance is negative: "+balance); + } + else{ + throw new IllegalArgumentException("Could not proceed withdrawal. Not enough credit."); + } + } + } + + /** + * + * @uml.property name="overdraft" + * + */ + public float getOverdraft() { + return overdraft; + } + + /** + * + * @uml.property name="overdraft" + * + */ + public void setOverdraft(float overdraft) { + this.overdraft = overdraft; + } + + /** + * + * @uml.property name="balance" + * + */ + public float getBalance() { + return balance; + } + + /** + * + * @uml.property name="balance" + * + */ + public void setBalance(float balance) { + this.balance = balance; + } + + /** + * + * @uml.property name="id" + * + */ + public Integer getId() { + return id; + } + + /** + * + * @uml.property name="owner" + * @uml.associationEnd inverse="accounts:fr.unantes.software.construction.Client" multiplicity="(0 1)" + * + */ + public Client owner; + + /** + * + * @uml.property name="owner" + * + */ + public Client getOwner() { + return owner; + } + + /** + * + * @uml.property name="owner" + * + */ + public void setOwner(Client owner) { + if (owner.role.equals("private") && !this.type.equals("private")) return; + if (owner.role.equals("company") && !this.type.equals("company")) return; + this.owner = owner; + } + + public void addOperation(Operation o) { + operation.add(o); + try { + o.setAccount((Account)this.clone()); + } catch (CloneNotSupportedException e) { + e.printStackTrace(); + } + } + + /** + * @uml.property name="history" + */ + public History getHistory() { + return history; + } + + /** + * @uml.property name="history" + */ + public void addHistory(Operation value) { + history.addHistory(value); + } + /** + * @uml.property name="history" + */ + public Operation[] historyToArray() { + return (Operation[]) history.getHistory().toArray(new Operation[history.getHistory().size()]); + } + +} + diff --git a/src/main/java/fr/unantes/software/construction/History.java b/src/main/java/fr/unantes/software/construction/History.java index a9a906d4..8e681b25 100644 --- a/src/main/java/fr/unantes/software/construction/History.java +++ b/src/main/java/fr/unantes/software/construction/History.java @@ -82,11 +82,4 @@ public class History { return history.size(); } - /** - * @uml.property name="history" - */ - public Operation[] historyToArray() { - return (Operation[]) history - .toArray(new Operation[history.size()]); - } } -- GitLab From 21871d69872f96f6834c2617535bb8c55b5292b3 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Tue, 10 Mar 2020 21:18:07 +0100 Subject: [PATCH 013/120] Added deposit and withdraw methods --- .../construction/DepositOperation.java | 53 +++++++++++-------- .../construction/WithdrawOperation.java | 47 ++++++++-------- 2 files changed, 56 insertions(+), 44 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/DepositOperation.java b/src/main/java/fr/unantes/software/construction/DepositOperation.java index bd2de044..9322a038 100755 --- a/src/main/java/fr/unantes/software/construction/DepositOperation.java +++ b/src/main/java/fr/unantes/software/construction/DepositOperation.java @@ -1,22 +1,31 @@ - -package fr.unantes.software.construction; - -import java.time.LocalDateTime; - -public class DepositOperation extends Operation { - - /** - * Calls the constructor of super class with the parameter amount - */ - public DepositOperation(float amount, LocalDateTime dateTime) { - super(amount, dateTime); - } - - /** - * returns "Deposit" - */ - public String getOperationType() { - return "Deposit"; - } - -} + +package fr.unantes.software.construction; +import java.time.LocalDateTime; + +public class DepositOperation extends Operation { + + /** + * Calls the constructor of super class with the parameter amount + */ + public DepositOperation(float amount, LocalDateTime dateTime) { + super(amount, dateTime); + } + + /** + * returns "Deposit" + */ + public String getOperationType() { + return "Deposit"; + } + + /** + * + * @uml.property name="amount" + * + */ + + public void deposit(float amount) { + //TODO + } + +} diff --git a/src/main/java/fr/unantes/software/construction/WithdrawOperation.java b/src/main/java/fr/unantes/software/construction/WithdrawOperation.java index d4a16f01..f9a707c0 100755 --- a/src/main/java/fr/unantes/software/construction/WithdrawOperation.java +++ b/src/main/java/fr/unantes/software/construction/WithdrawOperation.java @@ -1,22 +1,25 @@ - -package fr.unantes.software.construction; - -import java.time.LocalDateTime; - -public class WithdrawOperation extends Operation { - - /** - * calls the super constructor with the amount - */ - public WithdrawOperation(float amount, LocalDateTime dateTime) { - super(amount, dateTime); - } - - /** - * returns "Withdraw" - */ - public String getOperationType() { - return "Withdraw"; - } - -} + +package fr.unantes.software.construction; + +import java.time.LocalDateTime; + +public class WithdrawOperation extends Operation { + + /** + * calls the super constructor with the amount + */ + public WithdrawOperation(float amount, LocalDateTime dateTime) { + super(amount, dateTime); + } + + /** + * returns "Withdraw" + */ + public String getOperationType() { + return "Withdraw"; + } + + public void withdraw(float amount) { + //TODO + } +} -- GitLab From 35bf5720db0ea16529e77142a2e0d9739566f921 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Tue, 10 Mar 2020 21:20:48 +0100 Subject: [PATCH 014/120] Created references clases for Account and Operations --- .../software/construction/Account.java | 6 +- .../software/construction/Operation.java | 95 +++++++++---------- .../references/ManyToOneReference.java | 37 ++++++++ .../references/OneToManyReference.java | 32 +++++++ 4 files changed, 116 insertions(+), 54 deletions(-) create mode 100644 src/main/java/fr/unantes/software/construction/references/ManyToOneReference.java create mode 100644 src/main/java/fr/unantes/software/construction/references/OneToManyReference.java diff --git a/src/main/java/fr/unantes/software/construction/Account.java b/src/main/java/fr/unantes/software/construction/Account.java index af01bd7a..4eacafd1 100755 --- a/src/main/java/fr/unantes/software/construction/Account.java +++ b/src/main/java/fr/unantes/software/construction/Account.java @@ -1,12 +1,15 @@ package fr.unantes.software.construction; +import fr.unantes.software.construction.references.ManyToOneReference; +import fr.unantes.software.construction.references.OneToManyReference; + import java.io.InvalidClassException; import java.time.LocalDateTime; import java.util.Vector; public class Account { private final Integer id; - public Vector operation; + public ManyToOneReference operation; public String type; private float balance; private float overdraft; @@ -21,7 +24,6 @@ public class Account { this.balance = amount; this.id = id; this.overdraft = overdraft; - operation = new Vector(); this.type = type; if (!type.equals("private") && !type.equals("company")) { throw new InvalidClassException("Invalid type supplied. An account can only be private or company"); diff --git a/src/main/java/fr/unantes/software/construction/Operation.java b/src/main/java/fr/unantes/software/construction/Operation.java index 76a241b0..172351ac 100755 --- a/src/main/java/fr/unantes/software/construction/Operation.java +++ b/src/main/java/fr/unantes/software/construction/Operation.java @@ -1,52 +1,43 @@ -package fr.unantes.software.construction; - -import java.time.LocalDateTime; - -public abstract class Operation { - - public Account account; - private LocalDateTime dateTime; - - /** - * - * This attribute memorizes the amount involved in the operation - * - */ - private float amount; - - /** - * - * @uml.property name="amount" - * - */ - public float getAmount() { - return amount; - } - - /** - * - * @uml.property name="amount" - * - */ - public void setAmount(float amount) { - this.amount = amount; - } - - /** - * Sets the amount with the parameter - */ - public Operation(float amount, LocalDateTime dateTime) { - this.amount = amount; - this.dateTime = dateTime; - } - - /** - * Returns the type of the operation as a String. - */ - public abstract String getOperationType(); - - public void set_account(Account xyz) { - account = xyz; - } - -} +package fr.unantes.software.construction; + +import fr.unantes.software.construction.references.OneToManyReference; + +import java.time.LocalDateTime; + +public abstract class Operation { + + public OneToManyReference account; + private LocalDateTime dateTime; + private float amount; // This attribute memorizes the amount involved in the operation + + /** + * Sets the amount with the parameter + */ + public Operation(float amount, LocalDateTime dateTime) { + this.amount = amount; + this.dateTime = dateTime; + } + /** + * + * @uml.property name="amount" + * + */ + public float getAmount() { + return amount; + } + + + public void setAccount(Account value){ + this.account.set(value); + } + + public Account getAccount(){ + return this.account.get(); + } + + /** + * Returns the type of the operation as a String. + */ + public abstract String getOperationType(); + +} diff --git a/src/main/java/fr/unantes/software/construction/references/ManyToOneReference.java b/src/main/java/fr/unantes/software/construction/references/ManyToOneReference.java new file mode 100644 index 00000000..7764beab --- /dev/null +++ b/src/main/java/fr/unantes/software/construction/references/ManyToOneReference.java @@ -0,0 +1,37 @@ +package fr.unantes.software.construction.references; + +import java.util.ArrayList; +import java.util.List; + +public abstract class ManyToOneReference { + final private List targets = new ArrayList<>(); + final private C container; + + public ManyToOneReference(C container) { + this.container = container; + } + + public void add(T value){ + //TODO + } + + public void remove(T value){ + //TODO + } + + public boolean contains(T value){ + //TODO + return false; + } + + public void basicRemove(T value){ + this.targets.remove(value); + } + + public void basicAdd(T value){ + this.targets.add(value); + } + + public abstract OneToManyReference oppositeFor(T target); + +} diff --git a/src/main/java/fr/unantes/software/construction/references/OneToManyReference.java b/src/main/java/fr/unantes/software/construction/references/OneToManyReference.java new file mode 100644 index 00000000..06e0d64d --- /dev/null +++ b/src/main/java/fr/unantes/software/construction/references/OneToManyReference.java @@ -0,0 +1,32 @@ +package fr.unantes.software.construction.references; + +public abstract class OneToManyReference { + private T target; + private C container; + + public boolean isSet(){ + //TODO + return false; + } + + public T get(){ + return this.target; + } + + public void set(T value){ + //TODO + + } + + public void unset(){ + //TODO + } + + public void basicSet(T value){ + this.target = value; + } + + public void basicUnset(T value){ + this.target = null; + } +} -- GitLab From 8c064915eeb4e14cde9a28f6f7c8f1227875075f Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Tue, 10 Mar 2020 21:22:37 +0100 Subject: [PATCH 015/120] updated Bank and TextUI classes to work with Account --- .../unantes/software/construction/Bank.java | 720 +++++++++--------- .../construction/ui/TextualUserInterface.java | 614 +++++++-------- 2 files changed, 667 insertions(+), 667 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/Bank.java b/src/main/java/fr/unantes/software/construction/Bank.java index 8a30e6a3..c9272bb2 100755 --- a/src/main/java/fr/unantes/software/construction/Bank.java +++ b/src/main/java/fr/unantes/software/construction/Bank.java @@ -1,360 +1,360 @@ -package fr.unantes.software.construction; - -import fr.unantes.software.construction.address.AddressBook; - -import java.io.InvalidClassException; -import java.util.Iterator; -import java.util.Vector; - -public class Bank { - public AddressBook ab; - - /** - * this constructor initializes the attributes : accountNumbers is initially 0, - * accounts and clients and initialized with new empty Vectors - */ - public Bank() { - this.accountNumbers = 0; - this.accounts = new Vector(); - ab = new AddressBook(); - } - - /** - * - * this is a counter that is incremented each time a new account is created - * - */ - private int accountNumbers; - - /** - * - * @uml.property name="accountNumbers" - * - */ - public int getAccountNumbers() { - return accountNumbers; - } - - /** - * - * @uml.property name="accountNumbers" - * - */ - public void setAccountNumbers(int accountNumbers) { - this.accountNumbers = accountNumbers; - } - - /** - * - * @uml.property name="clients" - * @uml.associationEnd inverse="bank:fr.unantes.software.construction.Client" multiplicity="(0 -1)" - * - */ - private Vector clients; - - /** - * - * @uml.property name="clients" - */ - public Vector getClients() { - return clients; - } - - /** - * - * @uml.property name="clients" - */ - public void setClients(Vector value) { - clients = value; - } - - /** - * - * @uml.property name="clients" - * @return - */ - public Iterator clientsIterator() { - return clients.iterator(); - } - - /** - * - * @uml.property name="clients" - */ - public boolean addClients(Client element) { - return clients.add(element); - } - - /** - * - * @uml.property name="clients" - */ - public boolean removeClients(Client element) { - return clients.remove(element); - } - - /** - * - * @uml.property name="clients" - */ - public boolean isClientsEmpty() { - return clients.isEmpty(); - } - - /** - * - * @uml.property name="clients" - */ - public void clearClients() { - clients.clear(); - } - - /** - * - * @uml.property name="clients" - */ - public boolean containsClients(Client element) { - return clients.contains(element); - } - - /** - * - * @uml.property name="clients" - */ - public boolean containsAllClients(Vector elements) { - return clients.containsAll(elements); - } - - /** - * - * @uml.property name="clients" - */ - public int clientsSize() { - return clients.size(); - } - - /** - * - * @uml.property name="clients" - */ - public Client[] clientsToArray() { - return (Client[]) clients - .toArray(new Client[clients.size()]); - } - - /** - * Creates an account for the person named name. - * If no client has this name, a new client object is created and is added to the list of clients, then the account is created - * If the client exists the account is created, added to the bank's and the client's list of accounts - */ - public int addAccount(String name, float amount, float overdraft, String type) { - Client p = getClient(name); - //if a client named name already exists in the bank's set of clients - if (p!=null){ - Account a = null; - try { - a = new Account(p, amount, overdraft, accountNumbers, type); - } catch (InvalidClassException e) { - e.printStackTrace(); - } - p.addAccounts(a); - this.addAccounts(a); - }; - return accountNumbers; - } - - /** - * Closes the account number accountNumber. - * If the account exists, it is removed form the bank's list of accounts and from the owner's list of accounts. - * If the account does not exist, an Exception is thrown. - */ - public void closeAccount(int accountNumber) throws Exception { - Account a=getAccount(accountNumber); - if (a!=null){ - a.owner.removeAccounts(a); - this.removeAccounts(a); - } - else{ - Exception error = new Exception("The account number "+accountNumber+" does not exist. Impossible to close this account"); - throw error; - } - } - - /** - * Looks for a person named name in the set of clients. - * Returns the Client object corresponding to the client if it exists - * Returns null if there is no client named name - */ - public Client getClient(String name) { - Iterator it = this.clientsIterator(); - while (it.hasNext()){ - Client p = (Client)it.next(); - if(p.getName()==name){ - return p; - } - - } - return null; - } - - /** - * Looks for an account with the number accountNumber in the set of accounts - * Returns the account if it exists - * Returns null if no account has the number accountNumber - * The assumption is that there cannot be several accounts with the same number - */ - public Account getAccount(int accountNumber) { - Iterator it = this.accountsIterator(); - while (it.hasNext()){ - Account a = (Account)it.next(); - if(a.getNumber()==accountNumber){ - return a; - } - - } - return null; - } - - /** - * Deposits the amount on the account number accountNumber - * Throws an exception if there is no account number accountNumber - */ - public void deposit(int accountNumber, float amount) throws Exception { - Account a = getAccount(accountNumber); - if (a!=null){ - a.deposit(amount); - } - else{ - Exception error = new Exception("The account number "+accountNumber+" does not exist. Impossible to deposit"); - throw error; - } - } - - /** - * Withdraws the amount from the account number accountNumber - * Throws an exception if there is no account number accountNumber - */ - public void withdraw(int accountNumber, float amount) throws Exception { - Account a = getAccount(accountNumber); - if (a!=null){ - a.withdraw(amount); - } - else{ - Exception error = new Exception("The account number "+accountNumber+" does not exist. Impossible to withdraw"); - throw error; - } - } - - /** - * Returns the collection of accounts of the client named name - * If there is no client named name, the method returns null - */ - public Account[] getAccountsOfClient(String name) { - Client client = getClient(name); - if (client!=null){ - return client.accountsToArray(); - } - else{ - return null; - } - } - - /** - * - * @uml.property name="accounts" - * @uml.associationEnd aggregation="composite" inverse="bank:fr.unantes.software.construction.Account" multiplicity="(0 -1)" - * - */ - private Vector accounts; - - /** - * - * @uml.property name="accounts" - */ - public Vector getAccounts() { - return accounts; - } - - /** - * - * @uml.property name="accounts" - */ - public void setAccounts(Vector value) { - accounts = value; - } - - /** - * - * @uml.property name="accounts" - */ - public Iterator accountsIterator() { - return accounts.iterator(); - } - - /** - * - * @uml.property name="accounts" - */ - public boolean addAccounts(Account element) { - return accounts.add(element); - } - - /** - * - * @uml.property name="accounts" - */ - public boolean removeAccounts(Account element) { - return accounts.remove(element); - } - - /** - * - * @uml.property name="accounts" - */ - public boolean isAccountsEmpty() { - return accounts.isEmpty(); - } - - /** - * - * @uml.property name="accounts" - */ - public void clearAccounts() { - accounts.clear(); - } - - /** - * - * @uml.property name="accounts" - */ - public boolean containsAccounts(Account element) { - return accounts.contains(element); - } - - /** - * - * @uml.property name="accounts" - */ - public boolean containsAllAccounts(Vector elements) { - return accounts.containsAll(elements); - } - - /** - * - * @uml.property name="accounts" - */ - public int accountsSize() { - return accounts.size(); - } - - /** - * - * @uml.property name="accounts" - */ - public Account[] accountsToArray() { - return (Account[]) accounts - .toArray(new Account[accounts.size()]); - } - -} - +package fr.unantes.software.construction; + +import fr.unantes.software.construction.address.AddressBook; + +import java.io.InvalidClassException; +import java.util.Iterator; +import java.util.Vector; + +public class Bank { + public AddressBook ab; + + /** + * this constructor initializes the attributes : accountNumbers is initially 0, + * accounts and clients and initialized with new empty Vectors + */ + public Bank() { + this.accountNumbers = 0; + this.accounts = new Vector(); + ab = new AddressBook(); + } + + /** + * + * this is a counter that is incremented each time a new account is created + * + */ + private int accountNumbers; + + /** + * + * @uml.property name="accountNumbers" + * + */ + public int getAccountNumbers() { + return accountNumbers; + } + + /** + * + * @uml.property name="accountNumbers" + * + */ + public void setAccountNumbers(int accountNumbers) { + this.accountNumbers = accountNumbers; + } + + /** + * + * @uml.property name="clients" + * @uml.associationEnd inverse="bank:fr.unantes.software.construction.Client" multiplicity="(0 -1)" + * + */ + private Vector clients; + + /** + * + * @uml.property name="clients" + */ + public Vector getClients() { + return clients; + } + + /** + * + * @uml.property name="clients" + */ + public void setClients(Vector value) { + clients = value; + } + + /** + * + * @uml.property name="clients" + * @return + */ + public Iterator clientsIterator() { + return clients.iterator(); + } + + /** + * + * @uml.property name="clients" + */ + public boolean addClients(Client element) { + return clients.add(element); + } + + /** + * + * @uml.property name="clients" + */ + public boolean removeClients(Client element) { + return clients.remove(element); + } + + /** + * + * @uml.property name="clients" + */ + public boolean isClientsEmpty() { + return clients.isEmpty(); + } + + /** + * + * @uml.property name="clients" + */ + public void clearClients() { + clients.clear(); + } + + /** + * + * @uml.property name="clients" + */ + public boolean containsClients(Client element) { + return clients.contains(element); + } + + /** + * + * @uml.property name="clients" + */ + public boolean containsAllClients(Vector elements) { + return clients.containsAll(elements); + } + + /** + * + * @uml.property name="clients" + */ + public int clientsSize() { + return clients.size(); + } + + /** + * + * @uml.property name="clients" + */ + public Client[] clientsToArray() { + return (Client[]) clients + .toArray(new Client[clients.size()]); + } + + /** + * Creates an account for the person named name. + * If no client has this name, a new client object is created and is added to the list of clients, then the account is created + * If the client exists the account is created, added to the bank's and the client's list of accounts + */ + public int addAccount(String name, float amount, float overdraft, String type) { + Client p = getClient(name); + //if a client named name already exists in the bank's set of clients + if (p!=null){ + Account a = null; + try { + a = new Account(p, amount, overdraft, accountNumbers, type); + } catch (InvalidClassException e) { + e.printStackTrace(); + } + p.addAccounts(a); + this.addAccounts(a); + }; + return accountNumbers; + } + + /** + * Closes the account number accountNumber. + * If the account exists, it is removed form the bank's list of accounts and from the owner's list of accounts. + * If the account does not exist, an Exception is thrown. + */ + public void closeAccount(int accountNumber) throws Exception { + Account a=getAccount(accountNumber); + if (a!=null){ + a.owner.removeAccounts(a); + this.removeAccounts(a); + } + else{ + Exception error = new Exception("The account number "+accountNumber+" does not exist. Impossible to close this account"); + throw error; + } + } + + /** + * Looks for a person named name in the set of clients. + * Returns the Client object corresponding to the client if it exists + * Returns null if there is no client named name + */ + public Client getClient(String name) { + Iterator it = this.clientsIterator(); + while (it.hasNext()){ + Client p = (Client)it.next(); + if(p.getName()==name){ + return p; + } + + } + return null; + } + + /** + * Looks for an account with the number accountNumber in the set of accounts + * Returns the account if it exists + * Returns null if no account has the number accountNumber + * The assumption is that there cannot be several accounts with the same number + */ + public Account getAccount(int accountNumber) { + Iterator it = this.accountsIterator(); + while (it.hasNext()){ + Account a = (Account)it.next(); + if(a.getId()==accountNumber){ + return a; + } + + } + return null; + } + + /** + * Deposits the amount on the account number accountNumber + * Throws an exception if there is no account number accountNumber + */ + public void deposit(int accountNumber, float amount) throws Exception { + Account a = getAccount(accountNumber); + if (a!=null){ + a.deposit(amount); + } + else{ + Exception error = new Exception("The account number "+accountNumber+" does not exist. Impossible to deposit"); + throw error; + } + } + + /** + * Withdraws the amount from the account number accountNumber + * Throws an exception if there is no account number accountNumber + */ + public void withdraw(int accountNumber, float amount) throws Exception { + Account a = getAccount(accountNumber); + if (a!=null){ + a.withdraw(amount); + } + else{ + Exception error = new Exception("The account number "+accountNumber+" does not exist. Impossible to withdraw"); + throw error; + } + } + + /** + * Returns the collection of accounts of the client named name + * If there is no client named name, the method returns null + */ + public Account[] getAccountsOfClient(String name) { + Client client = getClient(name); + if (client!=null){ + return client.accountsToArray(); + } + else{ + return null; + } + } + + /** + * + * @uml.property name="accounts" + * @uml.associationEnd aggregation="composite" inverse="bank:fr.unantes.software.construction.Account" multiplicity="(0 -1)" + * + */ + private Vector accounts; + + /** + * + * @uml.property name="accounts" + */ + public Vector getAccounts() { + return accounts; + } + + /** + * + * @uml.property name="accounts" + */ + public void setAccounts(Vector value) { + accounts = value; + } + + /** + * + * @uml.property name="accounts" + */ + public Iterator accountsIterator() { + return accounts.iterator(); + } + + /** + * + * @uml.property name="accounts" + */ + public boolean addAccounts(Account element) { + return accounts.add(element); + } + + /** + * + * @uml.property name="accounts" + */ + public boolean removeAccounts(Account element) { + return accounts.remove(element); + } + + /** + * + * @uml.property name="accounts" + */ + public boolean isAccountsEmpty() { + return accounts.isEmpty(); + } + + /** + * + * @uml.property name="accounts" + */ + public void clearAccounts() { + accounts.clear(); + } + + /** + * + * @uml.property name="accounts" + */ + public boolean containsAccounts(Account element) { + return accounts.contains(element); + } + + /** + * + * @uml.property name="accounts" + */ + public boolean containsAllAccounts(Vector elements) { + return accounts.containsAll(elements); + } + + /** + * + * @uml.property name="accounts" + */ + public int accountsSize() { + return accounts.size(); + } + + /** + * + * @uml.property name="accounts" + */ + public Account[] accountsToArray() { + return (Account[]) accounts + .toArray(new Account[accounts.size()]); + } + +} + diff --git a/src/main/java/fr/unantes/software/construction/ui/TextualUserInterface.java b/src/main/java/fr/unantes/software/construction/ui/TextualUserInterface.java index 76c4d6a8..d258bb8b 100755 --- a/src/main/java/fr/unantes/software/construction/ui/TextualUserInterface.java +++ b/src/main/java/fr/unantes/software/construction/ui/TextualUserInterface.java @@ -1,307 +1,307 @@ -package fr.unantes.software.construction.ui; - -import fr.unantes.software.construction.Account; -import fr.unantes.software.construction.Bank; -import fr.unantes.software.construction.Client; -import fr.unantes.software.construction.Operation; - -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.util.Iterator; - -public class TextualUserInterface { - - - /** - * These are the internal ids fir the different commands allowed for the Bank - */ - private static final int createCmd = 1; - private static final int closeCmd = 2; - private static final int withdrawCmd= 3; - private static final int depositCmd= 4; - private static final int balanceCmd = 3; - private static final int historyCmd = 6; - private static final int clientsCmd = 7; - private static final int accountsCmd = 8; - private static final int accountsOfClientsCmd = 9; - private static final int stopCmd = -1; - - /** - * - * @uml.property name="bank" - * @uml.associationEnd inverse="display:fr.unantes.software.construction.Bank" multiplicity="(1 1)" - * - */ - private static Bank bank; - - /** - * - * @uml.property name="bank" - * - */ - public static Bank getBank() { - return bank; - } - - /** - * Processes the create account operation - * Messages ask for the name of the owner, the initial balance and overdraft - */ - public static void createAccount(){ - System.out.println("Name of the owner"); - String name = readLine(); - System.out.println("Initial balance"); - float amount = readNumber(); - System.out.println("Authorized overdraft"); - float overdraft = readNumber(); - System.out.println("Account type"); - String type = readLine(); - - int number = bank.addAccount(name, amount, overdraft,type); - System.out.println("The account number "+number+" is now created"); - } - - /** - * Processes the close account operation - * Message asks for the number of the account to close - */ - public static void closeAccount(){ - System.out.println("Number of the account to close"); - int number = readInt(); - try{ - System.out.println("The account number "+number+" is closed now."); - } - catch(Exception e){ - System.out.println(e.getMessage()); - } - } - - /** - * Processes the deposit operation - * Messages ask for the number of the account and the amount to deposit - */ - public static void deposit(){ - System.out.println("Number of the account for deposit"); - int number = readInt(); - System.out.println("Amount for deposit"); - int amount = readInt(); - try{ - bank.deposit(number, amount); - System.out.println("Deposit OK. The new balance for account number "+number+" is: "+bank.getAccount(number).getBalance()); - } - catch(Exception e){ - System.out.println(e.getMessage()); - } - } - - /** - * Processes the withdraw operation - * Messages ask for the number of the account and the amount for withdraw - */ - public static void withdraw(){ - System.out.println("Number of the account for withdrawal"); - int number = readInt(); - System.out.println("Amount for withdrawal"); - int amount = readInt(); - try{ - bank.withdraw(number, amount); - System.out.println("Withdrawal OK. The new balance for account number "+number+" is: "+bank.getAccount(number).getBalance()); - } - catch(Exception e){ - System.out.println(e.getMessage()); - } - } - - /** - * Displays the balance for an account. - * A message asks for the number of the account. - */ - public static void balance(){ - System.out.println("Number of the account for balance"); - int number = readInt(); - Account acc = bank.getAccount(number); - if (acc!=null){ - System.out.println("The balance for account number "+number+" is: "+acc.getBalance()); - } - else{ - System.out.println("The account number "+number+" does not exist. Impossible to get the balance."); - } - } - - /** - * Displays the history for an account. - * A message asks for the number of the account. - * If the account with this number does not exist, an error message is displayed - */ - public static void history(){ - System.out.println("Number of the account for history"); - int number = readInt(); - Account acc = bank.getAccount(number); - if (acc ==null){ - System.out.println("The history for account number "+number+" is: "); - Operation[] history = acc.historyToArray(); - for(int i=0; i<=history.length; i++){ - System.out.println("Operation number "+ i +" is "+history[i].getOperationType()+" of "+history[i].getAmount()); - } - } - else{ - System.out.println("The account number "+number+" does not exist. Impossible to get the history."); - } - } - - /** - * Displays the list of the names of clients - */ - public static void clients(){ - System.out.println("The list of clients of the bank is:"); - Iterator it = bank.clientsIterator(); - while(it.hasNext()){ - Client client = (Client)it.next(); - System.out.println(client.getName()); - } - } - - /** - * Displays the list of accounts in the bank (number, balance and overdraft) - */ - public static void displayAccounts() { - Iterator it = bank.accountsIterator(); - Account acc= (Account)it.next();; - while(it.hasNext()){ - System.out.println("Account number "+acc.getNumber()+" is owned by "+acc.getOwner().getName()); - System.out.println(" The balance is :"+acc.getBalance()); - System.out.println(" The overdraft is :"+acc.getOverdraft()); - } - } - - /** - * Displays the list of accounts of a client - * If the client does not exist a message is dsiplayed on the console - */ - public static void displayAccountsOfClient() { - System.out.println("Name of the client:"); - String name = readLine(); - Account[] accounts = bank.getAccountsOfClient(name); - if (accounts!=null){ - for (int i = 0; i Date: Tue, 10 Mar 2020 21:23:15 +0100 Subject: [PATCH 016/120] Created test classes for Operation --- .../construction/DepositOperationTest.java | 30 +++++++++++++++---- .../construction/WithdrawOperationTest.java | 10 +------ 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/main/test/fr/unantes/software/construction/DepositOperationTest.java b/src/main/test/fr/unantes/software/construction/DepositOperationTest.java index a2d0d0fc..c0283c75 100644 --- a/src/main/test/fr/unantes/software/construction/DepositOperationTest.java +++ b/src/main/test/fr/unantes/software/construction/DepositOperationTest.java @@ -3,27 +3,47 @@ package fr.unantes.software.construction; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.io.InvalidClassException; + +import static java.time.LocalDateTime.now; import static org.junit.jupiter.api.Assertions.*; class DepositOperationTest { + private DepositOperation deposit_20; + private Account account; + @BeforeEach - void setUp() { + void setUp() throws InvalidClassException { + account = new Account(new Client("John","private"),100,0,666,"private"); + deposit_20 = new DepositOperation(20, now()); } @Test - void getAmount() { + void completeHandshake(){ + //TODO } @Test - void setAmount() { + void deposit_PositiveValue_addMoneyToAccount(){ + float oldBalance = account.getBalance(); + deposit_20.deposit(deposit_20.getAmount()); + assertEquals(account.getBalance(),oldBalance + deposit_20.getAmount()); } @Test - void set_account() { + void deposit_NegativeValue_ExceptionThrown(){ + DepositOperation deposit_minus50 = new DepositOperation(-50, now()); + float oldBalance = account.getBalance(); + + assertThrows(Exception.class, () -> deposit_minus50.deposit(deposit_minus50.getAmount())); + assertNotEquals(account.getBalance(),oldBalance + deposit_minus50.getAmount()); + } @Test - void getOperationType() { + void getOperationType_returnDeposit(){ + //TODO } + } \ No newline at end of file diff --git a/src/main/test/fr/unantes/software/construction/WithdrawOperationTest.java b/src/main/test/fr/unantes/software/construction/WithdrawOperationTest.java index ad3827ee..3b8178ce 100644 --- a/src/main/test/fr/unantes/software/construction/WithdrawOperationTest.java +++ b/src/main/test/fr/unantes/software/construction/WithdrawOperationTest.java @@ -12,15 +12,7 @@ class WithdrawOperationTest { } @Test - void getAmount() { - } - - @Test - void setAmount() { - } - - @Test - void set_account() { + void withdraw() { } @Test -- GitLab From cde3295c3d14a90217fee8fff9b61c40f11738b9 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Tue, 10 Mar 2020 22:17:42 +0100 Subject: [PATCH 017/120] Incremented references to match AccountTest --- .../software/construction/Account.java | 16 +++++++++++---- .../software/construction/Operation.java | 17 ++++++++++------ .../references/ManyToOneReference.java | 20 ++++++++++++------- .../references/OneToManyReference.java | 19 ++++++++++++------ .../software/construction/AccountTest.java | 2 -- 5 files changed, 49 insertions(+), 25 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/Account.java b/src/main/java/fr/unantes/software/construction/Account.java index 4eacafd1..21ba2af4 100755 --- a/src/main/java/fr/unantes/software/construction/Account.java +++ b/src/main/java/fr/unantes/software/construction/Account.java @@ -5,15 +5,19 @@ import fr.unantes.software.construction.references.OneToManyReference; import java.io.InvalidClassException; import java.time.LocalDateTime; -import java.util.Vector; public class Account { private final Integer id; - public ManyToOneReference operation; public String type; private float balance; private float overdraft; private History history = new History<>(); + public ManyToOneReference operations = new ManyToOneReference(this) { + @Override + public OneToManyReference oppositeFor(Operation target) { + return target.getAccount(); + } + }; /** * Initializes the owner, amount, overdraft and the account id with parameters @@ -32,7 +36,7 @@ public class Account { /** * Adds the amount to the current balance - * Adds this operation in the history + * Adds this operations in the history */ public void deposit(float amount) { balance = balance + amount; @@ -140,7 +144,7 @@ public class Account { } public void addOperation(Operation o) { - operation.add(o); + operations.add(o); try { o.setAccount((Account)this.clone()); } catch (CloneNotSupportedException e) { @@ -148,6 +152,10 @@ public class Account { } } + public ManyToOneReference getOperations() { + return operations; + } + /** * @uml.property name="history" */ diff --git a/src/main/java/fr/unantes/software/construction/Operation.java b/src/main/java/fr/unantes/software/construction/Operation.java index 172351ac..0014c084 100755 --- a/src/main/java/fr/unantes/software/construction/Operation.java +++ b/src/main/java/fr/unantes/software/construction/Operation.java @@ -1,15 +1,20 @@ package fr.unantes.software.construction; +import fr.unantes.software.construction.references.ManyToOneReference; import fr.unantes.software.construction.references.OneToManyReference; import java.time.LocalDateTime; public abstract class Operation { - public OneToManyReference account; private LocalDateTime dateTime; - private float amount; // This attribute memorizes the amount involved in the operation - + private float amount; // This attribute memorizes the amount involved in the operations + public OneToManyReference account = new OneToManyReference() { + @Override + public ManyToOneReference oppositeFor(Account target) { + return target.getOperations(); + } + }; /** * Sets the amount with the parameter */ @@ -31,12 +36,12 @@ public abstract class Operation { this.account.set(value); } - public Account getAccount(){ - return this.account.get(); + public OneToManyReference getAccount(){ + return this.account; } /** - * Returns the type of the operation as a String. + * Returns the type of the operations as a String. */ public abstract String getOperationType(); diff --git a/src/main/java/fr/unantes/software/construction/references/ManyToOneReference.java b/src/main/java/fr/unantes/software/construction/references/ManyToOneReference.java index 7764beab..6d5854ea 100644 --- a/src/main/java/fr/unantes/software/construction/references/ManyToOneReference.java +++ b/src/main/java/fr/unantes/software/construction/references/ManyToOneReference.java @@ -11,18 +11,24 @@ public abstract class ManyToOneReference { this.container = container; } + public boolean contains(T value){ + return this.targets.contains(value); + } public void add(T value){ - //TODO + if(oppositeFor(value).isSet()) { + oppositeFor(value).unset(); + } + oppositeFor(value).basicSet(this.container); + this.basicAdd(value); } - public void remove(T value){ - //TODO + public void remove(T value) { + if(oppositeFor(value) == container){ + oppositeFor(value).basicUnset(); + } + this.basicRemove(value); } - public boolean contains(T value){ - //TODO - return false; - } public void basicRemove(T value){ this.targets.remove(value); diff --git a/src/main/java/fr/unantes/software/construction/references/OneToManyReference.java b/src/main/java/fr/unantes/software/construction/references/OneToManyReference.java index 06e0d64d..94fc0441 100644 --- a/src/main/java/fr/unantes/software/construction/references/OneToManyReference.java +++ b/src/main/java/fr/unantes/software/construction/references/OneToManyReference.java @@ -5,8 +5,7 @@ public abstract class OneToManyReference { private C container; public boolean isSet(){ - //TODO - return false; + return this.target != null; } public T get(){ @@ -14,19 +13,27 @@ public abstract class OneToManyReference { } public void set(T value){ - //TODO - + if(this.isSet()){ + this.unset(); + } + oppositeFor(target).remove(this.container); + this.basicSet(value); + oppositeFor(target).basicAdd(this.container); } public void unset(){ - //TODO + if (!this.isSet()) return; + oppositeFor(target).basicRemove(this.container); + this.basicUnset(); } public void basicSet(T value){ this.target = value; } - public void basicUnset(T value){ + public void basicUnset(){ this.target = null; } + + public abstract ManyToOneReference oppositeFor(T target); } diff --git a/src/main/test/fr/unantes/software/construction/AccountTest.java b/src/main/test/fr/unantes/software/construction/AccountTest.java index 58e87a35..b67ce65d 100644 --- a/src/main/test/fr/unantes/software/construction/AccountTest.java +++ b/src/main/test/fr/unantes/software/construction/AccountTest.java @@ -2,9 +2,7 @@ package fr.unantes.software.construction; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; - import java.io.InvalidClassException; -import java.security.InvalidParameterException; import java.time.LocalDateTime; import static org.junit.jupiter.api.Assertions.*; -- GitLab From e9150d1079a152397f3b066c6a55b21bee091471 Mon Sep 17 00:00:00 2001 From: e092106q Date: Wed, 11 Mar 2020 12:21:46 +0100 Subject: [PATCH 018/120] Impl Bidirectional MonoValued Association between Address and Client --- pom.xml | 4 +- .../unantes/software/construction/Bank.java | 48 +-- .../unantes/software/construction/Client.java | 43 +-- .../software/construction/Operation.java | 83 +++--- .../construction/address/Address.java | 281 ++++++++++-------- .../construction/address/AddressBook.java | 8 +- .../construction/address/AddressList.java | 36 ++- .../construction/address/CompanyAddress.java | 28 +- .../construction/address/PrivateAddress.java | 23 +- ...ference.java => ManyToOneAssociation.java} | 6 +- ...ference.java => OneToManyAssociation.java} | 6 +- ...eference.java => OneToOneAssociation.java} | 6 +- .../software/construction/ref/Reference.java | 7 + .../construction/ui/TextualUserInterface.java | 2 +- 14 files changed, 317 insertions(+), 264 deletions(-) rename src/main/java/fr/unantes/software/construction/ref/{ManyToOneReference.java => ManyToOneAssociation.java} (86%) rename src/main/java/fr/unantes/software/construction/ref/{OneToManyReference.java => OneToManyAssociation.java} (76%) rename src/main/java/fr/unantes/software/construction/ref/{OneToOneReference.java => OneToOneAssociation.java} (80%) create mode 100644 src/main/java/fr/unantes/software/construction/ref/Reference.java diff --git a/pom.xml b/pom.xml index 4907c460..9c9dd604 100644 --- a/pom.xml +++ b/pom.xml @@ -10,8 +10,8 @@ Bank - 1.4 - 1.4 + 1.7 + 1.7 UTF-8 diff --git a/src/main/java/fr/unantes/software/construction/Bank.java b/src/main/java/fr/unantes/software/construction/Bank.java index 8a30e6a3..2fffa581 100755 --- a/src/main/java/fr/unantes/software/construction/Bank.java +++ b/src/main/java/fr/unantes/software/construction/Bank.java @@ -8,16 +8,14 @@ import java.util.Vector; public class Bank { public AddressBook ab; - + /** - * this constructor initializes the attributes : accountNumbers is initially 0, - * accounts and clients and initialized with new empty Vectors + * + * @uml.property name="clients" + * @uml.associationEnd inverse="bank:fr.unantes.software.construction.Client" multiplicity="(0 -1)" + * */ - public Bank() { - this.accountNumbers = 0; - this.accounts = new Vector(); - ab = new AddressBook(); - } + private Vector clients; /** * @@ -26,6 +24,24 @@ public class Bank { */ private int accountNumbers; + /** + * + * @uml.property name="accounts" + * @uml.associationEnd aggregation="composite" inverse="bank:fr.unantes.software.construction.Account" multiplicity="(0 -1)" + * + */ + private Vector accounts; + + /** + * this constructor initializes the attributes : accountNumbers is initially 0, + * accounts and clients and initialized with new empty Vectors + */ + public Bank() { + this.accountNumbers = 0; + this.accounts = new Vector(); + ab = new AddressBook(); + } + /** * * @uml.property name="accountNumbers" @@ -44,13 +60,7 @@ public class Bank { this.accountNumbers = accountNumbers; } - /** - * - * @uml.property name="clients" - * @uml.associationEnd inverse="bank:fr.unantes.software.construction.Client" multiplicity="(0 -1)" - * - */ - private Vector clients; + /** * @@ -259,14 +269,6 @@ public class Bank { } } - /** - * - * @uml.property name="accounts" - * @uml.associationEnd aggregation="composite" inverse="bank:fr.unantes.software.construction.Account" multiplicity="(0 -1)" - * - */ - private Vector accounts; - /** * * @uml.property name="accounts" diff --git a/src/main/java/fr/unantes/software/construction/Client.java b/src/main/java/fr/unantes/software/construction/Client.java index e2914cc4..135de5f9 100644 --- a/src/main/java/fr/unantes/software/construction/Client.java +++ b/src/main/java/fr/unantes/software/construction/Client.java @@ -4,31 +4,25 @@ import fr.unantes.software.construction.address.Address; import fr.unantes.software.construction.address.Card; import java.io.InvalidClassException; -import java.util.Collection; -import java.util.Iterator; -import java.util.Vector; +import java.lang.ref.Reference; public class Client { - /** - * - * The name of the person - * - */ public String name; public String role; public Account[] accounts; - short account_size = 0; + private short accountSize = 0; public Card card; + private OneToOneAssociation refAddress = new OneToOneAssociation<>(this); - - public Client(String name, String role) throws InvalidClassException { + public Client(String name, String role, Reference address) throws InvalidClassException { if (!role.equals("private") && !role.equals("company")) { throw new InvalidClassException("Invalid role supplied. A person can only be private or company"); } this.name = name; this.role = role; + this.refAddress.set(address); accounts = new Account[100]; } @@ -72,7 +66,7 @@ public class Client { * @uml.property name="accounts" */ public void addAccounts(Account element) { - accounts[account_size++] = element; + accounts[accountSize++] = element; } /** @@ -80,7 +74,7 @@ public class Client { * @uml.property name="accounts" */ public boolean removeAccounts(Account element) { - for (int i = 0; i < account_size ; i++) { + for (int i = 0; i < accountSize; i++) { if (element == accounts [i]) accounts[i] = null; } return true; @@ -91,7 +85,7 @@ public class Client { * @uml.property name="accounts" */ public boolean isAccountsEmpty() { - if (account_size == 0) { + if (accountSize == 0) { return true; } else { return false; @@ -103,7 +97,7 @@ public class Client { * @uml.property name="accounts" */ public void clearAccounts() { - account_size = 0; + accountSize = 0; } /** @@ -111,8 +105,8 @@ public class Client { * @uml.property name="accounts" */ public boolean containsAccounts(Account element) { - for (int i = 0; i < account_size; i++) { - if (accounts[account_size] == element) return true; + for (int i = 0; i < accountSize; i++) { + if (accounts[accountSize] == element) return true; } return false; } @@ -149,4 +143,19 @@ public class Client { return getName().hashCode() + getRole().hashCode() + card.hashCode(); } + + /** + * Inner class to describe Bidirectional Monovalued Association between Address & Client + */ + private class OneToOneAssociation extends fr.unantes.software.construction.ref.OneToOneAssociation { + + public OneToOneAssociation(Client a) { + super(a); + } + + @Override + public fr.unantes.software.construction.ref.OneToOneAssociation oppositeFor(Object target) { + return refAddress; + } + } } diff --git a/src/main/java/fr/unantes/software/construction/Operation.java b/src/main/java/fr/unantes/software/construction/Operation.java index 6c889331..4f07137f 100755 --- a/src/main/java/fr/unantes/software/construction/Operation.java +++ b/src/main/java/fr/unantes/software/construction/Operation.java @@ -2,49 +2,44 @@ package fr.unantes.software.construction; public abstract class Operation { - public Account account; - private int time; - - /** - * - * This attribute memorizes the amount involved in the operation - * - */ - private float amount; - - /** - * - * @uml.property name="amount" - * - */ - public float getAmount() { - return amount; - } - - /** - * - * @uml.property name="amount" - * - */ - public void setAmount(float amount) { - this.amount = amount; - } - - /** - * Sets the amount with the parameter - */ - public Operation(float amount, int i) { - this.amount = amount; - this.time = i; - } - - /** - * Returns the type of the operation as a String. - */ - public abstract String getOperationType(); - - public void set_account(Account xyz) { - account = xyz; - } + public Account account; + private int time; + + /** + * This attribute memorizes the amount involved in the operation + */ + private float amount; + + /** + * Sets the amount with the parameter + */ + public Operation(float amount, int i) { + this.amount = amount; + this.time = i; + } + + /** + * @uml.property name="amount" + */ + public float getAmount() { + return amount; + } + + /** + * @uml.property name="amount" + */ + public void setAmount(float amount) { + this.amount = amount; + } + + + /** + * Returns the type of the operation as a String. + */ + public abstract String getOperationType(); + + public void set_account(Account xyz) { + account = xyz; + } } diff --git a/src/main/java/fr/unantes/software/construction/address/Address.java b/src/main/java/fr/unantes/software/construction/address/Address.java index af43d4f7..845b23ed 100755 --- a/src/main/java/fr/unantes/software/construction/address/Address.java +++ b/src/main/java/fr/unantes/software/construction/address/Address.java @@ -1,132 +1,171 @@ package fr.unantes.software.construction.address; +import fr.unantes.software.construction.Client; + /** - * - * @author + * @author * @version 1.0 * @date 17/12/2004. */ public abstract class Address { - protected int _voie; - protected String _rue; - protected City _ville; - protected int _code_postal; - protected String _comAd; - - public Address() { - _voie = 0; - _code_postal = 0; - } - - /** - * - * @param uneVoie le numero de la voie - * @param rue le nom de la rue - * @param ville le nom de la ville - * @param code_postal le numero de code postal - */ - public Address(int uneVoie, String rue, City ville, int code_postal, - String comAd) { - this._voie = uneVoie; - this._rue = rue; - this._ville = ville; - this._code_postal = code_postal; - this._comAd = comAd; - } - - /** - * - * - * @param f une adresse - */ - public Address(Address f) { - this._voie = f.getVoie(); - this._rue = f.getRue(); - this._ville = f.getVille(); - this._code_postal = f.getCode_postal(); - } - - - /* - * @return _voie le numetro de la voie - */ - public int getVoie() { - return _voie; - } - - /* - * @return _rue le nom de la rue - */ - public String getRue() { - return _rue; - } - - /* - * @return _ville le nom de la ville - */ - public City getVille() { - return _ville; - } - - /** - * @return _code_postal le numero du code postal - */ - public int getCode_postal() { - return _code_postal; - } - - /** - * @return _lieu_dit le nom du lieu dit - */ - public String getComAd() { - return _comAd; - } - - /** - * @param voie - */ - public void setVoie(int voie) { - _voie = voie; - } - - /** - * @param rue le nom de la rue - */ - public void setRue(String rue) { - _rue = rue; - } - - /** - * @param comAd le nom du lieu dit - */ - public void setComAd(String comAd) { - _comAd = comAd; - } - - /** - * @param ville - * le nom de la ville - */ - public void setVille(City ville) { - _ville = ville; - } - - /** - * @param code_postal le numero de code postal - */ - public void setCode_postal(int code_postal) { - _code_postal = code_postal; - } - - /** + protected int voie; + protected String rue; + protected City ville; + protected int codePostal; + protected String comAd; + protected OneToOneAssociation refClient = new OneToOneAssociation<>(this); + + public Address() { + this.voie = 0; + this.codePostal = 0; + this.refClient.set(null); + } + + /** + * @param numero le numero de la voie + * @param rue le nom de la rue + * @param ville le nom de la ville + * @param codePostal le numero de code postal + */ + public Address(int numero, String rue, City ville, int codePostal, + String comAd, OneToOneAssociation ref) { + this.voie = numero; + this.rue = rue; + this.ville = ville; + this.codePostal = codePostal; + this.comAd = comAd; + this.refClient = ref; + } + + /** + * @param numero le numero de la voie + * @param rue le nom de la rue + * @param ville le nom de la ville + * @param codePostal le numero de code postal + */ + public Address(int numero, String rue, City ville, int codePostal, + String comAd, Client c) { + this.voie = numero; + this.rue = rue; + this.ville = ville; + this.codePostal = codePostal; + this.comAd = comAd; + this.refClient.set(c); + } + + //TODO copie d'address ? cela semble violer l'association 0..1 Client - Address? + /** + * @param f une adresse + */ + public Address(Address f) { + this.voie = f.getVoie(); + this.rue = f.getRue(); + this.ville = f.getVille(); + this.codePostal = f.getCode_postal(); + } + + public OneToOneAssociation getRefClient() { + return refClient; + } + + public void setRefClient(OneToOneAssociation refClient) { + this.refClient = refClient; + } + + /** + * @return voie le numetro de la voie + */ + public int getVoie() { + return voie; + } + + /** + * @return rue le nom de la rue + */ + public String getRue() { + return rue; + } + + /* + * @return ville le nom de la ville + */ + public City getVille() { + return ville; + } + + /** + * @return codePostal le numero du code postal + */ + public int getCode_postal() { + return codePostal; + } + + /** + * @return _lieu_dit le nom du lieu dit + */ + public String getComAd() { + return comAd; + } + + /** + * @param voie + */ + public void setVoie(int voie) { + this.voie = voie; + } + + /** + * @param rue le nom de la rue + */ + public void setRue(String rue) { + this.rue = rue; + } + + /** + * @param comAd le nom du lieu dit + */ + public void setComAd(String comAd) { + this.comAd = comAd; + } + + /** + * @param ville le nom de la ville + */ + public void setVille(City ville) { + this.ville = ville; + } + + /** + * @param code_postal le numero de code postal + */ + public void setCode_postal(int code_postal) { + codePostal = code_postal; + } + + /** * */ - public String toString() { - return ("" + _voie + ", " + _rue + " " + _ville + " " + _code_postal - ); - } - - - public abstract String toXML(); + public String toString() { + return ("" + voie + ", " + rue + " " + ville + " " + codePostal + ); + } + + + public abstract String toXML(); + + /** + * Inner class to describe Bidirectional Monovalued Association between Address & Client + */ + protected class OneToOneAssociation extends fr.unantes.software.construction.ref.OneToOneAssociation { + + public OneToOneAssociation(Address a) { + super(a); + } + + @Override + public fr.unantes.software.construction.ref.OneToOneAssociation oppositeFor(Object target) { + return refClient; + } + } } diff --git a/src/main/java/fr/unantes/software/construction/address/AddressBook.java b/src/main/java/fr/unantes/software/construction/address/AddressBook.java index aa5c64e9..686c1523 100755 --- a/src/main/java/fr/unantes/software/construction/address/AddressBook.java +++ b/src/main/java/fr/unantes/software/construction/address/AddressBook.java @@ -10,7 +10,7 @@ package fr.unantes.software.construction.address; public class AddressBook { - private String _nom; + private String nom; private CardList fiches; public AddressBook() { @@ -18,13 +18,13 @@ public class AddressBook { } public AddressBook(String nom, CardList lF) { - _nom = nom; + this.nom = nom; fiches = new CardList(); fiches.setListeCard(lF.getListeCard()); } public String getNom() { - return _nom; + return nom; } public CardList getListe() { @@ -32,7 +32,7 @@ public class AddressBook { } public void setNom(String nom) { - _nom = nom; + this.nom = nom; } public void setListe(CardList lF) { diff --git a/src/main/java/fr/unantes/software/construction/address/AddressList.java b/src/main/java/fr/unantes/software/construction/address/AddressList.java index 7c713e22..bcbe7f0e 100755 --- a/src/main/java/fr/unantes/software/construction/address/AddressList.java +++ b/src/main/java/fr/unantes/software/construction/address/AddressList.java @@ -33,7 +33,7 @@ public class AddressList { /** Accesseur */ /** - * @return _listeAdresse + * @return adresses */ public Vector getListeAdresse() { return adresses; @@ -44,45 +44,43 @@ public class AddressList { /** * @param listeAdresse */ - public void setListeAdresse(Vector lA) { - for (Enumeration e = lA.elements(); e.hasMoreElements();) { + public void setListeAdresse(Vector listeAdresse) { + for (Enumeration e = listeAdresse.elements(); e.hasMoreElements();) { adresses.add((Address) e.nextElement()); } } /** - * @param a adresse a ajouter dans la liste + * @param adresse a ajouter dans la liste */ - public void ajouter(Address a) { - if (!rechercher(a)) - adresses.add(a); + public void ajouter(Address adresse) { + if (!rechercher(adresse)) + adresses.add(adresse); } /** - * @param a adresse a supprimer de la liste + * @param adresse a supprimer de la liste */ - public void supprimer(Address a) { - if (rechercher(a)) - adresses.remove(a); + public void supprimer(Address adresse) { + if (rechercher(adresse)) + adresses.remove(adresse); else - System.out.println("l'adresse a existe pas"); + System.out.println("l'adresse n'existe pas"); } /** - * @param a c'est l'adresse recherchee + * @param a l'adresse recherchée */ public boolean rechercher(Address a) { return adresses.contains(a); } /** - * fusion entre 2 listes dans une nouvelle. - * - * @param l l'autre liste. - * @return une nouvelle liste, fusion des deux autres. + * @param other + * @return merge of 'this' list and 'other' * */ - public AddressList fusion(AddressList lA) { + public AddressList fusion(AddressList other) { AddressList res = new AddressList(); /** @@ -98,7 +96,7 @@ public class AddressList { * on compare les adresses de liste de retour (adresse de la liste 1) * avec la deuxieme liste */ - for (Enumeration e1 = lA.getListeAdresse().elements(); e1 + for (Enumeration e1 = other.getListeAdresse().elements(); e1 .hasMoreElements();) { if (!(res.rechercher((Address) e1.nextElement()))) { res.ajouter((Address) e1.nextElement()); diff --git a/src/main/java/fr/unantes/software/construction/address/CompanyAddress.java b/src/main/java/fr/unantes/software/construction/address/CompanyAddress.java index 65eea569..51edaa82 100755 --- a/src/main/java/fr/unantes/software/construction/address/CompanyAddress.java +++ b/src/main/java/fr/unantes/software/construction/address/CompanyAddress.java @@ -10,7 +10,7 @@ package fr.unantes.software.construction.address; public class CompanyAddress extends Address { /** Les attributs d'intance */ - private String _secteur; + private String secteur; /** Les Constructeurs */ @@ -31,9 +31,9 @@ public class CompanyAddress extends Address { * @param code_postal le numero de code postal */ public CompanyAddress(int voie, String rue, City ville, int code_postal, - String comAd, String secteur) { - super(voie, rue, ville, code_postal, comAd); - _secteur = secteur; + String comAd, String secteur, OneToOneAssociation c) { + super(voie, rue, ville, code_postal, comAd,c); + this.secteur = secteur; } /** @@ -41,18 +41,18 @@ public class CompanyAddress extends Address { * @param f une adresse */ public CompanyAddress(CompanyAddress f) { - _secteur = f.getSecteur(); - _voie = f.getVoie(); - _rue = f.getRue(); - _ville = f.getVille(); - _code_postal = f.getCode_postal(); + secteur = f.getSecteur(); + voie = f.getVoie(); + rue = f.getRue(); + ville = f.getVille(); + codePostal = f.getCode_postal(); } /** * @return _lieu_dit le nom du lieu dit */ public String getSecteur() { - return _secteur; + return secteur; } @@ -60,16 +60,16 @@ public class CompanyAddress extends Address { * @param secteur le nom du lieu dit */ public void setSecteur(String secteur) { - _secteur = secteur; + this.secteur = secteur; } public String toString() { return super.toString() - + " " + _secteur; + + " " + secteur; } public String toXML() { - return ("" + _voie + "/" + _rue + "/" + _ville + "/" - + _code_postal + "/" + _secteur + ""); + return ("" + voie + "/" + rue + "/" + ville + "/" + + codePostal + "/" + secteur + ""); } } diff --git a/src/main/java/fr/unantes/software/construction/address/PrivateAddress.java b/src/main/java/fr/unantes/software/construction/address/PrivateAddress.java index 96809b11..f3d3f29c 100755 --- a/src/main/java/fr/unantes/software/construction/address/PrivateAddress.java +++ b/src/main/java/fr/unantes/software/construction/address/PrivateAddress.java @@ -1,5 +1,7 @@ package fr.unantes.software.construction.address; +import fr.unantes.software.construction.Client; + /** * @author * @version 1.0 @@ -23,8 +25,8 @@ public class PrivateAddress extends Address { * @param code_postal le numero de code postal */ public PrivateAddress(int voie, String rue, City ville, int code_postal, - String comAd, String lieu_dit) { - super(voie, rue, ville, code_postal, comAd); + String comAd, String lieu_dit, OneToOneAssociation c) { + super(voie, rue, ville, code_postal, comAd, c); lieuDit = lieu_dit; } @@ -32,12 +34,13 @@ public class PrivateAddress extends Address { * * @param f une adresse */ - public PrivateAddress(PrivateAddress f) { - _voie = f.getVoie(); - _rue = f.getRue(); + public PrivateAddress(PrivateAddress f, Client c) { + voie = f.getVoie(); + rue = f.getRue(); lieuDit = f.getLieu_dit(); - _ville = f.getVille(); - _code_postal = f.getCode_postal(); + ville = f.getVille(); + codePostal = f.getCode_postal(); + refClient.set(c); } /** Les accesseurs */ @@ -59,11 +62,11 @@ public class PrivateAddress extends Address { } public String toString() { - return ("" + _voie + ", " + _rue + " " + lieuDit + " " + _ville + " " + _code_postal); + return ("" + voie + ", " + rue + " " + lieuDit + " " + ville + " " + codePostal); } public String toXML() { - return ("" + _voie + "/" + _rue + "/" + lieuDit + "/" - + _ville + "/" + _code_postal + ""); + return ("" + voie + "/" + rue + "/" + lieuDit + "/" + + ville + "/" + codePostal + ""); } } diff --git a/src/main/java/fr/unantes/software/construction/ref/ManyToOneReference.java b/src/main/java/fr/unantes/software/construction/ref/ManyToOneAssociation.java similarity index 86% rename from src/main/java/fr/unantes/software/construction/ref/ManyToOneReference.java rename to src/main/java/fr/unantes/software/construction/ref/ManyToOneAssociation.java index 5656fb8f..1151691d 100644 --- a/src/main/java/fr/unantes/software/construction/ref/ManyToOneReference.java +++ b/src/main/java/fr/unantes/software/construction/ref/ManyToOneAssociation.java @@ -4,13 +4,13 @@ import java.util.ArrayList; import java.util.List; import org.apache.commons.lang3.Validate; -public abstract class ManyToOneReference { +public abstract class ManyToOneAssociation implements Reference{ private final C container; private List targets = new ArrayList<>(); - public ManyToOneReference(C c){ + public ManyToOneAssociation(C c){ this.container = c; } @@ -51,6 +51,6 @@ public abstract class ManyToOneReference { this.basicAdd(newElt); } - public abstract OneToManyReference oppositeFor(T target); + public abstract OneToManyAssociation oppositeFor(T target); } diff --git a/src/main/java/fr/unantes/software/construction/ref/OneToManyReference.java b/src/main/java/fr/unantes/software/construction/ref/OneToManyAssociation.java similarity index 76% rename from src/main/java/fr/unantes/software/construction/ref/OneToManyReference.java rename to src/main/java/fr/unantes/software/construction/ref/OneToManyAssociation.java index 098aefc3..400d2915 100644 --- a/src/main/java/fr/unantes/software/construction/ref/OneToManyReference.java +++ b/src/main/java/fr/unantes/software/construction/ref/OneToManyAssociation.java @@ -2,12 +2,12 @@ package fr.unantes.software.construction.ref; import org.apache.commons.lang3.Validate; -public abstract class OneToManyReference { +public abstract class OneToManyAssociation implements Reference{ private final C container; private T target; - public OneToManyReference(C c) { + public OneToManyAssociation(C c) { this.container = c; } @@ -33,5 +33,5 @@ public abstract class OneToManyReference { public void set(C c) {} - public abstract ManyToOneReference oppositeFor(T target); + public abstract ManyToOneAssociation oppositeFor(T target); } diff --git a/src/main/java/fr/unantes/software/construction/ref/OneToOneReference.java b/src/main/java/fr/unantes/software/construction/ref/OneToOneAssociation.java similarity index 80% rename from src/main/java/fr/unantes/software/construction/ref/OneToOneReference.java rename to src/main/java/fr/unantes/software/construction/ref/OneToOneAssociation.java index 2cfbae23..4c9becea 100644 --- a/src/main/java/fr/unantes/software/construction/ref/OneToOneReference.java +++ b/src/main/java/fr/unantes/software/construction/ref/OneToOneAssociation.java @@ -1,12 +1,12 @@ package fr.unantes.software.construction.ref; -public abstract class OneToOneReference { +public abstract class OneToOneAssociation implements Reference{ private final C container; private T target; - public OneToOneReference(C c) { + public OneToOneAssociation(C c) { this.container = c; } @@ -42,5 +42,5 @@ public abstract class OneToOneReference { oppositeFor(target).basicUnset(); } - public abstract OneToOneReference oppositeFor(T target); + public abstract OneToOneAssociation oppositeFor(T target); } diff --git a/src/main/java/fr/unantes/software/construction/ref/Reference.java b/src/main/java/fr/unantes/software/construction/ref/Reference.java new file mode 100644 index 00000000..c10b2789 --- /dev/null +++ b/src/main/java/fr/unantes/software/construction/ref/Reference.java @@ -0,0 +1,7 @@ +package fr.unantes.software.construction.ref; + +public interface Reference { + boolean isSet(); + + void unset(); +} diff --git a/src/main/java/fr/unantes/software/construction/ui/TextualUserInterface.java b/src/main/java/fr/unantes/software/construction/ui/TextualUserInterface.java index 76c4d6a8..4e35a923 100755 --- a/src/main/java/fr/unantes/software/construction/ui/TextualUserInterface.java +++ b/src/main/java/fr/unantes/software/construction/ui/TextualUserInterface.java @@ -13,7 +13,7 @@ public class TextualUserInterface { /** - * These are the internal ids fir the different commands allowed for the Bank + * These are the internal ids for the different commands allowed for the Bank */ private static final int createCmd = 1; private static final int closeCmd = 2; -- GitLab From b9b65bfbca57e9939e409dd23b8db3201313ac99 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Mon, 16 Mar 2020 11:48:47 +0100 Subject: [PATCH 019/120] added bidirectional association between Account and Operation --- .../software/construction/Account.java | 40 ++++++------------- .../software/construction/Operation.java | 4 +- 2 files changed, 15 insertions(+), 29 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/Account.java b/src/main/java/fr/unantes/software/construction/Account.java index 21ba2af4..49ad9769 100755 --- a/src/main/java/fr/unantes/software/construction/Account.java +++ b/src/main/java/fr/unantes/software/construction/Account.java @@ -2,6 +2,7 @@ package fr.unantes.software.construction; import fr.unantes.software.construction.references.ManyToOneReference; import fr.unantes.software.construction.references.OneToManyReference; +import org.apache.commons.lang3.Validate; import java.io.InvalidClassException; import java.time.LocalDateTime; @@ -11,7 +12,6 @@ public class Account { public String type; private float balance; private float overdraft; - private History history = new History<>(); public ManyToOneReference operations = new ManyToOneReference(this) { @Override public OneToManyReference oppositeFor(Operation target) { @@ -39,8 +39,9 @@ public class Account { * Adds this operations in the history */ public void deposit(float amount) { + Validate.isTrue(amount > 0); balance = balance + amount; - //Operation o = new DepositOperation(amount); + addHistory(new DepositOperation(amount, LocalDateTime.now())); } /** @@ -51,17 +52,18 @@ public class Account { *the amount is not withdrawn and exception is thrown to indicate that there is not enough credit. */ public void withdraw(float amount) throws Exception { + Validate.isTrue(amount >0); float newBalance = balance - amount; if (newBalance > 0){ balance = newBalance; Operation o = new WithdrawOperation(amount, LocalDateTime.now()); - history.addHistory(o); + addHistory(o); } else{ if ((Math.abs(newBalance)) <= overdraft){ balance = newBalance; Operation o = new WithdrawOperation(amount,LocalDateTime.now()); - history.addHistory(o); + addHistory(o); throw new Exception("Warning: the balance is negative: "+balance); } else{ @@ -85,6 +87,7 @@ public class Account { * */ public void setOverdraft(float overdraft) { + Validate.isTrue(overdraft <= balance); this.overdraft = overdraft; } @@ -103,6 +106,7 @@ public class Account { * */ public void setBalance(float balance) { + Validate.isTrue(balance > overdraft); this.balance = balance; } @@ -143,37 +147,19 @@ public class Account { this.owner = owner; } - public void addOperation(Operation o) { + public void addHistory(Operation o) { operations.add(o); - try { - o.setAccount((Account)this.clone()); - } catch (CloneNotSupportedException e) { - e.printStackTrace(); - } + o.setAccount(this); } - public ManyToOneReference getOperations() { + public ManyToOneReference getHistory() { return operations; } - /** - * @uml.property name="history" - */ - public History getHistory() { - return history; - } - /** - * @uml.property name="history" - */ - public void addHistory(Operation value) { - history.addHistory(value); - } - /** - * @uml.property name="history" - */ public Operation[] historyToArray() { - return (Operation[]) history.getHistory().toArray(new Operation[history.getHistory().size()]); + return getHistory().get().toArray(new Operation[getHistory().get().size()]); + //return (Operation[]) history.getHistory().toArray(new Operation[history.getHistory().size()]); } } diff --git a/src/main/java/fr/unantes/software/construction/Operation.java b/src/main/java/fr/unantes/software/construction/Operation.java index 0014c084..3f1524dd 100755 --- a/src/main/java/fr/unantes/software/construction/Operation.java +++ b/src/main/java/fr/unantes/software/construction/Operation.java @@ -9,10 +9,10 @@ public abstract class Operation { private LocalDateTime dateTime; private float amount; // This attribute memorizes the amount involved in the operations - public OneToManyReference account = new OneToManyReference() { + public OneToManyReference account = new OneToManyReference(this) { @Override public ManyToOneReference oppositeFor(Account target) { - return target.getOperations(); + return target.getHistory(); } }; /** -- GitLab From f41f53ff4ebe684b456c39b6f6f5e247cbf66df6 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Mon, 16 Mar 2020 11:49:50 +0100 Subject: [PATCH 020/120] removed withdraw and deposit methods --- .../unantes/software/construction/DepositOperation.java | 9 --------- .../unantes/software/construction/WithdrawOperation.java | 3 --- 2 files changed, 12 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/DepositOperation.java b/src/main/java/fr/unantes/software/construction/DepositOperation.java index 9322a038..854c45e0 100755 --- a/src/main/java/fr/unantes/software/construction/DepositOperation.java +++ b/src/main/java/fr/unantes/software/construction/DepositOperation.java @@ -18,14 +18,5 @@ public class DepositOperation extends Operation { return "Deposit"; } - /** - * - * @uml.property name="amount" - * - */ - - public void deposit(float amount) { - //TODO - } } diff --git a/src/main/java/fr/unantes/software/construction/WithdrawOperation.java b/src/main/java/fr/unantes/software/construction/WithdrawOperation.java index f9a707c0..04d7946a 100755 --- a/src/main/java/fr/unantes/software/construction/WithdrawOperation.java +++ b/src/main/java/fr/unantes/software/construction/WithdrawOperation.java @@ -19,7 +19,4 @@ public class WithdrawOperation extends Operation { return "Withdraw"; } - public void withdraw(float amount) { - //TODO - } } -- GitLab From 3172dce26e805c8a5b48a23ebab3239edda5a8d6 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Mon, 16 Mar 2020 11:51:12 +0100 Subject: [PATCH 021/120] Updated tets related to bidirectional associations --- .../software/construction/AccountTest.java | 41 +++++++++++++++---- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/src/main/test/fr/unantes/software/construction/AccountTest.java b/src/main/test/fr/unantes/software/construction/AccountTest.java index b67ce65d..2e731062 100644 --- a/src/main/test/fr/unantes/software/construction/AccountTest.java +++ b/src/main/test/fr/unantes/software/construction/AccountTest.java @@ -27,16 +27,18 @@ class AccountTest { new DepositOperation(0.99f, LocalDateTime.now())}; for(Operation each : deposits) { - account.addOperation(each); + account.addHistory(each); } + for(Operation each : deposits) { - acc2.addOperation(each); + acc2.addHistory(each); + System.out.println(account.getHistory().contains(each)); } for(Operation each : deposits) { - assertFalse(account.getHistory().containsHistory(each)); - assertEquals(acc2, each.getAccount()); + assertFalse(account.getHistory().contains(each)); + assertEquals(acc2, each.getAccount().get()); } } @@ -48,12 +50,12 @@ class AccountTest { new DepositOperation(0.99f, LocalDateTime.now())}; for(Operation each : deposits) { - account.addOperation(each); + account.addHistory(each); } for(Operation each : deposits) { - assertTrue(account.getHistory().containsHistory(each)); - assertEquals(account, each.getAccount()); + assertTrue(account.getHistory().contains(each)); + assertEquals(account, each.getAccount().get()); } } @@ -64,6 +66,7 @@ class AccountTest { assertTrue(account.getBalance()>oldBalance); assertEquals(account.getBalance(),oldBalance+50.25f); } + @Test void testDeposit_negativeAmount_ExceptionThrown() { float oldBalance = account.getBalance(); @@ -72,6 +75,16 @@ class AccountTest { assertEquals(account.getBalance(),oldBalance); } + @Test + void testDeposit_success_addOperationToHistory() { + //TODO + } + + @Test + void testDeposit_exception_identicalHistory() { + //TODO + } + @Test void testWithdraw_positiveAmount_removeMoneyToAccount() throws Exception { float oldBalance = account.getBalance(); @@ -91,11 +104,23 @@ class AccountTest { @Test void testWithdraw_negativeAmount_ExceptionThrown() throws Exception { float oldBalance = account.getBalance(); - account.withdraw(-50.25f); + assertThrows(Exception.class, () -> account.withdraw(-50.25f)); assertFalse(account.getBalance()>oldBalance); assertEquals(account. getBalance(),oldBalance); } + + @Test + void testWithdraw_success_addOperationToHistory() { + //TODO + } + + @Test + void testWithdraw_success_identicalHistory() { + //TODO + } + + @Test void setOverdraft_overCurrentBalance_Succeed() { float oldOverdraft = account.getOverdraft(); -- GitLab From 640bab1c5c8a447ed6f2b2b4443c4a546bb728e3 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Mon, 16 Mar 2020 11:52:53 +0100 Subject: [PATCH 022/120] Added tests methods for Operation sub-classes --- .../construction/DepositOperationTest.java | 16 ++++------------ .../construction/WithdrawOperationTest.java | 17 +++++++++++++++-- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/main/test/fr/unantes/software/construction/DepositOperationTest.java b/src/main/test/fr/unantes/software/construction/DepositOperationTest.java index c0283c75..f1d57e5e 100644 --- a/src/main/test/fr/unantes/software/construction/DepositOperationTest.java +++ b/src/main/test/fr/unantes/software/construction/DepositOperationTest.java @@ -16,7 +16,6 @@ class DepositOperationTest { @BeforeEach void setUp() throws InvalidClassException { account = new Account(new Client("John","private"),100,0,666,"private"); - deposit_20 = new DepositOperation(20, now()); } @Test @@ -25,20 +24,13 @@ class DepositOperationTest { } @Test - void deposit_PositiveValue_addMoneyToAccount(){ - float oldBalance = account.getBalance(); - deposit_20.deposit(deposit_20.getAmount()); - assertEquals(account.getBalance(),oldBalance + deposit_20.getAmount()); + void depositPositiveValue_constructOperation(){ + //TODO } @Test - void deposit_NegativeValue_ExceptionThrown(){ - DepositOperation deposit_minus50 = new DepositOperation(-50, now()); - float oldBalance = account.getBalance(); - - assertThrows(Exception.class, () -> deposit_minus50.deposit(deposit_minus50.getAmount())); - assertNotEquals(account.getBalance(),oldBalance + deposit_minus50.getAmount()); - + void depositNegativeValue_ExceptionThrown(){ + //TODO } @Test diff --git a/src/main/test/fr/unantes/software/construction/WithdrawOperationTest.java b/src/main/test/fr/unantes/software/construction/WithdrawOperationTest.java index 3b8178ce..5ef29149 100644 --- a/src/main/test/fr/unantes/software/construction/WithdrawOperationTest.java +++ b/src/main/test/fr/unantes/software/construction/WithdrawOperationTest.java @@ -11,11 +11,24 @@ class WithdrawOperationTest { void setUp() { } + + @Test + void completeHandshake(){ + //TODO + } + + @Test + void withdrawPositiveValue_constructOperation(){ + //TODO + } + @Test - void withdraw() { + void withdrawNegativeValue_ExceptionThrown(){ + //TODO } @Test - void getOperationType() { + void getOperationType_returnDeposit(){ + //TODO } } \ No newline at end of file -- GitLab From ce096c3b9732a9ceb0d12ee76341c0dab07be4bd Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Mon, 16 Mar 2020 11:55:57 +0100 Subject: [PATCH 023/120] Implemented referencesTo classes for Account and Operation --- .../construction/references/ManyToOneReference.java | 5 +++++ .../construction/references/OneToManyReference.java | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/fr/unantes/software/construction/references/ManyToOneReference.java b/src/main/java/fr/unantes/software/construction/references/ManyToOneReference.java index 6d5854ea..77efb476 100644 --- a/src/main/java/fr/unantes/software/construction/references/ManyToOneReference.java +++ b/src/main/java/fr/unantes/software/construction/references/ManyToOneReference.java @@ -11,9 +11,14 @@ public abstract class ManyToOneReference { this.container = container; } + public List get() { + return targets; + } + public boolean contains(T value){ return this.targets.contains(value); } + public void add(T value){ if(oppositeFor(value).isSet()) { oppositeFor(value).unset(); diff --git a/src/main/java/fr/unantes/software/construction/references/OneToManyReference.java b/src/main/java/fr/unantes/software/construction/references/OneToManyReference.java index 94fc0441..290cd0ee 100644 --- a/src/main/java/fr/unantes/software/construction/references/OneToManyReference.java +++ b/src/main/java/fr/unantes/software/construction/references/OneToManyReference.java @@ -4,6 +4,11 @@ public abstract class OneToManyReference { private T target; private C container; + protected OneToManyReference(C container) { + this.container = container; + } + + public boolean isSet(){ return this.target != null; } @@ -16,7 +21,6 @@ public abstract class OneToManyReference { if(this.isSet()){ this.unset(); } - oppositeFor(target).remove(this.container); this.basicSet(value); oppositeFor(target).basicAdd(this.container); } -- GitLab From 0cb492e198eed8e66929cec08b6ede33bd4b701a Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Mon, 16 Mar 2020 15:33:46 +0100 Subject: [PATCH 024/120] Changed id integer to universal unique identifier --- .../java/fr/unantes/software/construction/Account.java | 6 +++--- .../test/fr/unantes/software/construction/AccountTest.java | 7 +++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/Account.java b/src/main/java/fr/unantes/software/construction/Account.java index 49ad9769..f7078298 100755 --- a/src/main/java/fr/unantes/software/construction/Account.java +++ b/src/main/java/fr/unantes/software/construction/Account.java @@ -6,9 +6,10 @@ import org.apache.commons.lang3.Validate; import java.io.InvalidClassException; import java.time.LocalDateTime; +import java.util.UUID; public class Account { - private final Integer id; + private final Integer id = UUID.randomUUID().variant(); public String type; private float balance; private float overdraft; @@ -23,10 +24,9 @@ public class Account { * Initializes the owner, amount, overdraft and the account id with parameters * The method also initializes the history with a new empty Vector */ - public Account(Client p, float amount, float overdraft, Integer id, String type) throws InvalidClassException { + public Account(Client p, float amount, float overdraft, String type) throws InvalidClassException { this.owner = p; this.balance = amount; - this.id = id; this.overdraft = overdraft; this.type = type; if (!type.equals("private") && !type.equals("company")) { diff --git a/src/main/test/fr/unantes/software/construction/AccountTest.java b/src/main/test/fr/unantes/software/construction/AccountTest.java index 2e731062..3db3dd22 100644 --- a/src/main/test/fr/unantes/software/construction/AccountTest.java +++ b/src/main/test/fr/unantes/software/construction/AccountTest.java @@ -13,13 +13,13 @@ class AccountTest { @BeforeEach void setUp() throws InvalidClassException { - account = new Account(new Client("John","private"),100,0,0,"private"); - accOverdraft = new Account(new Client("Meg","private"),-100,-150,1,"private"); + account = new Account(new Client("John","private"),100,0,"private"); + accOverdraft = new Account(new Client("Meg","private"),-100,-150,"private"); } @Test void testCompleteHandshake() throws InvalidClassException { - Account acc2 = new Account(new Client("Marco","private"),100,0,2,"private"); + Account acc2 = new Account(new Client("Marco","private"),100,0,"private"); Operation[] deposits = {new DepositOperation(50, LocalDateTime.now()), new DepositOperation(25, LocalDateTime.now()), @@ -33,7 +33,6 @@ class AccountTest { for(Operation each : deposits) { acc2.addHistory(each); - System.out.println(account.getHistory().contains(each)); } for(Operation each : deposits) { -- GitLab From 1dad9c4cb8813c973884804ef08cd6c980cb8f44 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Mon, 16 Mar 2020 15:34:15 +0100 Subject: [PATCH 025/120] Removed unused class --- .../software/construction/History.java | 85 ------------------- 1 file changed, 85 deletions(-) delete mode 100644 src/main/java/fr/unantes/software/construction/History.java diff --git a/src/main/java/fr/unantes/software/construction/History.java b/src/main/java/fr/unantes/software/construction/History.java deleted file mode 100644 index 8e681b25..00000000 --- a/src/main/java/fr/unantes/software/construction/History.java +++ /dev/null @@ -1,85 +0,0 @@ -package fr.unantes.software.construction; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -public class History { - - /** - * @uml.property name="history" - * @uml.associationEnd inverse="compte:fr.unantes.software.construction.Operation" multiplicity="(0 -1)" - */ - private List history = new ArrayList<>(); - - /** - * @uml.property name="history" - */ - public List getHistory() { - return history; - } - - /** - * @uml.property name="history" - */ - public void setHistory(List value) { - history = value; - } - - /** - * @uml.property name="history" - */ - public Iterator historyIterator() { - return history.iterator(); - } - - /** - * @uml.property name="history" - */ - public boolean addHistory(T element) { - return history.add(element); - } - - /** - * @uml.property name="history" - */ - public boolean removeHistory(T element) { - return history.remove(element); - } - - /** - * @uml.property name="history" - */ - public boolean isHistoryEmpty() { - return history.isEmpty(); - } - - /** - * @uml.property name="history" - */ - public void clearHistory() { - history.clear(); - } - - /** - * @uml.property name="history" - */ - public boolean containsHistory(Operation element) { - return history.contains(element); - } - - /** - * @uml.property name="history" - */ - public boolean containsAllHistory(List elements) { - return history.containsAll(elements); - } - - /** - * @uml.property name="history" - */ - public int historySize() { - return history.size(); - } - -} -- GitLab From da9ce59619d17895efff6ab045d1cc59984354f2 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Mon, 16 Mar 2020 15:35:07 +0100 Subject: [PATCH 026/120] Implemented tests for Operation subclasses --- .../construction/DepositOperationTest.java | 25 ++++++++++----- .../construction/WithdrawOperationTest.java | 32 ++++++++++++++----- 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/src/main/test/fr/unantes/software/construction/DepositOperationTest.java b/src/main/test/fr/unantes/software/construction/DepositOperationTest.java index f1d57e5e..970a31e5 100644 --- a/src/main/test/fr/unantes/software/construction/DepositOperationTest.java +++ b/src/main/test/fr/unantes/software/construction/DepositOperationTest.java @@ -4,38 +4,47 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.io.InvalidClassException; +import java.time.LocalDateTime; import static java.time.LocalDateTime.now; import static org.junit.jupiter.api.Assertions.*; class DepositOperationTest { - private DepositOperation deposit_20; + private Operation deposit_20; private Account account; @BeforeEach void setUp() throws InvalidClassException { - account = new Account(new Client("John","private"),100,0,666,"private"); + account = new Account(new Client("John","private"),100,0,"private"); + deposit_20 = new DepositOperation(20f, LocalDateTime.now()); } @Test - void completeHandshake(){ - //TODO + void completeHandshake() throws InvalidClassException { + Account account2 = new Account(new Client("Tom","private"),0,0,"private"); + + account.addHistory(deposit_20); + account2.addHistory(deposit_20); + + assertEquals(deposit_20.getAccount().get(), account2); + assertNotEquals(deposit_20.getAccount().get(), account); + assertFalse(account.getHistory().contains(deposit_20)); + assertTrue(account2.getHistory().contains(deposit_20)); } @Test void depositPositiveValue_constructOperation(){ - //TODO + assertDoesNotThrow(()-> new DepositOperation(20f, LocalDateTime.now())); } @Test void depositNegativeValue_ExceptionThrown(){ - //TODO + assertThrows(IllegalArgumentException.class, () -> new DepositOperation(-20f, LocalDateTime.now())); } @Test void getOperationType_returnDeposit(){ - //TODO + assertEquals(deposit_20.getOperationType(), "Deposit"); } - } \ No newline at end of file diff --git a/src/main/test/fr/unantes/software/construction/WithdrawOperationTest.java b/src/main/test/fr/unantes/software/construction/WithdrawOperationTest.java index 5ef29149..bef25e0b 100644 --- a/src/main/test/fr/unantes/software/construction/WithdrawOperationTest.java +++ b/src/main/test/fr/unantes/software/construction/WithdrawOperationTest.java @@ -3,32 +3,48 @@ package fr.unantes.software.construction; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.io.InvalidClassException; +import java.time.LocalDateTime; + import static org.junit.jupiter.api.Assertions.*; class WithdrawOperationTest { + private Operation withdraw_20; + private Account account; + @BeforeEach - void setUp() { + void setUp() throws InvalidClassException { + account = new Account(new Client("John","private"),100,0,"private"); + withdraw_20 = new WithdrawOperation(20f, LocalDateTime.now()); } - @Test - void completeHandshake(){ - //TODO + void completeHandshake() throws InvalidClassException { + Account account2 = new Account(new Client("Tom","private"),0,0,"private"); + + account.addHistory(withdraw_20); + account2.addHistory(withdraw_20); + + assertEquals(withdraw_20.getAccount().get(), account2); + assertNotEquals(withdraw_20.getAccount().get(), withdraw_20); + assertFalse(account.getHistory().contains(withdraw_20)); + assertTrue(account2.getHistory().contains(withdraw_20)); } @Test void withdrawPositiveValue_constructOperation(){ - //TODO + assertDoesNotThrow(()-> new WithdrawOperation(20f, LocalDateTime.now())); + } @Test void withdrawNegativeValue_ExceptionThrown(){ - //TODO + assertThrows(IllegalArgumentException.class, () -> new DepositOperation(-20f, LocalDateTime.now())); } @Test - void getOperationType_returnDeposit(){ - //TODO + void getOperationType_returnWithdraw(){ + assertEquals(withdraw_20.getOperationType(), "Withdraw"); } } \ No newline at end of file -- GitLab From bc9776bfe502d54ef35f0bb622beaa60d83e5f03 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Mon, 16 Mar 2020 15:35:56 +0100 Subject: [PATCH 027/120] modified Bank to fit new implementation of Account's id --- src/main/java/fr/unantes/software/construction/Bank.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/fr/unantes/software/construction/Bank.java b/src/main/java/fr/unantes/software/construction/Bank.java index c9272bb2..5b782033 100755 --- a/src/main/java/fr/unantes/software/construction/Bank.java +++ b/src/main/java/fr/unantes/software/construction/Bank.java @@ -153,7 +153,7 @@ public class Bank { if (p!=null){ Account a = null; try { - a = new Account(p, amount, overdraft, accountNumbers, type); + a = new Account(p, amount, overdraft, type); } catch (InvalidClassException e) { e.printStackTrace(); } -- GitLab From f9a15c77a34cbe907039f7ae52458199b3a9d26f Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Mon, 16 Mar 2020 15:36:36 +0100 Subject: [PATCH 028/120] Modified Operation to make its subclasses tests work --- src/main/java/fr/unantes/software/construction/Operation.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/fr/unantes/software/construction/Operation.java b/src/main/java/fr/unantes/software/construction/Operation.java index 3f1524dd..8943fbc6 100755 --- a/src/main/java/fr/unantes/software/construction/Operation.java +++ b/src/main/java/fr/unantes/software/construction/Operation.java @@ -2,6 +2,7 @@ package fr.unantes.software.construction; import fr.unantes.software.construction.references.ManyToOneReference; import fr.unantes.software.construction.references.OneToManyReference; +import org.apache.commons.lang3.Validate; import java.time.LocalDateTime; @@ -19,6 +20,7 @@ public abstract class Operation { * Sets the amount with the parameter */ public Operation(float amount, LocalDateTime dateTime) { + Validate.isTrue(amount > 0); this.amount = amount; this.dateTime = dateTime; } -- GitLab From 12c7ddfe3739d59a04f25564465deb67daa0b33c Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Wed, 18 Mar 2020 12:22:54 +0100 Subject: [PATCH 029/120] Change attributes and methods name to match appropriate code style --- .../software/construction/address/Card.java | 244 +++++++++--------- .../construction/address/CardList.java | 63 +++-- .../construction/address/CompanyCard.java | 52 ++-- .../construction/address/PrivateCard.java | 82 +++--- 4 files changed, 222 insertions(+), 219 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/address/Card.java b/src/main/java/fr/unantes/software/construction/address/Card.java index 7309bf87..6066b7c4 100755 --- a/src/main/java/fr/unantes/software/construction/address/Card.java +++ b/src/main/java/fr/unantes/software/construction/address/Card.java @@ -1,122 +1,122 @@ -package fr.unantes.software.construction.address; - -import fr.unantes.software.construction.Client; - -/** - * @author - * @version 1.0 - * @date 17/12/2004. - */ -public abstract class Card { - - - protected String identification; - protected GroupList _grp = new GroupList(); - protected AddressList _ad = new AddressList(); - protected PhoneList _tel= new PhoneList(); - protected MailList _mail = new MailList(); - public Client client; - - /** - * Constructeur sans parametres - */ - public Card(String nom) { - identification = nom; - } - - - /** - * @return _ad - */ - public AddressList getListeAdresse() { - return _ad; - } - - /** - * @return _tel - */ - public PhoneList getListeTel() { - return _tel; - } - - /** - * @return _mail - */ - public MailList getListeMail() { - return _mail; - } - - /** - * @return _grp - */ - public GroupList getListeGroupe() { - return _grp; - } - - - /** - * @param ad - */ - public void setListeAdresse(AddressList ad) { - _ad = ad; - } - - /** - * @param tel - */ - public void setListeTel(PhoneList tel) { - _tel = tel; - } - - /** - * @param mail - */ - public void setListeMail(MailList mail) { - _mail = mail; - } - - /** - * @param grp - */ - public void setListeGroupe(GroupList grp) { - _grp = grp; - } - - /** - * Renvoie une fusion de deux fiches. - * @param f - * @return - */ - public abstract Card merge(Card f); - - public abstract CompanyCard mergeCompanyCard(CompanyCard f); - - public abstract PrivateCard fusionFichePart(PrivateCard f); - - - public abstract String toXML(); - - public boolean memeFiche(Card f) { - return (identification.equals(f.getIdentification())); - } - - - /** - * @return _nomF nom de la fiche - */ - public String getIdentification() { - return identification; - } - - - public void setIdentification(String str) { - identification = str; - } - - public boolean equals(Object other) { - if (other instanceof Card) { - return identification.equals(((Card) other).identification); - } - return false; - } -} +package fr.unantes.software.construction.address; + +import fr.unantes.software.construction.Client; + +/** + * @author + * @version 1.0 + * @date 17/12/2004. + */ +public abstract class Card { + + + protected String identification; + protected GroupList groups = new GroupList(); + protected AddressList addresses = new AddressList(); + protected PhoneList phones = new PhoneList(); + protected MailList mails = new MailList(); + protected Client client; + + /** + * Constructeur sans parametres + */ + public Card(String id) { + identification = id; + } + + + /** + * @return addresses + */ + public AddressList getAddresses() { + return addresses; + } + + /** + * @return phones + */ + public PhoneList getPhones() { + return phones; + } + + /** + * @return mails + */ + public MailList getMails() { + return mails; + } + + /** + * @return groups + */ + public GroupList getGroups() { + return groups; + } + + + /** + * @param addresses + */ + public void setAddresses(AddressList addresses) { + this.addresses = addresses; + } + + /** + * @param phones + */ + public void setPhones(PhoneList phones) { + this.phones = phones; + } + + /** + * @param mails + */ + public void setMails(MailList mails) { + this.mails = mails; + } + + /** + * @param groups + */ + public void setGroups(GroupList groups) { + this.groups = groups; + } + + /** + * Renvoie une fusion de deux fiches. + * @param card + * @return + */ + public abstract Card merge(Card card); + + public abstract CompanyCard mergeCompanyCard(CompanyCard card); + + public abstract PrivateCard fusionFichePart(PrivateCard card); + + + public abstract String toXML(); + + public boolean identicalCard(Card card) { + return (identification.equals(card.getIdentification())); + } + + + /** + * @return _nomF nom de la fiche + */ + public String getIdentification() { + return identification; + } + + + public void setIdentification(String str) { + identification = str; + } + + public boolean equals(Object other) { + if (other instanceof Card) { + return identification.equals(((Card) other).identification); + } + return false; + } +} diff --git a/src/main/java/fr/unantes/software/construction/address/CardList.java b/src/main/java/fr/unantes/software/construction/address/CardList.java index 16041c98..0fb617cd 100755 --- a/src/main/java/fr/unantes/software/construction/address/CardList.java +++ b/src/main/java/fr/unantes/software/construction/address/CardList.java @@ -5,78 +5,77 @@ import java.util.*; public class CardList { /** Les attributs d'instance */ - protected Vector _listeCard; + protected Vector cards; /** Les Constructeurs */ public CardList(){ - _listeCard = new Vector(); + cards = new Vector(); } /** - * @param lF un objet adresse que l'on veux copier + * @param cards un objet adresse que l'on veux copier */ - public CardList (CardList lF){ - _listeCard = new Vector(); - for (Enumeration e = lF.getListeCard().elements() ; e.hasMoreElements() ;) { - _listeCard.add(e.nextElement()); + public CardList (CardList cards){ + this.cards = new Vector(); + for (Enumeration e = cards.get().elements(); e.hasMoreElements() ;) { + this.cards.add(e.nextElement()); } } /** Accesseur */ /** - * @return _listeCard + * @return cards */ - public Vector getListeCard(){ - return _listeCard; + public Vector get(){ + return cards; } /** Modificateur */ /** - * @param lF + * @param cards */ - public void setListeCard(Vector lF){ - for (Enumeration e = lF.elements() ; e.hasMoreElements() ;) { - _listeCard.add(e.nextElement()); + public void set(Vector cards){ + for (Enumeration e = cards.elements() ; e.hasMoreElements() ;) { + this.cards.add(e.nextElement()); } } /** - * @param f fiche à ajouter dans la liste + * @param card fiche à ajouter dans la liste */ - public void add(Card f){ - if(!find(f)) _listeCard.add(f); + public void add(Card card){ + if(!contains(card)) cards.add(card); } /** - * @param f fiche à supprimer de la liste + * @param card fiche à supprimer de la liste */ - public void delete(Card f){ - if (find(f)) _listeCard.remove(f); - else System.out.println("l'adresse a existe pas"); + public void delete(Card card){ + if (contains(card)) cards.remove(card); } /** - * @param f c'est la fiche rechercher + * @param card c'est la fiche rechercher */ - public boolean find(Card f){ - return _listeCard.contains(f); + public boolean contains(Card card){ + return cards.contains(card); } /** * fusion entre 2 listes dans un 3° que l'on crée - * @param lF 2° liste a faire fusionner + * @param cards 2° liste a faire fusionner * @return Liste la 3° liste fusion de la liste courante et de la liste passé en paramètre */ - public CardList merge(CardList lF){ + public CardList merge(CardList cards){ CardList res = new CardList(); boolean r; - for (Enumeration e = _listeCard.elements() ; e.hasMoreElements() ;) { + for (Enumeration e = this.cards.elements(); e.hasMoreElements() ;) { r =false; - for (Enumeration e1 = lF.getListeCard().elements() ; e1.hasMoreElements() ;) { - if(((Card)e.nextElement()).memeFiche((Card)e1.nextElement())){ + for (Enumeration e1 = cards.get().elements(); e1.hasMoreElements() ;) { + if(((Card)e.nextElement()).identicalCard((Card)e1.nextElement())){ res.add(((Card)e.nextElement()).merge((Card)e1.nextElement())); r = true; } @@ -91,7 +90,7 @@ public class CardList { public String toXML(){ String res = ""; - Enumeration e = _listeCard.elements(); + Enumeration e = cards.elements(); while (e.hasMoreElements()){ res = res + ((Card)e.nextElement()).toXML(); } @@ -102,9 +101,9 @@ public class CardList { /** * @return res */ - public String toTring(){ + public String toString(){ String res = ""; - for (Enumeration e = _listeCard.elements() ; e.hasMoreElements() ;) { + for (Enumeration e = cards.elements(); e.hasMoreElements() ;) { res = res + "/n" + e.nextElement().toString(); } return res; diff --git a/src/main/java/fr/unantes/software/construction/address/CompanyCard.java b/src/main/java/fr/unantes/software/construction/address/CompanyCard.java index 8e838e3b..8ca0d8e5 100755 --- a/src/main/java/fr/unantes/software/construction/address/CompanyCard.java +++ b/src/main/java/fr/unantes/software/construction/address/CompanyCard.java @@ -2,33 +2,35 @@ package fr.unantes.software.construction.address; public class CompanyCard extends Card { - protected String _raison_social; + protected String companyName; - public CompanyCard(String raison_social) { - super(raison_social); - _raison_social = raison_social; + public CompanyCard(String companyName) { + super(companyName); + this.companyName = companyName; } - - public String getRaisonSocial() { - return _raison_social; + public String getCompanyName() { + return companyName; } - public void setRaisonSocial(String raison_social) { - _raison_social = raison_social; + public void setCompanyName(String companyName) { + this.companyName = companyName; } - public CompanyCard mergeCompanyCard(CompanyCard f) { - CompanyCard res = new CompanyCard(identification); - f.setIdentification(identification); - f.setRaisonSocial(_raison_social); - res.setListeAdresse(_ad.fusion(f.getListeAdresse())); - res.setListeTel(_tel.merge(f.getListeTel())); - res.setListeMail(_mail.merge(f.getListeMail())); - res.setListeGroupe(_grp.merge(f.getListeGroupe())); - return res; + public CompanyCard mergeCompanyCard(CompanyCard card) { + CompanyCard newCard = new CompanyCard(identification); + + card.setIdentification(identification); + card.setCompanyName(companyName); + + newCard.setAddresses(addresses.fusion(card.getAddresses())); + newCard.setPhones(phones.merge(card.getPhones())); + newCard.setMails(mails.merge(card.getMails())); + newCard.setGroups(groups.merge(card.getGroups())); + + return newCard; } /** @@ -36,19 +38,21 @@ public class CompanyCard extends Card { * * @see Card#merge(Card) */ - public Card merge(Card f) { + + public Card merge(Card card) { Card res = new PrivateCard(identification); - if (memeFiche(f)) - res = f.mergeCompanyCard(this); + + if (identicalCard(card)) + res = card.mergeCompanyCard(this); return res; } - public PrivateCard fusionFichePart(PrivateCard f) { + public PrivateCard fusionFichePart(PrivateCard card) { return null; } public String toXML() { - return ("" + identification + _raison_social + _ad.toXML() - + _tel.toXML() + _mail.toXML() + _grp.toXML() + ""); + return ("" + identification + companyName + addresses.toXML() + + phones.toXML() + mails.toXML() + groups.toXML() + ""); } } diff --git a/src/main/java/fr/unantes/software/construction/address/PrivateCard.java b/src/main/java/fr/unantes/software/construction/address/PrivateCard.java index 443209fc..970a6663 100755 --- a/src/main/java/fr/unantes/software/construction/address/PrivateCard.java +++ b/src/main/java/fr/unantes/software/construction/address/PrivateCard.java @@ -9,86 +9,86 @@ package fr.unantes.software.construction.address; public class PrivateCard extends Card { /** attributs d'insatance */ - protected String _prenom; - protected String _nomP; + protected String firstName; + protected String lastName; - public PrivateCard(String nom, String prenom) { - super(nom + prenom); - _nomP = nom; - _prenom = prenom; + public PrivateCard(String lastName, String firstName) { + super(lastName + firstName); + this.lastName = lastName; + this.firstName = firstName; } public PrivateCard(String id) { super(id); - _nomP = ""; - _prenom = ""; + lastName = ""; + firstName = ""; } /** - * @return _nomP nom de la personne de la fiche + * @return lastName nom de la personne de la fiche */ - public String getNomP() { - return _nomP; + public String getLastName() { + return lastName; } /** - * @return _prenom prenom de la personne de la fiche + * @return firstName prenom de la personne de la fiche */ - public String getPrenom() { - return _prenom; + public String getFirstName() { + return firstName; } /** - * @return _nom nom de la personne de la fiche + * @return _nom lastName de la personne de la fiche */ - public void setNomP(String nom) { - _nomP = nom; + public void setLastName(String lastName) { + this.lastName = lastName; } /** - * @param prenom + * @param firstName * prenom de la personne de la fiche */ - public void setPrenom(String prenom) { - _prenom = prenom; + public void setPrenom(String firstName) { + this.firstName = firstName; } /** * permet la fusion entre la fiche courante et une fiche passee en parametre * dans une troisieme fiche * - * @param f fiche a faire fusionner a vec la fiche courante + * @param card fiche a faire fusionner a vec la fiche courante * @return fiche resultant de la fusion de la fiche courante et celle passee en parametre */ - public Card merge(Card f) { - Card res = new PrivateCard(identification); - if (memeFiche(f)) - res = f.fusionFichePart(this); - return res; + public Card merge(Card card) { + Card newCard = new PrivateCard(identification); + if (identicalCard(card)) + newCard = card.fusionFichePart(this); + return newCard; } - public CompanyCard mergeCompanyCard(CompanyCard f) { + public CompanyCard mergeCompanyCard(CompanyCard card) { return null; } - public PrivateCard fusionFichePart(PrivateCard f) { - PrivateCard res = new PrivateCard(identification); - res.setIdentification(identification); - res.setNomP(_nomP); - if (_prenom == null) - res.setPrenom(f.getPrenom()); + public PrivateCard fusionFichePart(PrivateCard card) { + PrivateCard newCard = new PrivateCard(identification); + newCard.setIdentification(identification); + newCard.setLastName(lastName); + if (firstName == null) + newCard.setPrenom(card.getFirstName()); else - res.setPrenom(_prenom); - res.setListeAdresse(_ad.fusion(f.getListeAdresse())); - res.setListeTel(_tel.merge(f.getListeTel())); - res.setListeMail(_mail.merge(f.getListeMail())); - res.setListeGroupe(_grp.merge(f.getListeGroupe())); - return res; + newCard.setPrenom(firstName); + newCard.setAddresses(addresses.fusion(card.getAddresses())); + newCard.setPhones(phones.merge(card.getPhones())); + newCard.setMails(mails.merge(card.getMails())); + newCard.setGroups(groups.merge(card.getGroups())); + return newCard; } public String toXML() { - return ("" + identification + _nomP + _prenom + _ad.toXML() - + _tel.toXML() + _mail.toXML() + _grp.toXML() + ""); + return ("" + identification + lastName + firstName + addresses.toXML() + + phones.toXML() + mails.toXML() + groups.toXML() + ""); } } -- GitLab From 90611d85c035b56baf7673657f9709c83f7ad9cd Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Wed, 18 Mar 2020 13:42:31 +0100 Subject: [PATCH 030/120] Change attributes and methods name to match appropriate code style --- .../construction/address/Address.java | 264 +++++++++--------- .../construction/address/AddressBook.java | 49 ++-- .../construction/address/AddressList.java | 262 ++++++++--------- .../construction/address/CompanyAddress.java | 51 ++-- .../construction/address/PrivateAddress.java | 52 ++-- .../construction/ui/TextualUserInterface.java | 4 +- 6 files changed, 342 insertions(+), 340 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/address/Address.java b/src/main/java/fr/unantes/software/construction/address/Address.java index af43d4f7..d63963d6 100755 --- a/src/main/java/fr/unantes/software/construction/address/Address.java +++ b/src/main/java/fr/unantes/software/construction/address/Address.java @@ -1,132 +1,132 @@ -package fr.unantes.software.construction.address; - -/** - * - * @author - * @version 1.0 - * @date 17/12/2004. - */ -public abstract class Address { - - protected int _voie; - protected String _rue; - protected City _ville; - protected int _code_postal; - protected String _comAd; - - public Address() { - _voie = 0; - _code_postal = 0; - } - - /** - * - * @param uneVoie le numero de la voie - * @param rue le nom de la rue - * @param ville le nom de la ville - * @param code_postal le numero de code postal - */ - public Address(int uneVoie, String rue, City ville, int code_postal, - String comAd) { - this._voie = uneVoie; - this._rue = rue; - this._ville = ville; - this._code_postal = code_postal; - this._comAd = comAd; - } - - /** - * - * - * @param f une adresse - */ - public Address(Address f) { - this._voie = f.getVoie(); - this._rue = f.getRue(); - this._ville = f.getVille(); - this._code_postal = f.getCode_postal(); - } - - - /* - * @return _voie le numetro de la voie - */ - public int getVoie() { - return _voie; - } - - /* - * @return _rue le nom de la rue - */ - public String getRue() { - return _rue; - } - - /* - * @return _ville le nom de la ville - */ - public City getVille() { - return _ville; - } - - /** - * @return _code_postal le numero du code postal - */ - public int getCode_postal() { - return _code_postal; - } - - /** - * @return _lieu_dit le nom du lieu dit - */ - public String getComAd() { - return _comAd; - } - - /** - * @param voie - */ - public void setVoie(int voie) { - _voie = voie; - } - - /** - * @param rue le nom de la rue - */ - public void setRue(String rue) { - _rue = rue; - } - - /** - * @param comAd le nom du lieu dit - */ - public void setComAd(String comAd) { - _comAd = comAd; - } - - /** - * @param ville - * le nom de la ville - */ - public void setVille(City ville) { - _ville = ville; - } - - /** - * @param code_postal le numero de code postal - */ - public void setCode_postal(int code_postal) { - _code_postal = code_postal; - } - - /** - * - */ - public String toString() { - return ("" + _voie + ", " + _rue + " " + _ville + " " + _code_postal - ); - } - - - public abstract String toXML(); -} +package fr.unantes.software.construction.address; + +/** + * + * @author + * @version 1.0 + * @date 17/12/2004. + */ +public abstract class Address { + + protected Integer streetNumber; + protected String streetName; + protected City city; + protected Integer zipCode; + protected String locality; //Lieu-dit + + public Address() { + streetNumber = 0; + zipCode = 0; + } + + /** + * + * @param streetNumber le numero de la voie + * @param street le nom de la rue + * @param city le nom de la ville + * @param zipCode le numero de code postal + */ + public Address(Integer streetNumber, String street, City city, Integer zipCode, + String locality) { + this.streetNumber = streetNumber; + this.streetName = street; + this.city = city; + this.zipCode = zipCode; + this.locality = locality; + } + + /** + * + * + * @param address une adresse + */ + public Address(Address address) { + this.streetNumber = address.getStreetNumber(); + this.streetName = address.getStreet(); + this.city = address.getCity(); + this.zipCode = address.getZipCode(); + } + + + /* + * @return streetNumber le numero de la voie + */ + public Integer getStreetNumber() { + return streetNumber; + } + + /* + * @return streetName le nom de la rue + */ + public String getStreet() { + return streetName; + } + + /* + * @return city le nom de la ville + */ + public City getCity() { + return city; + } + + /** + * @return zipCode le numero du code postal + */ + public int getZipCode() { + return zipCode; + } + + /** + * @return _lieu_dit le nom du lieu dit + */ + public String getLocality() { + return locality; + } + + /** + * @param streetNumber + */ + public void setStreetNumber(Integer streetNumber) { + this.streetNumber = streetNumber; + } + + /** + * @param street le nom de la rue + */ + public void setStreet(String street) { + streetName = street; + } + + /** + * @param locality le nom du lieu dit + */ + public void setLocality(String locality) { + this.locality = locality; + } + + /** + * @param city + * le nom de la ville + */ + public void setCity(City city) { + this.city = city; + } + + /** + * @param zipCode le numero de code postal + */ + public void setZipCode(int zipCode) { + this.zipCode = zipCode; + } + + /** + * + */ + public String toString() { + return ("" + streetNumber + ", " + streetName + " " + city + " " + zipCode + ); + } + + + public abstract String toXML(); +} diff --git a/src/main/java/fr/unantes/software/construction/address/AddressBook.java b/src/main/java/fr/unantes/software/construction/address/AddressBook.java index aa5c64e9..175968e6 100755 --- a/src/main/java/fr/unantes/software/construction/address/AddressBook.java +++ b/src/main/java/fr/unantes/software/construction/address/AddressBook.java @@ -10,53 +10,52 @@ package fr.unantes.software.construction.address; public class AddressBook { - private String _nom; - private CardList fiches; + private String name; + private CardList cards; public AddressBook() { - fiches = new CardList(); + cards = new CardList(); } - public AddressBook(String nom, CardList lF) { - _nom = nom; - fiches = new CardList(); - fiches.setListeCard(lF.getListeCard()); + public AddressBook(String name, CardList cards) { + this.name = name; + this.cards = new CardList(); + this.cards.set(cards.get()); } - public String getNom() { - return _nom; + public String getName() { + return name; } - public CardList getListe() { - return fiches; + public CardList getCards() { + return cards; } - public void setNom(String nom) { - _nom = nom; + public void setName(String names) { + name = names; } - public void setListe(CardList lF) { - fiches.setListeCard(lF.getListeCard()); + public void setCards(CardList cards) { + this.cards.set(cards.get()); } /** * Fusione deux reprtoires. Rend un nouvel objet. * - * @param r - * @param nom + * @param addressBook + * @param name * @return */ - public AddressBook merge(AddressBook r, String nom) { - AddressBook res = new AddressBook(); - CardList lF; - lF = fiches.merge(r.getListe()); - res.setNom(nom); - res.setListe(lF); - return res; + public AddressBook merge(AddressBook addressBook, String name) { + AddressBook newBook = new AddressBook(); + CardList newCard = this.cards.merge(addressBook.getCards()); + newBook.setName(name); + newBook.setCards(newCard); + return newBook; } public String toXML() { - return ("" + "" + getListe().toXML() + "" + ""); + return ("" + "" + getCards().toXML() + "" + ""); } } diff --git a/src/main/java/fr/unantes/software/construction/address/AddressList.java b/src/main/java/fr/unantes/software/construction/address/AddressList.java index 7c713e22..01d7c240 100755 --- a/src/main/java/fr/unantes/software/construction/address/AddressList.java +++ b/src/main/java/fr/unantes/software/construction/address/AddressList.java @@ -1,131 +1,131 @@ -package fr.unantes.software.construction.address; - -/** - * - * @author - * @version 1.0 - * @date 17/12/2004. - */ - -import java.util.*; - -public class AddressList { - - /** Les attributs d'instance */ - protected Vector adresses; - - /** Les Constructeurs */ - - public AddressList() { - adresses = new Vector(); - } - - /** - * @param lA un objet adresse que l'on veut copier - */ - public AddressList(AddressList lA) { - adresses = new Vector(); - for (Enumeration e = lA.getListeAdresse().elements(); e - .hasMoreElements();) { - adresses.add((Address) e.nextElement()); - } - } - - /** Accesseur */ - /** - * @return _listeAdresse - */ - public Vector getListeAdresse() { - return adresses; - } - - /** Modificateur */ - - /** - * @param listeAdresse - */ - public void setListeAdresse(Vector lA) { - for (Enumeration e = lA.elements(); e.hasMoreElements();) { - adresses.add((Address) e.nextElement()); - } - } - - /** - * @param a adresse a ajouter dans la liste - */ - public void ajouter(Address a) { - if (!rechercher(a)) - adresses.add(a); - } - - /** - * @param a adresse a supprimer de la liste - */ - public void supprimer(Address a) { - if (rechercher(a)) - adresses.remove(a); - else - System.out.println("l'adresse a existe pas"); - } - - /** - * @param a c'est l'adresse recherchee - */ - public boolean rechercher(Address a) { - return adresses.contains(a); - } - - /** - * fusion entre 2 listes dans une nouvelle. - * - * @param l l'autre liste. - * @return une nouvelle liste, fusion des deux autres. - * - */ - public AddressList fusion(AddressList lA) { - AddressList res = new AddressList(); - - /** - * on met toute les adresses de la premiere liste dans la liste de - * retour - */ - for (Enumeration e = adresses.elements(); e - .hasMoreElements();) { - res.ajouter((Address) e.nextElement()); - } - - /** - * on compare les adresses de liste de retour (adresse de la liste 1) - * avec la deuxieme liste - */ - for (Enumeration e1 = lA.getListeAdresse().elements(); e1 - .hasMoreElements();) { - if (!(res.rechercher((Address) e1.nextElement()))) { - res.ajouter((Address) e1.nextElement()); - } - } - return res; - } - - public String toXML() { - String res = ""; - Enumeration e = adresses.elements(); - while (e.hasMoreElements()) { - res = res + ((Address) e.nextElement()).toXML(); - } - res = res + ""; - return res; - } - - /** - * @return res - */ - public String toString() { - String res = ""; - for (Enumeration e = adresses.elements(); e - .hasMoreElements();) { - res = res + "/n" + e.nextElement().toString(); - } - return res; - } -} +package fr.unantes.software.construction.address; + +/** + * + * @author + * @version 1.0 + * @date 17/12/2004. + */ + +import java.util.*; + +public class AddressList { + + /** Les attributs d'instance */ + protected Vector addresses; + + /** Les Constructeurs */ + + public AddressList() { + addresses = new Vector(); + } + + /** + * @param addresses un objet adresse que l'on veut copier + */ + public AddressList(AddressList addresses) { + this.addresses = new Vector(); + for (Enumeration e = addresses.getListeAdresse().elements(); e + .hasMoreElements();) { + this.addresses.add(e.nextElement()); + } + } + + /** Accesseur */ + /** + * @return _listeAdresse + */ + public Vector getListeAdresse() { + return addresses; + } + + /** Modificateur */ + + /** + * @param addresses + */ + public void setAddresses(Vector addresses) { + for (Enumeration e = addresses.elements(); e.hasMoreElements();) { + this.addresses.add(e.nextElement()); + } + } + + /** + * @param address adresse a add dans la liste + */ + public void add(Address address) { + if (!rechercher(address)) + addresses.add(address); + } + + /** + * @param address adresse a remove de la liste + */ + public void remove(Address address) { + if (rechercher(address)) + addresses.remove(address); + else + System.out.println("l'adresse a existe pas"); + } + + /** + * @param address c'est l'adresse recherchee + */ + public boolean rechercher(Address address) { + return addresses.contains(address); + } + + /** + * fusion entre 2 listes dans une nouvelle. + * + * @param l l'autre liste. + * @return une nouvelle liste, fusion des deux autres. + * + */ + public AddressList fusion(AddressList addresses) { + AddressList newAddressList = new AddressList(); + + /** + * on met toute les addresses de la premiere liste dans la liste de + * retour + */ + for (Enumeration e = this.addresses.elements(); e + .hasMoreElements();) { + newAddressList.add((Address) e.nextElement()); + } + + /** + * on compare les addresses de liste de retour (adresse de la liste 1) + * avec la deuxieme liste + */ + for (Enumeration e1 = addresses.getListeAdresse().elements(); e1 + .hasMoreElements();) { + if (!(newAddressList.rechercher((Address) e1.nextElement()))) { + newAddressList.add((Address) e1.nextElement()); + } + } + return newAddressList; + } + + public String toXML() { + String res = ""; + Enumeration e = addresses.elements(); + while (e.hasMoreElements()) { + res = res + ((Address) e.nextElement()).toXML(); + } + res = res + ""; + return res; + } + + /** + * @return res + */ + public String toString() { + String res = ""; + for (Enumeration e = addresses.elements(); e + .hasMoreElements();) { + res = res + "/n" + e.nextElement().toString(); + } + return res; + } +} diff --git a/src/main/java/fr/unantes/software/construction/address/CompanyAddress.java b/src/main/java/fr/unantes/software/construction/address/CompanyAddress.java index 65eea569..88597d13 100755 --- a/src/main/java/fr/unantes/software/construction/address/CompanyAddress.java +++ b/src/main/java/fr/unantes/software/construction/address/CompanyAddress.java @@ -10,7 +10,7 @@ package fr.unantes.software.construction.address; public class CompanyAddress extends Address { /** Les attributs d'intance */ - private String _secteur; + private String zone; /** Les Constructeurs */ @@ -24,52 +24,53 @@ public class CompanyAddress extends Address { /** * * - * @param voie le numero de la voie - * @param rue le nom de la rue - * @param secteur le secteur de la rue - * @param ville le nom de la ville - * @param code_postal le numero de code postal + * @param streetNumber le numero de la voie + * @param street le nom de la rue + * @param zone le zone de la rue + * @param city le nom de la ville + * @param zipCode le numero de code postal */ - public CompanyAddress(int voie, String rue, City ville, int code_postal, - String comAd, String secteur) { - super(voie, rue, ville, code_postal, comAd); - _secteur = secteur; + public CompanyAddress(Integer streetNumber, String street, City city, int zipCode, + String locality, String zone) { + super(streetNumber, street, city, zipCode, locality); + this.zone = zone; } /** * - * @param f une adresse + * @param address une adresse */ - public CompanyAddress(CompanyAddress f) { - _secteur = f.getSecteur(); - _voie = f.getVoie(); - _rue = f.getRue(); - _ville = f.getVille(); - _code_postal = f.getCode_postal(); + public CompanyAddress(CompanyAddress address) { + zone = address.getZone(); + streetNumber = address.getStreetNumber(); + streetName = address.getStreet(); + city = address.getCity(); + zipCode = address.getZipCode(); } /** * @return _lieu_dit le nom du lieu dit */ - public String getSecteur() { - return _secteur; + public String getZone() { + return zone; } /** - * @param secteur le nom du lieu dit + * @param zone le nom du lieu dit */ - public void setSecteur(String secteur) { - _secteur = secteur; + public void setZone(String zone) { + this.zone = zone; } + @Override public String toString() { return super.toString() - + " " + _secteur; + + " " + zone; } public String toXML() { - return ("" + _voie + "/" + _rue + "/" + _ville + "/" - + _code_postal + "/" + _secteur + ""); + return ("" + streetNumber + "/" + streetName + "/" + city + "/" + + zipCode + "/" + zone + ""); } } diff --git a/src/main/java/fr/unantes/software/construction/address/PrivateAddress.java b/src/main/java/fr/unantes/software/construction/address/PrivateAddress.java index 96809b11..45af3df2 100755 --- a/src/main/java/fr/unantes/software/construction/address/PrivateAddress.java +++ b/src/main/java/fr/unantes/software/construction/address/PrivateAddress.java @@ -7,7 +7,7 @@ package fr.unantes.software.construction.address; */ public class PrivateAddress extends Address { - private String lieuDit; + private String locality; public PrivateAddress() { super(); @@ -16,28 +16,27 @@ public class PrivateAddress extends Address { /** * * - * @param voie le numero de la voie - * @param rue le nom de la rue - * @param lieu_dit le lieu dit de la rue - * @param ville le nom de la ville - * @param code_postal le numero de code postal + * @param streetNumber le numero de la voie + * @param street le nom de la rue + * @param city le nom de la ville + * @param zipCode le numero de code postal */ - public PrivateAddress(int voie, String rue, City ville, int code_postal, - String comAd, String lieu_dit) { - super(voie, rue, ville, code_postal, comAd); - lieuDit = lieu_dit; + public PrivateAddress(Integer streetNumber, String street, City city, int zipCode, + String locality) { + super(streetNumber, street, city, zipCode, locality); + this.locality = locality; } /** * - * @param f une adresse + * @param address une adresse */ - public PrivateAddress(PrivateAddress f) { - _voie = f.getVoie(); - _rue = f.getRue(); - lieuDit = f.getLieu_dit(); - _ville = f.getVille(); - _code_postal = f.getCode_postal(); + public PrivateAddress(PrivateAddress address) { + streetNumber = address.getStreetNumber(); + streetName = address.getStreet(); + locality = address.getLocality(); + city = address.getCity(); + zipCode = address.getZipCode(); } /** Les accesseurs */ @@ -45,25 +44,28 @@ public class PrivateAddress extends Address { /* * @return _lieu_dit le nom du lieu dit */ - public String getLieu_dit() { - return lieuDit; + @Override + public String getLocality() { + return locality; } /** Les modificateurs */ /** - * @param lieu_dit le nom du lieu dit + * @param locality le nom du lieu dit */ - public void setLieu_dit(String lieu_dit) { - lieuDit = lieu_dit; + @Override + public void setLocality(String locality) { + this.locality = locality; } + @Override public String toString() { - return ("" + _voie + ", " + _rue + " " + lieuDit + " " + _ville + " " + _code_postal); + return ("" + streetNumber + ", " + streetName + " " + locality + " " + city + " " + zipCode); } public String toXML() { - return ("" + _voie + "/" + _rue + "/" + lieuDit + "/" - + _ville + "/" + _code_postal + ""); + return ("" + streetNumber + "/" + streetName + "/" + locality + "/" + + city + "/" + zipCode + ""); } } diff --git a/src/main/java/fr/unantes/software/construction/ui/TextualUserInterface.java b/src/main/java/fr/unantes/software/construction/ui/TextualUserInterface.java index d258bb8b..4d7a376b 100755 --- a/src/main/java/fr/unantes/software/construction/ui/TextualUserInterface.java +++ b/src/main/java/fr/unantes/software/construction/ui/TextualUserInterface.java @@ -13,7 +13,7 @@ public class TextualUserInterface { /** - * These are the internal ids fir the different commands allowed for the Bank + * These are the internal ids for the different commands allowed for the Bank */ private static final int createCmd = 1; private static final int closeCmd = 2; @@ -176,7 +176,7 @@ public class TextualUserInterface { /** * Displays the list of accounts of a client - * If the client does not exist a message is dsiplayed on the console + * If the client does not exist a message is displayed on the console */ public static void displayAccountsOfClient() { System.out.println("Name of the client:"); -- GitLab From 19393b0da201e4e376a2875ca5a847737b4e73db Mon Sep 17 00:00:00 2001 From: Gries Robin Date: Thu, 19 Mar 2020 10:55:18 +0100 Subject: [PATCH 031/120] -Change use of Vector to List -Add preconditions -Add custom Exception when Account number/id is missing, instead of a generic one -specify all Iterator as Iterator or Iterator where missing --- .gitignore | 5 ++ .../AccountNumberDoesNotExistException.java | 12 ++++ .../unantes/software/construction/Bank.java | 63 +++++++++++-------- .../software/construction/BankTest.java | 15 ++--- 4 files changed, 62 insertions(+), 33 deletions(-) create mode 100644 src/main/java/fr/unantes/software/construction/AccountNumberDoesNotExistException.java diff --git a/.gitignore b/.gitignore index b3821680..6ef7dfba 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,8 @@ hs_err_pid* # Maven files target/ jenvrc + +# Gradle build, test logs +.gradle/ + +.attach_pid* \ No newline at end of file diff --git a/src/main/java/fr/unantes/software/construction/AccountNumberDoesNotExistException.java b/src/main/java/fr/unantes/software/construction/AccountNumberDoesNotExistException.java new file mode 100644 index 00000000..e29b9ba7 --- /dev/null +++ b/src/main/java/fr/unantes/software/construction/AccountNumberDoesNotExistException.java @@ -0,0 +1,12 @@ +package fr.unantes.software.construction; + +public class AccountNumberDoesNotExistException extends Exception{ + + public AccountNumberDoesNotExistException() {} + + public AccountNumberDoesNotExistException(String message) + { + super(message); + } + +} diff --git a/src/main/java/fr/unantes/software/construction/Bank.java b/src/main/java/fr/unantes/software/construction/Bank.java index 7cdb254c..3a8335f0 100755 --- a/src/main/java/fr/unantes/software/construction/Bank.java +++ b/src/main/java/fr/unantes/software/construction/Bank.java @@ -3,8 +3,11 @@ package fr.unantes.software.construction; import fr.unantes.software.construction.address.AddressBook; import java.io.InvalidClassException; +import java.util.ArrayList; import java.util.Iterator; -import java.util.Vector; +import java.util.List; +import java.util.List; +import org.apache.commons.lang3.Validate; public class Bank { private AddressBook ab; @@ -13,7 +16,7 @@ public class Bank { * @uml.property name="clients" * @uml.associationEnd inverse="bank:fr.unantes.software.construction.Client" multiplicity="(0 -1)" */ - private Vector clients; + private List clients = new ArrayList<>(); /** * this is a counter that is incremented each time a new account is created @@ -24,15 +27,14 @@ public class Bank { * @uml.property name="accounts" * @uml.associationEnd aggregation="composite" inverse="bank:fr.unantes.software.construction.Account" multiplicity="(0 -1)" */ - private Vector accounts; + private List accounts = new ArrayList<>(); /** * this constructor initializes the attributes : accountNumbers is initially 0, - * accounts and clients and initialized with new empty Vectors + * accounts and clients and initialized with new empty Lists */ public Bank() { this.accountNumbers = 0; - this.accounts = new Vector(); ab = new AddressBook(); } @@ -53,14 +55,14 @@ public class Bank { /** * @uml.property name="clients" */ - public Vector getClients() { + public List getClients() { return clients; } /** * @uml.property name="clients" */ - public void setClients(Vector value) { + public void setClients(List value) { clients = value; } @@ -68,7 +70,7 @@ public class Bank { * @uml.property name="clients" * @return */ - public Iterator clientsIterator() { + public Iterator clientsIterator() { return clients.iterator(); } @@ -76,6 +78,7 @@ public class Bank { * @uml.property name="clients" */ public boolean addClients(Client element) { + Validate.notNull(element); return clients.add(element); } @@ -83,6 +86,7 @@ public class Bank { * @uml.property name="clients" */ public boolean removeClients(Client element) { + Validate.notNull(element); return clients.remove(element); } @@ -104,13 +108,16 @@ public class Bank { * @uml.property name="clients" */ public boolean containsClients(Client element) { + Validate.notNull(element); return clients.contains(element); } /** * @uml.property name="clients" */ - public boolean containsAllClients(Vector elements) { + public boolean containsAllClients(List elements) { + Validate.notNull(elements); + Validate.notEmpty(elements); return clients.containsAll(elements); } @@ -130,13 +137,15 @@ public class Bank { } /** - * Creates an account for the person named name. + * Creates an account for the person named name. * If no client has this name, a new client object is created and * is added to the list of clients, then the account is created * If the client exists the account is created, added to the bank's * and the client's list of accounts */ public int addAccount(String name, float amount, float overdraft, String type) { + Validate.notNull(name); + Validate.notNull(type); Client p = getClient(name); //if a client named name already exists in the bank's set of clients if (p!=null){ @@ -157,15 +166,14 @@ public class Bank { * If the account exists, it is removed form the bank's list of accounts and from the owner's list of accounts. * If the account does not exist, an Exception is thrown. */ - public void closeAccount(int accountNumber) throws Exception { + public void closeAccount(int accountNumber) throws AccountNumberDoesNotExistException { Account a=getAccount(accountNumber); if (a!=null){ a.getOwner().removeAccounts(a); this.removeAccounts(a); } else{ - Exception error = new Exception("The account number "+accountNumber+" does not exist. Impossible to close this account"); - throw error; + throw new AccountNumberDoesNotExistException("The account number "+accountNumber+" does not exist. Impossible to close this account"); } } @@ -175,10 +183,10 @@ public class Bank { * Returns null if there is no client named name */ public Client getClient(String name) { - Iterator it = this.clientsIterator(); + Iterator it = this.clientsIterator(); while (it.hasNext()){ Client p = (Client)it.next(); - if(p.getName()==name){ + if(p.getName().equals(name)){ return p; } @@ -193,7 +201,7 @@ public class Bank { * The assumption is that there cannot be several accounts with the same number */ public Account getAccount(int accountNumber) { - Iterator it = this.accountsIterator(); + Iterator it = this.accountsIterator(); while (it.hasNext()){ Account a = (Account)it.next(); if(a.getId()==accountNumber) { @@ -207,14 +215,13 @@ public class Bank { * Deposits the amount on the account number accountNumber * Throws an exception if there is no account number accountNumber */ - public void deposit(int accountNumber, float amount) throws Exception { + public void deposit(int accountNumber, float amount) throws AccountNumberDoesNotExistException { Account a = getAccount(accountNumber); if (a!=null){ a.deposit(amount); } else{ - Exception error = new Exception("The account number "+accountNumber+" does not exist. Impossible to deposit"); - throw error; + throw new AccountNumberDoesNotExistException("The account number "+accountNumber+" does not exist. Impossible to deposit"); } } @@ -228,8 +235,8 @@ public class Bank { a.withdraw(amount); } else{ - Exception error = new Exception("The account number "+accountNumber+" does not exist. Impossible to withdraw"); - throw error; + throw new AccountNumberDoesNotExistException("The account number "+accountNumber+" does not exist. Impossible to withdraw"); + } } @@ -243,7 +250,7 @@ public class Bank { return client.accountsToArray(); } else{ - return null; + return new Account[]{}; } } @@ -251,7 +258,7 @@ public class Bank { * * @uml.property name="accounts" */ - public Vector getAccounts() { + public List getAccounts() { return accounts; } @@ -259,7 +266,7 @@ public class Bank { * * @uml.property name="accounts" */ - public void setAccounts(Vector value) { + public void setAccounts(List value) { accounts = value; } @@ -267,7 +274,7 @@ public class Bank { * * @uml.property name="accounts" */ - public Iterator accountsIterator() { + public Iterator accountsIterator() { return accounts.iterator(); } @@ -276,6 +283,7 @@ public class Bank { * @uml.property name="accounts" */ public boolean addAccounts(Account element) { + Validate.notNull(element); return accounts.add(element); } @@ -284,6 +292,7 @@ public class Bank { * @uml.property name="accounts" */ public boolean removeAccounts(Account element) { + Validate.notNull(element); return accounts.remove(element); } @@ -308,6 +317,7 @@ public class Bank { * @uml.property name="accounts" */ public boolean containsAccounts(Account element) { + Validate.notNull(element); return accounts.contains(element); } @@ -315,7 +325,8 @@ public class Bank { * * @uml.property name="accounts" */ - public boolean containsAllAccounts(Vector elements) { + public boolean containsAllAccounts(List elements) { + Validate.notNull(elements); return accounts.containsAll(elements); } diff --git a/src/main/test/fr/unantes/software/construction/BankTest.java b/src/main/test/fr/unantes/software/construction/BankTest.java index a8554e2a..202d23f8 100644 --- a/src/main/test/fr/unantes/software/construction/BankTest.java +++ b/src/main/test/fr/unantes/software/construction/BankTest.java @@ -16,12 +16,13 @@ public class BankTest { @BeforeEach void setup() throws InvalidClassException{ bank = new Bank(); - Client client = new Client("ComLtd","private",null); - + client = new Client("ComLtd","private"); } @Test void test_AddClients() { + assertNotNull(client); + bank.addClients(client); assertFalse(bank.isClientsEmpty()); assertTrue(bank.getClients().size() == 1); @@ -32,9 +33,9 @@ public class BankTest { void test_addAccount_WhenDoesNotExist() throws InvalidClassException{ int a = bank.addAccount("Martin", 15026.33f, 0.0f, "private" ); - assertTrue(bank.containsClients(new Client("Martin", "private",null))); + assertTrue(bank.containsClients(new Client("Martin", "private"))); assertNotNull(bank.getAccountsOfClient("Martin")); - assertEquals(bank.getAccountsOfClient("Martin")[0].getBalance(), 15026.33f); + assertEquals(15026.33f, bank.getAccountsOfClient("Martin")[0].getBalance()); } @Test @@ -42,15 +43,15 @@ public class BankTest { int a = bank.addAccount("Martin", 15026.33f, 0.0f, "private" ); int b = bank.addAccount("Martin", 42.00f, 0.0f, "private" ); - assertTrue(bank.containsClients(new Client("Martin", "private",null))); + assertTrue(bank.containsClients(new Client("Martin", "private"))); assertNotNull(bank.getAccountsOfClient("Martin")); - assertEquals(bank.getAccountsOfClient("Martin").length, 2); + assertEquals(2, bank.getAccountsOfClient("Martin").length); assertNotEquals(bank.getAccount(a), bank.getAccount(b)); } @Test void test_closeAccount_WhenDoesNotExist() { - + //TODO } } -- GitLab From 555997c49d2a8540fb600a6936c0fc2debb4c259 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Fri, 20 Mar 2020 09:11:36 +0100 Subject: [PATCH 032/120] Attribute and methods name modification to match style conventions --- .../construction/address/AddressList.java | 16 +- .../construction/address/CardList.java | 4 +- .../software/construction/address/Group.java | 54 ++-- .../construction/address/GroupList.java | 250 ++++++++-------- .../construction/address/MailList.java | 280 +++++++++--------- .../software/construction/address/Phone.java | 42 +-- .../construction/address/PhoneList.java | 254 ++++++++-------- 7 files changed, 451 insertions(+), 449 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/address/AddressList.java b/src/main/java/fr/unantes/software/construction/address/AddressList.java index 01d7c240..a17d4dbc 100755 --- a/src/main/java/fr/unantes/software/construction/address/AddressList.java +++ b/src/main/java/fr/unantes/software/construction/address/AddressList.java @@ -25,7 +25,7 @@ public class AddressList { */ public AddressList(AddressList addresses) { this.addresses = new Vector(); - for (Enumeration e = addresses.getListeAdresse().elements(); e + for (Enumeration e = addresses.get().elements(); e .hasMoreElements();) { this.addresses.add(e.nextElement()); } @@ -35,7 +35,7 @@ public class AddressList { /** * @return _listeAdresse */ - public Vector getListeAdresse() { + public Vector get() { return addresses; } @@ -44,7 +44,7 @@ public class AddressList { /** * @param addresses */ - public void setAddresses(Vector addresses) { + public void set(Vector addresses) { for (Enumeration e = addresses.elements(); e.hasMoreElements();) { this.addresses.add(e.nextElement()); } @@ -54,7 +54,7 @@ public class AddressList { * @param address adresse a add dans la liste */ public void add(Address address) { - if (!rechercher(address)) + if (!find(address)) addresses.add(address); } @@ -62,7 +62,7 @@ public class AddressList { * @param address adresse a remove de la liste */ public void remove(Address address) { - if (rechercher(address)) + if (find(address)) addresses.remove(address); else System.out.println("l'adresse a existe pas"); @@ -71,7 +71,7 @@ public class AddressList { /** * @param address c'est l'adresse recherchee */ - public boolean rechercher(Address address) { + public boolean find(Address address) { return addresses.contains(address); } @@ -98,9 +98,9 @@ public class AddressList { * on compare les addresses de liste de retour (adresse de la liste 1) * avec la deuxieme liste */ - for (Enumeration e1 = addresses.getListeAdresse().elements(); e1 + for (Enumeration e1 = addresses.get().elements(); e1 .hasMoreElements();) { - if (!(newAddressList.rechercher((Address) e1.nextElement()))) { + if (!(newAddressList.find((Address) e1.nextElement()))) { newAddressList.add((Address) e1.nextElement()); } } diff --git a/src/main/java/fr/unantes/software/construction/address/CardList.java b/src/main/java/fr/unantes/software/construction/address/CardList.java index 0fb617cd..1ec8af43 100755 --- a/src/main/java/fr/unantes/software/construction/address/CardList.java +++ b/src/main/java/fr/unantes/software/construction/address/CardList.java @@ -43,7 +43,7 @@ public class CardList { } /** - * @param card fiche à ajouter dans la liste + * @param card fiche à add dans la liste */ public void add(Card card){ if(!contains(card)) cards.add(card); @@ -56,7 +56,7 @@ public class CardList { } /** - * @param card c'est la fiche rechercher + * @param card c'est la fiche find */ public boolean contains(Card card){ return cards.contains(card); diff --git a/src/main/java/fr/unantes/software/construction/address/Group.java b/src/main/java/fr/unantes/software/construction/address/Group.java index 25b4c1fb..17b9b8be 100755 --- a/src/main/java/fr/unantes/software/construction/address/Group.java +++ b/src/main/java/fr/unantes/software/construction/address/Group.java @@ -10,56 +10,56 @@ public class Group { /** Attributs d'instance */ - protected String _grp; - protected String _comGrp; + protected String name; + protected String comment; /** Constructeurs */ public Group() { } - public Group(String grp, String comGrp) { - _grp = grp; - _comGrp = comGrp; + public Group(String name, String comment) { + this.name = name; + this.comment = comment; } /** Accesseurs */ /** - * @return _grp retroune le nom du groupe + * @return name retroune le nom du groupe */ - public String getGrp() { - return _grp; + public String getName() { + return name; } /** - * @return _comGrp commentaire sur le groupe + * @return comment commentaire sur le groupe */ - public String getComGrp() { - return _comGrp; + public String getComment() { + return comment; } /** Les Modificateurs */ /** - * @param grp + * @param name * nom du groupe */ - public void setGrp(String grp) { - _grp = grp; + public void setName(String name) { + this.name = name; } /** - * @param comGrp - * commentaire sur le group + * @param comment + * commentaire sur le name */ - public void setComGrp(String comGrp) { - _comGrp = comGrp; + public void setComment(String comment) { + this.comment = comment; } /** * */ - public boolean sameGroup(Group g) { - return (_grp.equals(g.getGrp())); + public boolean hasSameName(Group group) { + return (this.name.equals(group.getName())); } /** @@ -68,19 +68,19 @@ public class Group { * @param f fiche a faire fusionner avec la fiche courante * @return fiche resultant de la fusion de la fiche courante et celle passee en parametre */ - public Group merge(Group g) { + public Group merge(Group group) { Group res = null; - if (sameGroup(g)) { - res = new Group(_grp, ""); - if (_comGrp == null) - res.setComGrp(g.getComGrp()); + if (hasSameName(group)) { + res = new Group(name, ""); + if (comment == null) + res.setComment(group.getComment()); else - res.setComGrp(_comGrp); + res.setComment(comment); } return res; } public String toXML() { - return ("" + _grp + "/" + _comGrp + ""); + return ("" + name + "/" + comment + ""); } } diff --git a/src/main/java/fr/unantes/software/construction/address/GroupList.java b/src/main/java/fr/unantes/software/construction/address/GroupList.java index 7d0d2de0..c78aa4d6 100755 --- a/src/main/java/fr/unantes/software/construction/address/GroupList.java +++ b/src/main/java/fr/unantes/software/construction/address/GroupList.java @@ -1,125 +1,125 @@ -package fr.unantes.software.construction.address; - -import java.util.*; - -public class GroupList { - - Vector _listeGroup; - - public GroupList() { - _listeGroup = new Vector(); - } - - public GroupList(GroupList lG) { - _listeGroup = new Vector(); - for (Enumeration e = lG.getListeGroupe().elements(); e - .hasMoreElements();) { - _listeGroup.add((Group) e.nextElement()); - } - } - - /** - * @return _listeGroupe - */ - public Vector getListeGroupe() { - return _listeGroup; - } - - /** - * @param l - */ - public void setListeGroupe(Vector lG) { - for (Enumeration e = lG.elements(); e.hasMoreElements();) { - _listeGroup.add((Group) e.nextElement()); - } - } - - /** - * @param g - * element a ajouter dans la liste - */ - public void add(Group g) { - if (!find(g)) - _listeGroup.add(g); - } - - /** - * @param e - * element a supprimer de la liste - */ - public void delete(Group g) { - if (find(g)) - _listeGroup.remove(g); - else - System.out.println("le groupe n'existe pas"); - } - - /** - * @param g - * c'est l'element recherche - */ - public boolean find(Group g) { - boolean res = false; - for (Enumeration e = _listeGroup.elements(); e - .hasMoreElements();) { - if (((Group) e.nextElement()).getGrp().equals(g.getGrp())) - res = true; - } - return res; - } - - /** - * Fusion entre 2 listes dans un 3eme que l'on cree. - * - * @param l - * 2eme liste a faire fusionner - * @return La 3eme liste fusion de la liste courante et de la liste passee - * en parametre - */ - public GroupList merge(GroupList lg) { - GroupList res = new GroupList(); - - /* - * on met toute les adresses de la premiere liste dans la liste de - * retour - */ - for (Enumeration e = _listeGroup.elements(); e - .hasMoreElements();) { - res.add((Group) e.nextElement()); - } - - /* - * on compare les adresses de liste de retour (adresse de la liste 1) - * avec la 2eme liste - */ - for (Enumeration e1 = lg.getListeGroupe().elements(); e1 - .hasMoreElements();) { - if (!(res.find((Group) e1.nextElement()))) { - res.add((Group) e1.nextElement()); - } - } - return res; - } - - public String toXML() { - String res = ""; - Enumeration e = _listeGroup.elements(); - while (e.hasMoreElements()) { - res = res + ((Group) e.nextElement()).toXML(); - } - res = res + ""; - return res; - } - - /** - * @return res - */ - public String toString() { - String res = ""; - for (Enumeration e = _listeGroup.elements(); e - .hasMoreElements();) { - res = res + "/n" + e.nextElement().toString(); - } - return res; - } -} +package fr.unantes.software.construction.address; + +import java.util.*; + +public class GroupList { + + Vector groups; + + public GroupList() { + groups = new Vector(); + } + + public GroupList(GroupList groups) { + this.groups = new Vector(); + for (Enumeration e = groups.get().elements(); e + .hasMoreElements();) { + this.groups.add(e.nextElement()); + } + } + + /** + * @return _listeGroupe + */ + public Vector get() { + return groups; + } + + /** + * @param groups + */ + public void set(Vector groups) { + for (Enumeration e = groups.elements(); e.hasMoreElements();) { + this.groups.add(e.nextElement()); + } + } + + /** + * @param group + * element a add dans la liste + */ + public void add(Group group) { + if (!find(group)) + groups.add(group); + } + + /** + * @param group + * element a supprimer de la liste + */ + public void delete(Group group) { + if (find(group)) + groups.remove(group); + else + System.out.println("le groupe n'existe pas"); + } + + /** + * @param group + * c'est l'element recherche + */ + public boolean find(Group group) { + boolean res = false; + for (Enumeration e = groups.elements(); e + .hasMoreElements();) { + if (((Group) e.nextElement()).getName().equals(group.getName())) + res = true; + } + return res; + } + + /** + * Fusion entre 2 listes dans un 3eme que l'on cree. + * + * @param groups + * 2eme liste a faire fusionner + * @return La 3eme liste fusion de la liste courante et de la liste passee + * en parametre + */ + public GroupList merge(GroupList groups) { + GroupList res = new GroupList(); + + /* + * on met toute les adresses de la premiere liste dans la liste de + * retour + */ + for (Enumeration e = this.groups.elements(); e + .hasMoreElements();) { + res.add((Group) e.nextElement()); + } + + /* + * on compare les adresses de liste de retour (adresse de la liste 1) + * avec la 2eme liste + */ + for (Enumeration e1 = groups.get().elements(); e1 + .hasMoreElements();) { + if (!(res.find((Group) e1.nextElement()))) { + res.add((Group) e1.nextElement()); + } + } + return res; + } + + public String toXML() { + String res = ""; + Enumeration e = groups.elements(); + while (e.hasMoreElements()) { + res = res + ((Group) e.nextElement()).toXML(); + } + res = res + ""; + return res; + } + + /** + * @return res + */ + public String toString() { + String res = ""; + for (Enumeration e = groups.elements(); e + .hasMoreElements();) { + res = res + "/n" + e.nextElement().toString(); + } + return res; + } +} diff --git a/src/main/java/fr/unantes/software/construction/address/MailList.java b/src/main/java/fr/unantes/software/construction/address/MailList.java index 57bb0541..c796dec6 100755 --- a/src/main/java/fr/unantes/software/construction/address/MailList.java +++ b/src/main/java/fr/unantes/software/construction/address/MailList.java @@ -1,140 +1,140 @@ -package fr.unantes.software.construction.address; - -/** - * - * @author - * @version 1.0 - * @date 17/12/2004. - */ - -import java.util.*; - -public class MailList { - - private Vector _listeMail; - - public MailList() { - _listeMail = new Vector(); - } - - /** - * @param lM - * un objet adresse que l'on veut copier - */ - public MailList(MailList lM) { - _listeMail = new Vector(); - for (Enumeration e = lM.getListeMail().elements(); e - .hasMoreElements();) { - _listeMail.add((Mail) e.nextElement()); - } - } - - /** - * @return _listeMail - */ - public Vector getListeMail() { - return _listeMail; - } - - - /** - * @param lM - */ - public void setListeMail(Vector lM) { - for (Enumeration e = lM.elements(); e.hasMoreElements();) { - _listeMail.add((Mail) e.nextElement()); - } - } - - /** - * @param m - * mail a ajouter dans la liste - */ - public void ajouter(Mail m) { - if (!find(m)) - _listeMail.add(m); - // si existe deja faire la fusion des deux dans celle deja enregistree - // dans le vecteur. - /** - * else Mail b = listeMail.recupere(a); a = fusion (a, b); - * listeMail.remplacer(a); - */ - } - - /** - * @param m - * mail a supprimer de la liste - */ - public void delete(Mail m) { - if (find(m)) - _listeMail.remove(m); - else - System.out.println("le mail n'existe pas"); - } - - /** - * @param m - * c'est le mail recherche - */ - public boolean find(Mail m) { - boolean res = false; - for (Enumeration e = _listeMail.elements(); e.hasMoreElements();) { - if (((Mail) e.nextElement()).getHome().equals(m.getHome())) - res = true; - } - return res; - } - - /** - * fusion entre 2 listes dans une 3eme que l'on cree - * - * @param lM - * 2eme liste a faire fusionner - * @return Liste la 3eme liste fusion de la liste courante et de la liste - * passee en parametre - */ - public MailList merge(MailList lM) { - MailList res = new MailList(); - - /** - * on met toute les adresses de la premiere liste dans la liste de - * retour - */ - for (Enumeration e = _listeMail.elements(); e.hasMoreElements();) { - res.ajouter((Mail) e.nextElement()); - } - - /** - * on compare les adresses de liste de retour (adresse de la liste 1) - * avec la 2eme liste - */ - for (Enumeration e1 = lM.getListeMail().elements(); e1 - .hasMoreElements();) { - if (!(res.find((Mail) e1.nextElement()))) { - res.ajouter((Mail) e1.nextElement()); - } - } - return res; - } - - public String toXML() { - String res = ""; - Enumeration e = _listeMail.elements(); - while (e.hasMoreElements()) { - res = res + ((Mail) e.nextElement()).toXML(); - } - res = res + ""; - return res; - } - - /** - * @return res - */ - public String toString() { - String res = ""; - for (Enumeration e = _listeMail.elements(); e.hasMoreElements();) { - res = res + "/n" + e.nextElement().toString(); - } - return res; - } -} +package fr.unantes.software.construction.address; + +/** + * + * @author + * @version 1.0 + * @date 17/12/2004. + */ + +import java.util.*; + +public class MailList { + + private Vector mails; + + public MailList() { + mails = new Vector(); + } + + /** + * @param mails + * un objet adresse que l'on veut copier + */ + public MailList(MailList mails) { + this.mails = new Vector(); + for (Enumeration e = mails.get().elements(); e + .hasMoreElements();) { + this.mails.add(e.nextElement()); + } + } + + /** + * @return mails + */ + public Vector get() { + return mails; + } + + + /** + * @param mails + */ + public void set(Vector mails) { + for (Enumeration e = mails.elements(); e.hasMoreElements();) { + this.mails.add(e.nextElement()); + } + } + + /** + * @param mail + * mail a add dans la liste + */ + public void add(Mail mail) { + if (!find(mail)) + mails.add(mail); + // si existe deja faire la fusion des deux dans celle deja enregistree + // dans le vecteur. + /** + * else Mail b = listeMail.recupere(a); a = fusion (a, b); + * listeMail.remplacer(a); + */ + } + + /** + * @param mail + * mail a supprimer de la liste + */ + public void delete(Mail mail) { + if (find(mail)) + mails.remove(mail); + else + System.out.println("le mail n'existe pas"); + } + + /** + * @param mail + * c'est le mail recherche + */ + public boolean find(Mail mail) { + boolean res = false; + for (Enumeration e = mails.elements(); e.hasMoreElements();) { + if (((Mail) e.nextElement()).getHome().equals(mail.getHome())) + res = true; + } + return res; + } + + /** + * fusion entre 2 listes dans une 3eme que l'on cree + * + * @param mails + * 2eme liste a faire fusionner + * @return Liste la 3eme liste fusion de la liste courante et de la liste + * passee en parametre + */ + public MailList merge(MailList mails) { + MailList res = new MailList(); + + /** + * on met toute les adresses de la premiere liste dans la liste de + * retour + */ + for (Enumeration e = this.mails.elements(); e.hasMoreElements();) { + res.add((Mail) e.nextElement()); + } + + /** + * on compare les adresses de liste de retour (adresse de la liste 1) + * avec la 2eme liste + */ + for (Enumeration e1 = mails.get().elements(); e1 + .hasMoreElements();) { + if (!(res.find((Mail) e1.nextElement()))) { + res.add((Mail) e1.nextElement()); + } + } + return res; + } + + public String toXML() { + String res = ""; + Enumeration e = mails.elements(); + while (e.hasMoreElements()) { + res = res + ((Mail) e.nextElement()).toXML(); + } + res = res + ""; + return res; + } + + /** + * @return res + */ + public String toString() { + String res = ""; + for (Enumeration e = mails.elements(); e.hasMoreElements();) { + res = res + "/n" + e.nextElement().toString(); + } + return res; + } +} diff --git a/src/main/java/fr/unantes/software/construction/address/Phone.java b/src/main/java/fr/unantes/software/construction/address/Phone.java index 1da61370..11b96d27 100755 --- a/src/main/java/fr/unantes/software/construction/address/Phone.java +++ b/src/main/java/fr/unantes/software/construction/address/Phone.java @@ -1,63 +1,65 @@ package fr.unantes.software.construction.address; +import javax.annotation.Nonnull; + /** * @author * @version 1.0 * @date 17/12/2004. */ public class Phone { - - protected int number = 0; + @Nonnull + protected Integer phoneNumber; protected String comment; - public Phone(int num, String com) { - number = num; - comment = com; + public Phone(Integer phoneNumber, String comment) { + this.phoneNumber = phoneNumber; + this.comment = comment; } /** * @return _num_tel */ - public int getNumTel() { - return number; + public Integer getPhoneNumber() { + return phoneNumber; } /** * @return _com_tel */ - public String getComTel() { + public String getComment() { return comment; } /** - * @param num_tel + * @param phoneNumber */ - public void setNumTel(int num_tel) { - number = num_tel; + public void setPhoneNumber(Integer phoneNumber) { + this.phoneNumber = phoneNumber; } /** - * @param com + * @param comment */ - public void setComTel(String com) { - comment = com; + public void setComment(String comment) { + this.comment = comment; } /** * Rend un nouvel objet Tel, qui est une fusion des deux numeros * de telephone * - * @param t tel a faire fusionner avec l'objet tel courant. + * @param phone tel a faire fusionner avec l'objet tel courant. */ - public Phone merge(Phone t) { - int i = (number == 0 ? t.number : number); - String s = (comment == null ? t.comment : comment); + public Phone merge(Phone phone) { + int i = (phoneNumber == 0 ? phone.phoneNumber : phoneNumber); + String s = (comment == null ? phone.comment : comment); return new Phone(i,s); } public String toXML() { - return ("" + number + comment + ""); + return ("" + phoneNumber + comment + ""); } public boolean equals(Object another){ @@ -67,6 +69,6 @@ public class Phone { return false; Phone other = (Phone) another; - return (number == other.number) && comment.equals(other.comment); + return (phoneNumber == other.phoneNumber) && comment.equals(other.comment); } } diff --git a/src/main/java/fr/unantes/software/construction/address/PhoneList.java b/src/main/java/fr/unantes/software/construction/address/PhoneList.java index a204e989..83626f89 100755 --- a/src/main/java/fr/unantes/software/construction/address/PhoneList.java +++ b/src/main/java/fr/unantes/software/construction/address/PhoneList.java @@ -1,127 +1,127 @@ -package fr.unantes.software.construction.address; - -import java.util.*; - -public class PhoneList { - - protected Vector telephones; - - public PhoneList() { - telephones = new Vector(); - } - - /** - * @param lT un objet adresse que l'on veux copier - */ - public PhoneList(PhoneList lT) { - telephones = new Vector(); - for (Enumeration e = lT.getListeTel().elements(); e - .hasMoreElements();) { - telephones.add((Phone) e.nextElement()); - } - } - - /** - * @return _listeTel - */ - public Vector getListeTel() { - return telephones; - } - - - /** - * @param lT - */ - public void setListeTel(Vector lT) { - for (Enumeration e = lT.elements(); e.hasMoreElements();) { - telephones.add((Phone) e.nextElement()); - } - } - - /** - * @param t adresse a ajouter dans la liste - */ - public void add(Phone t) { - if (!find(t)) - telephones.add(t); - // si existe deja faire la fusion des deux dans celle deja enregistrer - // dans le vecteur. - /** - * else Tel b = listeTel.recupere(a); a = fusion (a, b); - * listeTel.remplacer(a); - */ - } - - /** - * @param t telephone a supprimer de la liste - */ - public void delete(Phone t) { - if (find(t)) - telephones.remove(t); - else - System.out.println("le telephone n'existe pas"); - } - - /** - * @param t c'est le telephone recherche - */ - public boolean find(Phone t) { - boolean res = false; - for (Enumeration e = telephones.elements(); e.hasMoreElements();) { - if (((Phone) e.nextElement()).getNumTel() == t.getNumTel()) - res = true; - } - return res; - } - - /** - * Fusion entre 2 listes dans une 3eme que l'on cree. - * - * @param l 2eme liste a faire fusionner - * @return La 3eme liste fusion de la liste courante et de la liste passee en parametre - */ - public PhoneList merge(PhoneList lT) { - PhoneList res = new PhoneList(); - - /** - * on met toute les adresses de la premiere liste dans la liste de - * retour - */ - for (Enumeration e = telephones.elements(); e.hasMoreElements();) { - res.add((Phone) e.nextElement()); - } - - /** - * on compare les adresses de liste de retour (adresse de la liste 1) - * avec la 2eme liste - */ - for (Enumeration e1 = lT.getListeTel().elements(); e1 - .hasMoreElements();) { - if (!(res.find((Phone) e1.nextElement()))) { - res.add((Phone) e1.nextElement()); - } - } - return res; - } - - public String toXML() { - String res = ""; - Enumeration e = telephones.elements(); - while (e.hasMoreElements()) { - res = res + ((Phone) e.nextElement()).toXML(); - } - res = res + ""; - return res; - } - - /** - * @return res - */ - public String toString() { - String res = ""; - for (Enumeration e = telephones.elements(); e.hasMoreElements();) { - res = res + "/n" + e.nextElement().toString(); - } - return res; - } -} +package fr.unantes.software.construction.address; + +import java.util.*; + +public class PhoneList { + + protected Vector phones; + + public PhoneList() { + phones = new Vector(); + } + + /** + * @param phones un objet adresse que l'on veux copier + */ + public PhoneList(PhoneList phones) { + this.phones = new Vector(); + for (Enumeration e = phones.get().elements(); e + .hasMoreElements();) { + this.phones.add((Phone) e.nextElement()); + } + } + + /** + * @return _listeTel + */ + public Vector get() { + return phones; + } + + + /** + * @param phones + */ + public void set(Vector phones) { + for (Enumeration e = phones.elements(); e.hasMoreElements();) { + this.phones.add((Phone) e.nextElement()); + } + } + + /** + * @param phone adresse a add dans la liste + */ + public void add(Phone phone) { + if (!find(phone)) + phones.add(phone); + // si existe deja faire la fusion des deux dans celle deja enregistrer + // dans le vecteur. + /** + * else Tel b = listeTel.recupere(a); a = fusion (a, b); + * listeTel.remplacer(a); + */ + } + + /** + * @param phone telephone a supprimer de la liste + */ + public void delete(Phone phone) { + if (find(phone)) + phones.remove(phone); + else + System.out.println("le telephone n'existe pas"); + } + + /** + * @param phone c'est le telephone recherche + */ + public boolean find(Phone phone) { + boolean res = false; + for (Enumeration e = phones.elements(); e.hasMoreElements();) { + if (((Phone) e.nextElement()).getPhoneNumber() == phone.getPhoneNumber()) + res = true; + } + return res; + } + + /** + * Fusion entre 2 listes dans une 3eme que l'on cree. + * + * @param l 2eme liste a faire fusionner + * @return La 3eme liste fusion de la liste courante et de la liste passee en parametre + */ + public PhoneList merge(PhoneList phones) { + PhoneList res = new PhoneList(); + + /** + * on met toute les adresses de la premiere liste dans la liste de + * retour + */ + for (Enumeration e = this.phones.elements(); e.hasMoreElements();) { + res.add((Phone) e.nextElement()); + } + + /** + * on compare les adresses de liste de retour (adresse de la liste 1) + * avec la 2eme liste + */ + for (Enumeration e1 = phones.get().elements(); e1 + .hasMoreElements();) { + if (!(res.find((Phone) e1.nextElement()))) { + res.add((Phone) e1.nextElement()); + } + } + return res; + } + + public String toXML() { + String res = ""; + Enumeration e = phones.elements(); + while (e.hasMoreElements()) { + res = res + ((Phone) e.nextElement()).toXML(); + } + res = res + ""; + return res; + } + + /** + * @return res + */ + public String toString() { + String res = ""; + for (Enumeration e = phones.elements(); e.hasMoreElements();) { + res = res + "/n" + e.nextElement().toString(); + } + return res; + } +} -- GitLab From d163be3a0318ab62bccdf6e90cf38128afa6dfae Mon Sep 17 00:00:00 2001 From: Gries Robin Date: Thu, 19 Mar 2020 11:37:48 +0100 Subject: [PATCH 033/120] Refactor to use *Reference from branch eleonore instead of robin as they had been duplicated (blame on me) --- .../unantes/software/construction/Client.java | 7 ++- .../construction/address/Address.java | 6 +- .../ref/ManyToOneAssociation.java | 56 ------------------- .../ref/OneToManyAssociation.java | 37 ------------ .../{ref => references}/Reference.java | 2 +- .../SingleReference.java} | 8 +-- 6 files changed, 13 insertions(+), 103 deletions(-) delete mode 100644 src/main/java/fr/unantes/software/construction/ref/ManyToOneAssociation.java delete mode 100644 src/main/java/fr/unantes/software/construction/ref/OneToManyAssociation.java rename src/main/java/fr/unantes/software/construction/{ref => references}/Reference.java (57%) rename src/main/java/fr/unantes/software/construction/{ref/OneToOneAssociation.java => references/SingleReference.java} (74%) diff --git a/src/main/java/fr/unantes/software/construction/Client.java b/src/main/java/fr/unantes/software/construction/Client.java index a68b5aae..1c3f8b12 100644 --- a/src/main/java/fr/unantes/software/construction/Client.java +++ b/src/main/java/fr/unantes/software/construction/Client.java @@ -3,8 +3,8 @@ package fr.unantes.software.construction; import fr.unantes.software.construction.address.Address; import fr.unantes.software.construction.address.Card; +import fr.unantes.software.construction.references.SingleReference; import java.io.InvalidClassException; -import java.lang.ref.Reference; public class Client { @@ -18,14 +18,15 @@ public class Client { /** * Inner class to describe Bidirectional Monovalued Association between Address & Client */ - private class OneToOneAssociation extends fr.unantes.software.construction.ref.OneToOneAssociation { + private class OneToOneAssociation extends + SingleReference { public OneToOneAssociation(Client a) { super(a); } @Override - public fr.unantes.software.construction.ref.OneToOneAssociation oppositeFor(Object target) { + public SingleReference oppositeFor(Object target) { return refAddress; } } diff --git a/src/main/java/fr/unantes/software/construction/address/Address.java b/src/main/java/fr/unantes/software/construction/address/Address.java index 845b23ed..26cf3a4b 100755 --- a/src/main/java/fr/unantes/software/construction/address/Address.java +++ b/src/main/java/fr/unantes/software/construction/address/Address.java @@ -1,6 +1,7 @@ package fr.unantes.software.construction.address; import fr.unantes.software.construction.Client; +import fr.unantes.software.construction.references.SingleReference; /** * @author @@ -157,14 +158,15 @@ public abstract class Address { /** * Inner class to describe Bidirectional Monovalued Association between Address & Client */ - protected class OneToOneAssociation extends fr.unantes.software.construction.ref.OneToOneAssociation { + protected class OneToOneAssociation extends + SingleReference { public OneToOneAssociation(Address a) { super(a); } @Override - public fr.unantes.software.construction.ref.OneToOneAssociation oppositeFor(Object target) { + public SingleReference oppositeFor(Object target) { return refClient; } } diff --git a/src/main/java/fr/unantes/software/construction/ref/ManyToOneAssociation.java b/src/main/java/fr/unantes/software/construction/ref/ManyToOneAssociation.java deleted file mode 100644 index 1151691d..00000000 --- a/src/main/java/fr/unantes/software/construction/ref/ManyToOneAssociation.java +++ /dev/null @@ -1,56 +0,0 @@ -package fr.unantes.software.construction.ref; - -import java.util.ArrayList; -import java.util.List; -import org.apache.commons.lang3.Validate; - -public abstract class ManyToOneAssociation implements Reference{ - - private final C container; - private List targets = new ArrayList<>(); - - - public ManyToOneAssociation(C c){ - this.container = c; - } - - public C getContainer(){ return container; } - - public List getTargets(){ return targets; } - - public boolean isEmpty(){ return targets.isEmpty(); } - - public boolean contains(T elt){ - Validate.notEmpty(targets); - return targets.contains(elt); - } - - public void basicRemove(T elt){ - targets.remove(elt); - } - - public void basicAdd(T newTarget){ - targets.add(newTarget); - } - - public void remove(T elt){ - if (isEmpty()) return; - else { - this.oppositeFor(elt).unset(); - this.basicRemove(elt); - oppositeFor(elt).basicSet(container); - //TODO check if these last 2 line should be swapped - } - } - - public void add(T newElt){ - if (oppositeFor(newElt).isSet()) { - oppositeFor(newElt).unset(); - } - oppositeFor(newElt).basicSet(container); - this.basicAdd(newElt); - } - - public abstract OneToManyAssociation oppositeFor(T target); - -} diff --git a/src/main/java/fr/unantes/software/construction/ref/OneToManyAssociation.java b/src/main/java/fr/unantes/software/construction/ref/OneToManyAssociation.java deleted file mode 100644 index 400d2915..00000000 --- a/src/main/java/fr/unantes/software/construction/ref/OneToManyAssociation.java +++ /dev/null @@ -1,37 +0,0 @@ -package fr.unantes.software.construction.ref; - -import org.apache.commons.lang3.Validate; - -public abstract class OneToManyAssociation implements Reference{ - - private final C container; - private T target; - - public OneToManyAssociation(C c) { - this.container = c; - } - - public T getTarget() { return target; } - - public C getContainer() { - Validate.notNull(container); - return container; - } - - - public boolean isSet() { return target != null; } - - public void basicUnset() { target = null; } - - public void basicSet(T newTarget) { - Validate.notNull(container); - target = newTarget; - } - - //TODO - public void unset() {} - public void set(C c) {} - - - public abstract ManyToOneAssociation oppositeFor(T target); -} diff --git a/src/main/java/fr/unantes/software/construction/ref/Reference.java b/src/main/java/fr/unantes/software/construction/references/Reference.java similarity index 57% rename from src/main/java/fr/unantes/software/construction/ref/Reference.java rename to src/main/java/fr/unantes/software/construction/references/Reference.java index c10b2789..06c6c05d 100644 --- a/src/main/java/fr/unantes/software/construction/ref/Reference.java +++ b/src/main/java/fr/unantes/software/construction/references/Reference.java @@ -1,4 +1,4 @@ -package fr.unantes.software.construction.ref; +package fr.unantes.software.construction.references; public interface Reference { boolean isSet(); diff --git a/src/main/java/fr/unantes/software/construction/ref/OneToOneAssociation.java b/src/main/java/fr/unantes/software/construction/references/SingleReference.java similarity index 74% rename from src/main/java/fr/unantes/software/construction/ref/OneToOneAssociation.java rename to src/main/java/fr/unantes/software/construction/references/SingleReference.java index 4c9becea..8c506a6b 100644 --- a/src/main/java/fr/unantes/software/construction/ref/OneToOneAssociation.java +++ b/src/main/java/fr/unantes/software/construction/references/SingleReference.java @@ -1,12 +1,12 @@ -package fr.unantes.software.construction.ref; +package fr.unantes.software.construction.references; -public abstract class OneToOneAssociation implements Reference{ +public abstract class SingleReference implements Reference{ private final C container; private T target; - public OneToOneAssociation(C c) { + public SingleReference(C c) { this.container = c; } @@ -42,5 +42,5 @@ public abstract class OneToOneAssociation implements Reference{ oppositeFor(target).basicUnset(); } - public abstract OneToOneAssociation oppositeFor(T target); + public abstract SingleReference oppositeFor(T target); } -- GitLab From 7383547025f3400df32676a19d66b3908af9250f Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Fri, 20 Mar 2020 09:11:36 +0100 Subject: [PATCH 034/120] Attribute and methods name modification to match style conventions --- .../construction/address/AddressList.java | 16 +- .../construction/address/CardList.java | 4 +- .../software/construction/address/Group.java | 54 ++-- .../construction/address/GroupList.java | 250 ++++++++-------- .../construction/address/MailList.java | 280 +++++++++--------- .../software/construction/address/Phone.java | 42 +-- .../construction/address/PhoneList.java | 254 ++++++++-------- 7 files changed, 451 insertions(+), 449 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/address/AddressList.java b/src/main/java/fr/unantes/software/construction/address/AddressList.java index 01d7c240..a17d4dbc 100755 --- a/src/main/java/fr/unantes/software/construction/address/AddressList.java +++ b/src/main/java/fr/unantes/software/construction/address/AddressList.java @@ -25,7 +25,7 @@ public class AddressList { */ public AddressList(AddressList addresses) { this.addresses = new Vector(); - for (Enumeration e = addresses.getListeAdresse().elements(); e + for (Enumeration e = addresses.get().elements(); e .hasMoreElements();) { this.addresses.add(e.nextElement()); } @@ -35,7 +35,7 @@ public class AddressList { /** * @return _listeAdresse */ - public Vector getListeAdresse() { + public Vector get() { return addresses; } @@ -44,7 +44,7 @@ public class AddressList { /** * @param addresses */ - public void setAddresses(Vector addresses) { + public void set(Vector addresses) { for (Enumeration e = addresses.elements(); e.hasMoreElements();) { this.addresses.add(e.nextElement()); } @@ -54,7 +54,7 @@ public class AddressList { * @param address adresse a add dans la liste */ public void add(Address address) { - if (!rechercher(address)) + if (!find(address)) addresses.add(address); } @@ -62,7 +62,7 @@ public class AddressList { * @param address adresse a remove de la liste */ public void remove(Address address) { - if (rechercher(address)) + if (find(address)) addresses.remove(address); else System.out.println("l'adresse a existe pas"); @@ -71,7 +71,7 @@ public class AddressList { /** * @param address c'est l'adresse recherchee */ - public boolean rechercher(Address address) { + public boolean find(Address address) { return addresses.contains(address); } @@ -98,9 +98,9 @@ public class AddressList { * on compare les addresses de liste de retour (adresse de la liste 1) * avec la deuxieme liste */ - for (Enumeration e1 = addresses.getListeAdresse().elements(); e1 + for (Enumeration e1 = addresses.get().elements(); e1 .hasMoreElements();) { - if (!(newAddressList.rechercher((Address) e1.nextElement()))) { + if (!(newAddressList.find((Address) e1.nextElement()))) { newAddressList.add((Address) e1.nextElement()); } } diff --git a/src/main/java/fr/unantes/software/construction/address/CardList.java b/src/main/java/fr/unantes/software/construction/address/CardList.java index 0fb617cd..1ec8af43 100755 --- a/src/main/java/fr/unantes/software/construction/address/CardList.java +++ b/src/main/java/fr/unantes/software/construction/address/CardList.java @@ -43,7 +43,7 @@ public class CardList { } /** - * @param card fiche à ajouter dans la liste + * @param card fiche à add dans la liste */ public void add(Card card){ if(!contains(card)) cards.add(card); @@ -56,7 +56,7 @@ public class CardList { } /** - * @param card c'est la fiche rechercher + * @param card c'est la fiche find */ public boolean contains(Card card){ return cards.contains(card); diff --git a/src/main/java/fr/unantes/software/construction/address/Group.java b/src/main/java/fr/unantes/software/construction/address/Group.java index 25b4c1fb..17b9b8be 100755 --- a/src/main/java/fr/unantes/software/construction/address/Group.java +++ b/src/main/java/fr/unantes/software/construction/address/Group.java @@ -10,56 +10,56 @@ public class Group { /** Attributs d'instance */ - protected String _grp; - protected String _comGrp; + protected String name; + protected String comment; /** Constructeurs */ public Group() { } - public Group(String grp, String comGrp) { - _grp = grp; - _comGrp = comGrp; + public Group(String name, String comment) { + this.name = name; + this.comment = comment; } /** Accesseurs */ /** - * @return _grp retroune le nom du groupe + * @return name retroune le nom du groupe */ - public String getGrp() { - return _grp; + public String getName() { + return name; } /** - * @return _comGrp commentaire sur le groupe + * @return comment commentaire sur le groupe */ - public String getComGrp() { - return _comGrp; + public String getComment() { + return comment; } /** Les Modificateurs */ /** - * @param grp + * @param name * nom du groupe */ - public void setGrp(String grp) { - _grp = grp; + public void setName(String name) { + this.name = name; } /** - * @param comGrp - * commentaire sur le group + * @param comment + * commentaire sur le name */ - public void setComGrp(String comGrp) { - _comGrp = comGrp; + public void setComment(String comment) { + this.comment = comment; } /** * */ - public boolean sameGroup(Group g) { - return (_grp.equals(g.getGrp())); + public boolean hasSameName(Group group) { + return (this.name.equals(group.getName())); } /** @@ -68,19 +68,19 @@ public class Group { * @param f fiche a faire fusionner avec la fiche courante * @return fiche resultant de la fusion de la fiche courante et celle passee en parametre */ - public Group merge(Group g) { + public Group merge(Group group) { Group res = null; - if (sameGroup(g)) { - res = new Group(_grp, ""); - if (_comGrp == null) - res.setComGrp(g.getComGrp()); + if (hasSameName(group)) { + res = new Group(name, ""); + if (comment == null) + res.setComment(group.getComment()); else - res.setComGrp(_comGrp); + res.setComment(comment); } return res; } public String toXML() { - return ("" + _grp + "/" + _comGrp + ""); + return ("" + name + "/" + comment + ""); } } diff --git a/src/main/java/fr/unantes/software/construction/address/GroupList.java b/src/main/java/fr/unantes/software/construction/address/GroupList.java index 7d0d2de0..c78aa4d6 100755 --- a/src/main/java/fr/unantes/software/construction/address/GroupList.java +++ b/src/main/java/fr/unantes/software/construction/address/GroupList.java @@ -1,125 +1,125 @@ -package fr.unantes.software.construction.address; - -import java.util.*; - -public class GroupList { - - Vector _listeGroup; - - public GroupList() { - _listeGroup = new Vector(); - } - - public GroupList(GroupList lG) { - _listeGroup = new Vector(); - for (Enumeration e = lG.getListeGroupe().elements(); e - .hasMoreElements();) { - _listeGroup.add((Group) e.nextElement()); - } - } - - /** - * @return _listeGroupe - */ - public Vector getListeGroupe() { - return _listeGroup; - } - - /** - * @param l - */ - public void setListeGroupe(Vector lG) { - for (Enumeration e = lG.elements(); e.hasMoreElements();) { - _listeGroup.add((Group) e.nextElement()); - } - } - - /** - * @param g - * element a ajouter dans la liste - */ - public void add(Group g) { - if (!find(g)) - _listeGroup.add(g); - } - - /** - * @param e - * element a supprimer de la liste - */ - public void delete(Group g) { - if (find(g)) - _listeGroup.remove(g); - else - System.out.println("le groupe n'existe pas"); - } - - /** - * @param g - * c'est l'element recherche - */ - public boolean find(Group g) { - boolean res = false; - for (Enumeration e = _listeGroup.elements(); e - .hasMoreElements();) { - if (((Group) e.nextElement()).getGrp().equals(g.getGrp())) - res = true; - } - return res; - } - - /** - * Fusion entre 2 listes dans un 3eme que l'on cree. - * - * @param l - * 2eme liste a faire fusionner - * @return La 3eme liste fusion de la liste courante et de la liste passee - * en parametre - */ - public GroupList merge(GroupList lg) { - GroupList res = new GroupList(); - - /* - * on met toute les adresses de la premiere liste dans la liste de - * retour - */ - for (Enumeration e = _listeGroup.elements(); e - .hasMoreElements();) { - res.add((Group) e.nextElement()); - } - - /* - * on compare les adresses de liste de retour (adresse de la liste 1) - * avec la 2eme liste - */ - for (Enumeration e1 = lg.getListeGroupe().elements(); e1 - .hasMoreElements();) { - if (!(res.find((Group) e1.nextElement()))) { - res.add((Group) e1.nextElement()); - } - } - return res; - } - - public String toXML() { - String res = ""; - Enumeration e = _listeGroup.elements(); - while (e.hasMoreElements()) { - res = res + ((Group) e.nextElement()).toXML(); - } - res = res + ""; - return res; - } - - /** - * @return res - */ - public String toString() { - String res = ""; - for (Enumeration e = _listeGroup.elements(); e - .hasMoreElements();) { - res = res + "/n" + e.nextElement().toString(); - } - return res; - } -} +package fr.unantes.software.construction.address; + +import java.util.*; + +public class GroupList { + + Vector groups; + + public GroupList() { + groups = new Vector(); + } + + public GroupList(GroupList groups) { + this.groups = new Vector(); + for (Enumeration e = groups.get().elements(); e + .hasMoreElements();) { + this.groups.add(e.nextElement()); + } + } + + /** + * @return _listeGroupe + */ + public Vector get() { + return groups; + } + + /** + * @param groups + */ + public void set(Vector groups) { + for (Enumeration e = groups.elements(); e.hasMoreElements();) { + this.groups.add(e.nextElement()); + } + } + + /** + * @param group + * element a add dans la liste + */ + public void add(Group group) { + if (!find(group)) + groups.add(group); + } + + /** + * @param group + * element a supprimer de la liste + */ + public void delete(Group group) { + if (find(group)) + groups.remove(group); + else + System.out.println("le groupe n'existe pas"); + } + + /** + * @param group + * c'est l'element recherche + */ + public boolean find(Group group) { + boolean res = false; + for (Enumeration e = groups.elements(); e + .hasMoreElements();) { + if (((Group) e.nextElement()).getName().equals(group.getName())) + res = true; + } + return res; + } + + /** + * Fusion entre 2 listes dans un 3eme que l'on cree. + * + * @param groups + * 2eme liste a faire fusionner + * @return La 3eme liste fusion de la liste courante et de la liste passee + * en parametre + */ + public GroupList merge(GroupList groups) { + GroupList res = new GroupList(); + + /* + * on met toute les adresses de la premiere liste dans la liste de + * retour + */ + for (Enumeration e = this.groups.elements(); e + .hasMoreElements();) { + res.add((Group) e.nextElement()); + } + + /* + * on compare les adresses de liste de retour (adresse de la liste 1) + * avec la 2eme liste + */ + for (Enumeration e1 = groups.get().elements(); e1 + .hasMoreElements();) { + if (!(res.find((Group) e1.nextElement()))) { + res.add((Group) e1.nextElement()); + } + } + return res; + } + + public String toXML() { + String res = ""; + Enumeration e = groups.elements(); + while (e.hasMoreElements()) { + res = res + ((Group) e.nextElement()).toXML(); + } + res = res + ""; + return res; + } + + /** + * @return res + */ + public String toString() { + String res = ""; + for (Enumeration e = groups.elements(); e + .hasMoreElements();) { + res = res + "/n" + e.nextElement().toString(); + } + return res; + } +} diff --git a/src/main/java/fr/unantes/software/construction/address/MailList.java b/src/main/java/fr/unantes/software/construction/address/MailList.java index 57bb0541..c796dec6 100755 --- a/src/main/java/fr/unantes/software/construction/address/MailList.java +++ b/src/main/java/fr/unantes/software/construction/address/MailList.java @@ -1,140 +1,140 @@ -package fr.unantes.software.construction.address; - -/** - * - * @author - * @version 1.0 - * @date 17/12/2004. - */ - -import java.util.*; - -public class MailList { - - private Vector _listeMail; - - public MailList() { - _listeMail = new Vector(); - } - - /** - * @param lM - * un objet adresse que l'on veut copier - */ - public MailList(MailList lM) { - _listeMail = new Vector(); - for (Enumeration e = lM.getListeMail().elements(); e - .hasMoreElements();) { - _listeMail.add((Mail) e.nextElement()); - } - } - - /** - * @return _listeMail - */ - public Vector getListeMail() { - return _listeMail; - } - - - /** - * @param lM - */ - public void setListeMail(Vector lM) { - for (Enumeration e = lM.elements(); e.hasMoreElements();) { - _listeMail.add((Mail) e.nextElement()); - } - } - - /** - * @param m - * mail a ajouter dans la liste - */ - public void ajouter(Mail m) { - if (!find(m)) - _listeMail.add(m); - // si existe deja faire la fusion des deux dans celle deja enregistree - // dans le vecteur. - /** - * else Mail b = listeMail.recupere(a); a = fusion (a, b); - * listeMail.remplacer(a); - */ - } - - /** - * @param m - * mail a supprimer de la liste - */ - public void delete(Mail m) { - if (find(m)) - _listeMail.remove(m); - else - System.out.println("le mail n'existe pas"); - } - - /** - * @param m - * c'est le mail recherche - */ - public boolean find(Mail m) { - boolean res = false; - for (Enumeration e = _listeMail.elements(); e.hasMoreElements();) { - if (((Mail) e.nextElement()).getHome().equals(m.getHome())) - res = true; - } - return res; - } - - /** - * fusion entre 2 listes dans une 3eme que l'on cree - * - * @param lM - * 2eme liste a faire fusionner - * @return Liste la 3eme liste fusion de la liste courante et de la liste - * passee en parametre - */ - public MailList merge(MailList lM) { - MailList res = new MailList(); - - /** - * on met toute les adresses de la premiere liste dans la liste de - * retour - */ - for (Enumeration e = _listeMail.elements(); e.hasMoreElements();) { - res.ajouter((Mail) e.nextElement()); - } - - /** - * on compare les adresses de liste de retour (adresse de la liste 1) - * avec la 2eme liste - */ - for (Enumeration e1 = lM.getListeMail().elements(); e1 - .hasMoreElements();) { - if (!(res.find((Mail) e1.nextElement()))) { - res.ajouter((Mail) e1.nextElement()); - } - } - return res; - } - - public String toXML() { - String res = ""; - Enumeration e = _listeMail.elements(); - while (e.hasMoreElements()) { - res = res + ((Mail) e.nextElement()).toXML(); - } - res = res + ""; - return res; - } - - /** - * @return res - */ - public String toString() { - String res = ""; - for (Enumeration e = _listeMail.elements(); e.hasMoreElements();) { - res = res + "/n" + e.nextElement().toString(); - } - return res; - } -} +package fr.unantes.software.construction.address; + +/** + * + * @author + * @version 1.0 + * @date 17/12/2004. + */ + +import java.util.*; + +public class MailList { + + private Vector mails; + + public MailList() { + mails = new Vector(); + } + + /** + * @param mails + * un objet adresse que l'on veut copier + */ + public MailList(MailList mails) { + this.mails = new Vector(); + for (Enumeration e = mails.get().elements(); e + .hasMoreElements();) { + this.mails.add(e.nextElement()); + } + } + + /** + * @return mails + */ + public Vector get() { + return mails; + } + + + /** + * @param mails + */ + public void set(Vector mails) { + for (Enumeration e = mails.elements(); e.hasMoreElements();) { + this.mails.add(e.nextElement()); + } + } + + /** + * @param mail + * mail a add dans la liste + */ + public void add(Mail mail) { + if (!find(mail)) + mails.add(mail); + // si existe deja faire la fusion des deux dans celle deja enregistree + // dans le vecteur. + /** + * else Mail b = listeMail.recupere(a); a = fusion (a, b); + * listeMail.remplacer(a); + */ + } + + /** + * @param mail + * mail a supprimer de la liste + */ + public void delete(Mail mail) { + if (find(mail)) + mails.remove(mail); + else + System.out.println("le mail n'existe pas"); + } + + /** + * @param mail + * c'est le mail recherche + */ + public boolean find(Mail mail) { + boolean res = false; + for (Enumeration e = mails.elements(); e.hasMoreElements();) { + if (((Mail) e.nextElement()).getHome().equals(mail.getHome())) + res = true; + } + return res; + } + + /** + * fusion entre 2 listes dans une 3eme que l'on cree + * + * @param mails + * 2eme liste a faire fusionner + * @return Liste la 3eme liste fusion de la liste courante et de la liste + * passee en parametre + */ + public MailList merge(MailList mails) { + MailList res = new MailList(); + + /** + * on met toute les adresses de la premiere liste dans la liste de + * retour + */ + for (Enumeration e = this.mails.elements(); e.hasMoreElements();) { + res.add((Mail) e.nextElement()); + } + + /** + * on compare les adresses de liste de retour (adresse de la liste 1) + * avec la 2eme liste + */ + for (Enumeration e1 = mails.get().elements(); e1 + .hasMoreElements();) { + if (!(res.find((Mail) e1.nextElement()))) { + res.add((Mail) e1.nextElement()); + } + } + return res; + } + + public String toXML() { + String res = ""; + Enumeration e = mails.elements(); + while (e.hasMoreElements()) { + res = res + ((Mail) e.nextElement()).toXML(); + } + res = res + ""; + return res; + } + + /** + * @return res + */ + public String toString() { + String res = ""; + for (Enumeration e = mails.elements(); e.hasMoreElements();) { + res = res + "/n" + e.nextElement().toString(); + } + return res; + } +} diff --git a/src/main/java/fr/unantes/software/construction/address/Phone.java b/src/main/java/fr/unantes/software/construction/address/Phone.java index 1da61370..11b96d27 100755 --- a/src/main/java/fr/unantes/software/construction/address/Phone.java +++ b/src/main/java/fr/unantes/software/construction/address/Phone.java @@ -1,63 +1,65 @@ package fr.unantes.software.construction.address; +import javax.annotation.Nonnull; + /** * @author * @version 1.0 * @date 17/12/2004. */ public class Phone { - - protected int number = 0; + @Nonnull + protected Integer phoneNumber; protected String comment; - public Phone(int num, String com) { - number = num; - comment = com; + public Phone(Integer phoneNumber, String comment) { + this.phoneNumber = phoneNumber; + this.comment = comment; } /** * @return _num_tel */ - public int getNumTel() { - return number; + public Integer getPhoneNumber() { + return phoneNumber; } /** * @return _com_tel */ - public String getComTel() { + public String getComment() { return comment; } /** - * @param num_tel + * @param phoneNumber */ - public void setNumTel(int num_tel) { - number = num_tel; + public void setPhoneNumber(Integer phoneNumber) { + this.phoneNumber = phoneNumber; } /** - * @param com + * @param comment */ - public void setComTel(String com) { - comment = com; + public void setComment(String comment) { + this.comment = comment; } /** * Rend un nouvel objet Tel, qui est une fusion des deux numeros * de telephone * - * @param t tel a faire fusionner avec l'objet tel courant. + * @param phone tel a faire fusionner avec l'objet tel courant. */ - public Phone merge(Phone t) { - int i = (number == 0 ? t.number : number); - String s = (comment == null ? t.comment : comment); + public Phone merge(Phone phone) { + int i = (phoneNumber == 0 ? phone.phoneNumber : phoneNumber); + String s = (comment == null ? phone.comment : comment); return new Phone(i,s); } public String toXML() { - return ("" + number + comment + ""); + return ("" + phoneNumber + comment + ""); } public boolean equals(Object another){ @@ -67,6 +69,6 @@ public class Phone { return false; Phone other = (Phone) another; - return (number == other.number) && comment.equals(other.comment); + return (phoneNumber == other.phoneNumber) && comment.equals(other.comment); } } diff --git a/src/main/java/fr/unantes/software/construction/address/PhoneList.java b/src/main/java/fr/unantes/software/construction/address/PhoneList.java index a204e989..83626f89 100755 --- a/src/main/java/fr/unantes/software/construction/address/PhoneList.java +++ b/src/main/java/fr/unantes/software/construction/address/PhoneList.java @@ -1,127 +1,127 @@ -package fr.unantes.software.construction.address; - -import java.util.*; - -public class PhoneList { - - protected Vector telephones; - - public PhoneList() { - telephones = new Vector(); - } - - /** - * @param lT un objet adresse que l'on veux copier - */ - public PhoneList(PhoneList lT) { - telephones = new Vector(); - for (Enumeration e = lT.getListeTel().elements(); e - .hasMoreElements();) { - telephones.add((Phone) e.nextElement()); - } - } - - /** - * @return _listeTel - */ - public Vector getListeTel() { - return telephones; - } - - - /** - * @param lT - */ - public void setListeTel(Vector lT) { - for (Enumeration e = lT.elements(); e.hasMoreElements();) { - telephones.add((Phone) e.nextElement()); - } - } - - /** - * @param t adresse a ajouter dans la liste - */ - public void add(Phone t) { - if (!find(t)) - telephones.add(t); - // si existe deja faire la fusion des deux dans celle deja enregistrer - // dans le vecteur. - /** - * else Tel b = listeTel.recupere(a); a = fusion (a, b); - * listeTel.remplacer(a); - */ - } - - /** - * @param t telephone a supprimer de la liste - */ - public void delete(Phone t) { - if (find(t)) - telephones.remove(t); - else - System.out.println("le telephone n'existe pas"); - } - - /** - * @param t c'est le telephone recherche - */ - public boolean find(Phone t) { - boolean res = false; - for (Enumeration e = telephones.elements(); e.hasMoreElements();) { - if (((Phone) e.nextElement()).getNumTel() == t.getNumTel()) - res = true; - } - return res; - } - - /** - * Fusion entre 2 listes dans une 3eme que l'on cree. - * - * @param l 2eme liste a faire fusionner - * @return La 3eme liste fusion de la liste courante et de la liste passee en parametre - */ - public PhoneList merge(PhoneList lT) { - PhoneList res = new PhoneList(); - - /** - * on met toute les adresses de la premiere liste dans la liste de - * retour - */ - for (Enumeration e = telephones.elements(); e.hasMoreElements();) { - res.add((Phone) e.nextElement()); - } - - /** - * on compare les adresses de liste de retour (adresse de la liste 1) - * avec la 2eme liste - */ - for (Enumeration e1 = lT.getListeTel().elements(); e1 - .hasMoreElements();) { - if (!(res.find((Phone) e1.nextElement()))) { - res.add((Phone) e1.nextElement()); - } - } - return res; - } - - public String toXML() { - String res = ""; - Enumeration e = telephones.elements(); - while (e.hasMoreElements()) { - res = res + ((Phone) e.nextElement()).toXML(); - } - res = res + ""; - return res; - } - - /** - * @return res - */ - public String toString() { - String res = ""; - for (Enumeration e = telephones.elements(); e.hasMoreElements();) { - res = res + "/n" + e.nextElement().toString(); - } - return res; - } -} +package fr.unantes.software.construction.address; + +import java.util.*; + +public class PhoneList { + + protected Vector phones; + + public PhoneList() { + phones = new Vector(); + } + + /** + * @param phones un objet adresse que l'on veux copier + */ + public PhoneList(PhoneList phones) { + this.phones = new Vector(); + for (Enumeration e = phones.get().elements(); e + .hasMoreElements();) { + this.phones.add((Phone) e.nextElement()); + } + } + + /** + * @return _listeTel + */ + public Vector get() { + return phones; + } + + + /** + * @param phones + */ + public void set(Vector phones) { + for (Enumeration e = phones.elements(); e.hasMoreElements();) { + this.phones.add((Phone) e.nextElement()); + } + } + + /** + * @param phone adresse a add dans la liste + */ + public void add(Phone phone) { + if (!find(phone)) + phones.add(phone); + // si existe deja faire la fusion des deux dans celle deja enregistrer + // dans le vecteur. + /** + * else Tel b = listeTel.recupere(a); a = fusion (a, b); + * listeTel.remplacer(a); + */ + } + + /** + * @param phone telephone a supprimer de la liste + */ + public void delete(Phone phone) { + if (find(phone)) + phones.remove(phone); + else + System.out.println("le telephone n'existe pas"); + } + + /** + * @param phone c'est le telephone recherche + */ + public boolean find(Phone phone) { + boolean res = false; + for (Enumeration e = phones.elements(); e.hasMoreElements();) { + if (((Phone) e.nextElement()).getPhoneNumber() == phone.getPhoneNumber()) + res = true; + } + return res; + } + + /** + * Fusion entre 2 listes dans une 3eme que l'on cree. + * + * @param l 2eme liste a faire fusionner + * @return La 3eme liste fusion de la liste courante et de la liste passee en parametre + */ + public PhoneList merge(PhoneList phones) { + PhoneList res = new PhoneList(); + + /** + * on met toute les adresses de la premiere liste dans la liste de + * retour + */ + for (Enumeration e = this.phones.elements(); e.hasMoreElements();) { + res.add((Phone) e.nextElement()); + } + + /** + * on compare les adresses de liste de retour (adresse de la liste 1) + * avec la 2eme liste + */ + for (Enumeration e1 = phones.get().elements(); e1 + .hasMoreElements();) { + if (!(res.find((Phone) e1.nextElement()))) { + res.add((Phone) e1.nextElement()); + } + } + return res; + } + + public String toXML() { + String res = ""; + Enumeration e = phones.elements(); + while (e.hasMoreElements()) { + res = res + ((Phone) e.nextElement()).toXML(); + } + res = res + ""; + return res; + } + + /** + * @return res + */ + public String toString() { + String res = ""; + for (Enumeration e = phones.elements(); e.hasMoreElements();) { + res = res + "/n" + e.nextElement().toString(); + } + return res; + } +} -- GitLab From 3aab727537dad1e0d3f2a494bb772fc4495982bd Mon Sep 17 00:00:00 2001 From: Gries Robin Date: Fri, 20 Mar 2020 17:31:27 +0100 Subject: [PATCH 035/120] Change primitive array to List and Iterator where needed in Bank and Client --- .../unantes/software/construction/Bank.java | 34 +++++++-------- .../unantes/software/construction/Client.java | 43 +++++-------------- .../construction/ui/TextualUserInterface.java | 18 ++++---- .../software/construction/BankTest.java | 27 ++++++++---- 4 files changed, 54 insertions(+), 68 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/Bank.java b/src/main/java/fr/unantes/software/construction/Bank.java index 3a8335f0..41d167d8 100755 --- a/src/main/java/fr/unantes/software/construction/Bank.java +++ b/src/main/java/fr/unantes/software/construction/Bank.java @@ -6,7 +6,6 @@ import java.io.InvalidClassException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import java.util.List; import org.apache.commons.lang3.Validate; public class Bank { @@ -146,18 +145,20 @@ public class Bank { public int addAccount(String name, float amount, float overdraft, String type) { Validate.notNull(name); Validate.notNull(type); - Client p = getClient(name); - //if a client named name already exists in the bank's set of clients - if (p!=null){ - Account a = null; - try { - a = new Account(p, amount, overdraft, type); - } catch (InvalidClassException e) { - e.printStackTrace(); + Client pending = getClient(name); + + try { + if (pending == null) { + pending = new Client(name, type); + this.addClients(pending); } - p.addAccounts(a); - this.addAccounts(a); + Account acc = new Account(pending, amount, overdraft, type); + this.addAccounts(acc); + pending.addAccounts(acc); + } catch (InvalidClassException e) { + e.printStackTrace(); } + return accountNumbers; } @@ -244,14 +245,8 @@ public class Bank { * Returns the collection of accounts of the client named name * If there is no client named name, the method returns null */ - public Account[] getAccountsOfClient(String name) { - Client client = getClient(name); - if (client!=null){ - return client.accountsToArray(); - } - else{ - return new Account[]{}; - } + public Iterator clientAccountsIterator(String name) { + return this.getClient(name).getAccountsIterator(); } /** @@ -284,6 +279,7 @@ public class Bank { */ public boolean addAccounts(Account element) { Validate.notNull(element); + accountNumbers++; return accounts.add(element); } diff --git a/src/main/java/fr/unantes/software/construction/Client.java b/src/main/java/fr/unantes/software/construction/Client.java index 1c3f8b12..c556de77 100644 --- a/src/main/java/fr/unantes/software/construction/Client.java +++ b/src/main/java/fr/unantes/software/construction/Client.java @@ -5,12 +5,15 @@ import fr.unantes.software.construction.address.Card; import fr.unantes.software.construction.references.SingleReference; import java.io.InvalidClassException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; public class Client { public String name; public String role; - public Account[] accounts; + public List accounts= new ArrayList<>(100); private short accountSize = 0; public Card card; private OneToOneAssociation refAddress = new OneToOneAssociation<>(this); @@ -39,7 +42,6 @@ public class Client { this.name = name; this.role = role; - accounts = new Account[100]; } public Address getAddress(){ @@ -73,16 +75,8 @@ public class Client { * * @uml.property name="accounts" */ - public Account[] getAccounts() { - return accounts; - } - - /** - * - * @uml.property name="accounts" - */ - public void setAccounts(Account[] value) { - accounts = value; + public Iterator getAccountsIterator() { + return accounts.iterator(); } /** @@ -90,18 +84,15 @@ public class Client { * @uml.property name="accounts" */ public void addAccounts(Account element) { - accounts[accountSize++] = element; + accounts.add(element); } /** * * @uml.property name="accounts" */ - public boolean removeAccounts(Account element) { - for (int i = 0; i < accountSize; i++) { - if (element == accounts [i]) accounts[i] = null; - } - return true; + public void removeAccounts(Account element) { + accounts.remove(element); } /** @@ -129,10 +120,7 @@ public class Client { * @uml.property name="accounts" */ public boolean containsAccounts(Account element) { - for (int i = 0; i < accountSize; i++) { - if (accounts[accountSize] == element) return true; - } - return false; + return accounts.contains(element); } @@ -141,18 +129,9 @@ public class Client { * @uml.property name="accounts" */ public int accountsSize() { - return accounts.length; + return accounts.size(); } - /** - * - * @uml.property name="accounts" - */ - public Account[] accountsToArray() { - return accounts; - } - - public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; diff --git a/src/main/java/fr/unantes/software/construction/ui/TextualUserInterface.java b/src/main/java/fr/unantes/software/construction/ui/TextualUserInterface.java index 6bfb5f76..5016349f 100755 --- a/src/main/java/fr/unantes/software/construction/ui/TextualUserInterface.java +++ b/src/main/java/fr/unantes/software/construction/ui/TextualUserInterface.java @@ -176,19 +176,21 @@ public class TextualUserInterface { /** * Displays the list of accounts of a client - * If the client does not exist a message is dsiplayed on the console + * If the client does not exist a message is displayed on the console */ public static void displayAccountsOfClient() { System.out.println("Name of the client:"); String name = readLine(); - Account[] accounts = bank.getAccountsOfClient(name); - if (accounts!=null){ - for (int i = 0; i it = bank.clientAccountsIterator("Martin"); + int counter = 0; + + assertTrue(bank.clientAccountsIterator("Martin").hasNext()); + + while(it.hasNext()) { + it.next(); + counter++; + } + assertEquals(2, counter); - assertTrue(bank.containsClients(new Client("Martin", "private"))); - assertNotNull(bank.getAccountsOfClient("Martin")); - assertEquals(2, bank.getAccountsOfClient("Martin").length); assertNotEquals(bank.getAccount(a), bank.getAccount(b)); } @Test void test_closeAccount_WhenDoesNotExist() { - //TODO + assertFalse(bank.removeClients(client)); } } -- GitLab From ae5d5e47af4b30b3433433a31dd0a9ca72e26f4b Mon Sep 17 00:00:00 2001 From: Gries Robin Date: Fri, 20 Mar 2020 17:32:22 +0100 Subject: [PATCH 036/120] Impl Association between Client and Address --- .../construction/address/Address.java | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/address/Address.java b/src/main/java/fr/unantes/software/construction/address/Address.java index 26cf3a4b..b406d106 100755 --- a/src/main/java/fr/unantes/software/construction/address/Address.java +++ b/src/main/java/fr/unantes/software/construction/address/Address.java @@ -17,6 +17,23 @@ public abstract class Address { protected String comAd; protected OneToOneAssociation refClient = new OneToOneAssociation<>(this); + /** + * Inner class to describe Bidirectional Monovalued Association between Address & Client + */ + protected class OneToOneAssociation extends + SingleReference { + + public OneToOneAssociation(Address a) { + super(a); + } + + @Override + public SingleReference oppositeFor(Object target) { + return refClient; + } + } + + public Address() { this.voie = 0; this.codePostal = 0; @@ -55,7 +72,7 @@ public abstract class Address { this.refClient.set(c); } - //TODO copie d'address ? cela semble violer l'association 0..1 Client - Address? + //TODO this ctor seems to be copying an Address which could violate the one to one association with CLient /** * @param f une adresse */ @@ -66,8 +83,8 @@ public abstract class Address { this.codePostal = f.getCode_postal(); } - public OneToOneAssociation getRefClient() { - return refClient; + public Client getClient() { + return (Client)refClient.get(); } public void setRefClient(OneToOneAssociation refClient) { @@ -144,9 +161,6 @@ public abstract class Address { codePostal = code_postal; } - /** - * - */ public String toString() { return ("" + voie + ", " + rue + " " + ville + " " + codePostal ); @@ -155,19 +169,5 @@ public abstract class Address { public abstract String toXML(); - /** - * Inner class to describe Bidirectional Monovalued Association between Address & Client - */ - protected class OneToOneAssociation extends - SingleReference { - - public OneToOneAssociation(Address a) { - super(a); - } - @Override - public SingleReference oppositeFor(Object target) { - return refClient; - } - } } -- GitLab From ebc490a27321c2154786f1c9cf03d4f29df6856b Mon Sep 17 00:00:00 2001 From: Gries Robin Date: Fri, 20 Mar 2020 17:32:22 +0100 Subject: [PATCH 037/120] Impl Association between Client and Address --- .../construction/address/Address.java | 43 +++++++++---------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/address/Address.java b/src/main/java/fr/unantes/software/construction/address/Address.java index 26cf3a4b..70a15e9a 100755 --- a/src/main/java/fr/unantes/software/construction/address/Address.java +++ b/src/main/java/fr/unantes/software/construction/address/Address.java @@ -17,6 +17,23 @@ public abstract class Address { protected String comAd; protected OneToOneAssociation refClient = new OneToOneAssociation<>(this); + /** + * Inner class to describe Bidirectional Monovalued Association between Address & Client + */ + protected class OneToOneAssociation extends + SingleReference { + + public OneToOneAssociation(Address a) { + super(a); + } + + @Override + public SingleReference oppositeFor(Object target) { + return refClient; + } + } + + public Address() { this.voie = 0; this.codePostal = 0; @@ -46,16 +63,15 @@ public abstract class Address { * @param codePostal le numero de code postal */ public Address(int numero, String rue, City ville, int codePostal, - String comAd, Client c) { + String comAd) { this.voie = numero; this.rue = rue; this.ville = ville; this.codePostal = codePostal; this.comAd = comAd; - this.refClient.set(c); } - //TODO copie d'address ? cela semble violer l'association 0..1 Client - Address? + //TODO this ctor seems to be copying an Address which could violate the one to one association with CLient /** * @param f une adresse */ @@ -66,8 +82,8 @@ public abstract class Address { this.codePostal = f.getCode_postal(); } - public OneToOneAssociation getRefClient() { - return refClient; + public Client getClient() { + return (Client)refClient.get(); } public void setRefClient(OneToOneAssociation refClient) { @@ -144,9 +160,6 @@ public abstract class Address { codePostal = code_postal; } - /** - * - */ public String toString() { return ("" + voie + ", " + rue + " " + ville + " " + codePostal ); @@ -155,19 +168,5 @@ public abstract class Address { public abstract String toXML(); - /** - * Inner class to describe Bidirectional Monovalued Association between Address & Client - */ - protected class OneToOneAssociation extends - SingleReference { - - public OneToOneAssociation(Address a) { - super(a); - } - @Override - public SingleReference oppositeFor(Object target) { - return refClient; - } - } } -- GitLab From 814f81d53ff96b078a25f88eb2ee785b47f62f34 Mon Sep 17 00:00:00 2001 From: Gries Robin Date: Fri, 20 Mar 2020 18:00:23 +0100 Subject: [PATCH 038/120] Impl Monovalued Bidirectional Association Client<->Address --- .../unantes/software/construction/Client.java | 43 +++++-------------- .../construction/address/Address.java | 43 +++++++++---------- .../references/SingleReference.java | 4 +- 3 files changed, 34 insertions(+), 56 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/Client.java b/src/main/java/fr/unantes/software/construction/Client.java index 1c3f8b12..c556de77 100644 --- a/src/main/java/fr/unantes/software/construction/Client.java +++ b/src/main/java/fr/unantes/software/construction/Client.java @@ -5,12 +5,15 @@ import fr.unantes.software.construction.address.Card; import fr.unantes.software.construction.references.SingleReference; import java.io.InvalidClassException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; public class Client { public String name; public String role; - public Account[] accounts; + public List accounts= new ArrayList<>(100); private short accountSize = 0; public Card card; private OneToOneAssociation refAddress = new OneToOneAssociation<>(this); @@ -39,7 +42,6 @@ public class Client { this.name = name; this.role = role; - accounts = new Account[100]; } public Address getAddress(){ @@ -73,16 +75,8 @@ public class Client { * * @uml.property name="accounts" */ - public Account[] getAccounts() { - return accounts; - } - - /** - * - * @uml.property name="accounts" - */ - public void setAccounts(Account[] value) { - accounts = value; + public Iterator getAccountsIterator() { + return accounts.iterator(); } /** @@ -90,18 +84,15 @@ public class Client { * @uml.property name="accounts" */ public void addAccounts(Account element) { - accounts[accountSize++] = element; + accounts.add(element); } /** * * @uml.property name="accounts" */ - public boolean removeAccounts(Account element) { - for (int i = 0; i < accountSize; i++) { - if (element == accounts [i]) accounts[i] = null; - } - return true; + public void removeAccounts(Account element) { + accounts.remove(element); } /** @@ -129,10 +120,7 @@ public class Client { * @uml.property name="accounts" */ public boolean containsAccounts(Account element) { - for (int i = 0; i < accountSize; i++) { - if (accounts[accountSize] == element) return true; - } - return false; + return accounts.contains(element); } @@ -141,18 +129,9 @@ public class Client { * @uml.property name="accounts" */ public int accountsSize() { - return accounts.length; + return accounts.size(); } - /** - * - * @uml.property name="accounts" - */ - public Account[] accountsToArray() { - return accounts; - } - - public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; diff --git a/src/main/java/fr/unantes/software/construction/address/Address.java b/src/main/java/fr/unantes/software/construction/address/Address.java index 26cf3a4b..70a15e9a 100755 --- a/src/main/java/fr/unantes/software/construction/address/Address.java +++ b/src/main/java/fr/unantes/software/construction/address/Address.java @@ -17,6 +17,23 @@ public abstract class Address { protected String comAd; protected OneToOneAssociation refClient = new OneToOneAssociation<>(this); + /** + * Inner class to describe Bidirectional Monovalued Association between Address & Client + */ + protected class OneToOneAssociation extends + SingleReference { + + public OneToOneAssociation(Address a) { + super(a); + } + + @Override + public SingleReference oppositeFor(Object target) { + return refClient; + } + } + + public Address() { this.voie = 0; this.codePostal = 0; @@ -46,16 +63,15 @@ public abstract class Address { * @param codePostal le numero de code postal */ public Address(int numero, String rue, City ville, int codePostal, - String comAd, Client c) { + String comAd) { this.voie = numero; this.rue = rue; this.ville = ville; this.codePostal = codePostal; this.comAd = comAd; - this.refClient.set(c); } - //TODO copie d'address ? cela semble violer l'association 0..1 Client - Address? + //TODO this ctor seems to be copying an Address which could violate the one to one association with CLient /** * @param f une adresse */ @@ -66,8 +82,8 @@ public abstract class Address { this.codePostal = f.getCode_postal(); } - public OneToOneAssociation getRefClient() { - return refClient; + public Client getClient() { + return (Client)refClient.get(); } public void setRefClient(OneToOneAssociation refClient) { @@ -144,9 +160,6 @@ public abstract class Address { codePostal = code_postal; } - /** - * - */ public String toString() { return ("" + voie + ", " + rue + " " + ville + " " + codePostal ); @@ -155,19 +168,5 @@ public abstract class Address { public abstract String toXML(); - /** - * Inner class to describe Bidirectional Monovalued Association between Address & Client - */ - protected class OneToOneAssociation extends - SingleReference { - - public OneToOneAssociation(Address a) { - super(a); - } - @Override - public SingleReference oppositeFor(Object target) { - return refClient; - } - } } diff --git a/src/main/java/fr/unantes/software/construction/references/SingleReference.java b/src/main/java/fr/unantes/software/construction/references/SingleReference.java index 8c506a6b..e9c7dd3f 100644 --- a/src/main/java/fr/unantes/software/construction/references/SingleReference.java +++ b/src/main/java/fr/unantes/software/construction/references/SingleReference.java @@ -18,11 +18,11 @@ public abstract class SingleReference implements Reference{ return target != null; } - public void basicUnset(){ + private void basicUnset(){ target = null; } - public void basicSet(T newTarget){ + private void basicSet(T newTarget){ target = newTarget; } -- GitLab From 80f49302043e56efe70dfd53ce94f3d845620e97 Mon Sep 17 00:00:00 2001 From: Gries Robin Date: Fri, 20 Mar 2020 18:16:19 +0100 Subject: [PATCH 039/120] Change class Bank to use List and Iterator instead of primitive array --- .../unantes/software/construction/Bank.java | 34 ++++++++----------- .../construction/ui/TextualUserInterface.java | 18 +++++----- .../software/construction/BankTest.java | 27 ++++++++++----- 3 files changed, 43 insertions(+), 36 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/Bank.java b/src/main/java/fr/unantes/software/construction/Bank.java index 3a8335f0..41d167d8 100755 --- a/src/main/java/fr/unantes/software/construction/Bank.java +++ b/src/main/java/fr/unantes/software/construction/Bank.java @@ -6,7 +6,6 @@ import java.io.InvalidClassException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import java.util.List; import org.apache.commons.lang3.Validate; public class Bank { @@ -146,18 +145,20 @@ public class Bank { public int addAccount(String name, float amount, float overdraft, String type) { Validate.notNull(name); Validate.notNull(type); - Client p = getClient(name); - //if a client named name already exists in the bank's set of clients - if (p!=null){ - Account a = null; - try { - a = new Account(p, amount, overdraft, type); - } catch (InvalidClassException e) { - e.printStackTrace(); + Client pending = getClient(name); + + try { + if (pending == null) { + pending = new Client(name, type); + this.addClients(pending); } - p.addAccounts(a); - this.addAccounts(a); + Account acc = new Account(pending, amount, overdraft, type); + this.addAccounts(acc); + pending.addAccounts(acc); + } catch (InvalidClassException e) { + e.printStackTrace(); } + return accountNumbers; } @@ -244,14 +245,8 @@ public class Bank { * Returns the collection of accounts of the client named name * If there is no client named name, the method returns null */ - public Account[] getAccountsOfClient(String name) { - Client client = getClient(name); - if (client!=null){ - return client.accountsToArray(); - } - else{ - return new Account[]{}; - } + public Iterator clientAccountsIterator(String name) { + return this.getClient(name).getAccountsIterator(); } /** @@ -284,6 +279,7 @@ public class Bank { */ public boolean addAccounts(Account element) { Validate.notNull(element); + accountNumbers++; return accounts.add(element); } diff --git a/src/main/java/fr/unantes/software/construction/ui/TextualUserInterface.java b/src/main/java/fr/unantes/software/construction/ui/TextualUserInterface.java index 6bfb5f76..5016349f 100755 --- a/src/main/java/fr/unantes/software/construction/ui/TextualUserInterface.java +++ b/src/main/java/fr/unantes/software/construction/ui/TextualUserInterface.java @@ -176,19 +176,21 @@ public class TextualUserInterface { /** * Displays the list of accounts of a client - * If the client does not exist a message is dsiplayed on the console + * If the client does not exist a message is displayed on the console */ public static void displayAccountsOfClient() { System.out.println("Name of the client:"); String name = readLine(); - Account[] accounts = bank.getAccountsOfClient(name); - if (accounts!=null){ - for (int i = 0; i it = bank.clientAccountsIterator("Martin"); + int counter = 0; + + assertTrue(bank.clientAccountsIterator("Martin").hasNext()); + + while(it.hasNext()) { + it.next(); + counter++; + } + assertEquals(2, counter); - assertTrue(bank.containsClients(new Client("Martin", "private"))); - assertNotNull(bank.getAccountsOfClient("Martin")); - assertEquals(2, bank.getAccountsOfClient("Martin").length); assertNotEquals(bank.getAccount(a), bank.getAccount(b)); } @Test void test_closeAccount_WhenDoesNotExist() { - //TODO + assertFalse(bank.removeClients(client)); } } -- GitLab From f3b88ae5e183920785b5ea84de91d2390043d81f Mon Sep 17 00:00:00 2001 From: Gries Robin Date: Fri, 20 Mar 2020 18:19:31 +0100 Subject: [PATCH 040/120] Change attrivute visibility public -> private --- .../java/fr/unantes/software/construction/Client.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/Client.java b/src/main/java/fr/unantes/software/construction/Client.java index c556de77..244e1612 100644 --- a/src/main/java/fr/unantes/software/construction/Client.java +++ b/src/main/java/fr/unantes/software/construction/Client.java @@ -11,11 +11,11 @@ import java.util.List; public class Client { - public String name; - public String role; - public List accounts= new ArrayList<>(100); + private String name; + private String role; + private List accounts= new ArrayList<>(100); private short accountSize = 0; - public Card card; + private Card card; private OneToOneAssociation refAddress = new OneToOneAssociation<>(this); /** -- GitLab From ce58a2deb4e5bebb92ac909bbef1ac1ddf21bff4 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Sat, 21 Mar 2020 15:02:49 +0100 Subject: [PATCH 041/120] Added tests for bidirectional association between Account & Client --- .../software/construction/AccountTest.java | 28 +++++++--- .../software/construction/ClientTest.java | 55 +++++++++++++++++++ 2 files changed, 76 insertions(+), 7 deletions(-) create mode 100644 src/main/test/fr/unantes/software/construction/ClientTest.java diff --git a/src/main/test/fr/unantes/software/construction/AccountTest.java b/src/main/test/fr/unantes/software/construction/AccountTest.java index 3db3dd22..f44ede50 100644 --- a/src/main/test/fr/unantes/software/construction/AccountTest.java +++ b/src/main/test/fr/unantes/software/construction/AccountTest.java @@ -18,7 +18,7 @@ class AccountTest { } @Test - void testCompleteHandshake() throws InvalidClassException { + void testCompleteHandshakeWith_Operation() throws InvalidClassException { Account acc2 = new Account(new Client("Marco","private"),100,0,"private"); Operation[] deposits = {new DepositOperation(50, LocalDateTime.now()), @@ -42,7 +42,7 @@ class AccountTest { } @Test - void testBidirectionalAdd() { + void testBidirectionalAddWith_Operation() { Operation[] deposits = {new DepositOperation(50, LocalDateTime.now()), new DepositOperation(25, LocalDateTime.now()), new DepositOperation(25, LocalDateTime.now()), @@ -136,7 +136,7 @@ class AccountTest { } @Test - void setBalance_overOverdraft_Suceed() { + void setBalance_overOverdraft_Succeed() { account.setBalance(50); assertEquals(account.getBalance(),50); assertTrue(accOverdraft.getBalance() > accOverdraft.getOverdraft()); @@ -151,15 +151,29 @@ class AccountTest { @Test void setOwner() throws InvalidClassException { - Client oldClient = account.getOwner(); + Client oldClient = account.getOwner().get(); Client newClient = new Client("Timmy", "private"); assertNotEquals(account.getOwner(), newClient); - assertEquals(account.getOwner(), oldClient); + assertEquals(account.getOwner().get(), oldClient); account.setOwner(newClient); - assertNotEquals(account.getOwner(), oldClient); - assertEquals(account.getOwner(), newClient); + assertNotEquals(account.getOwner().get(), oldClient); + assertEquals(account.getOwner().get(), newClient); } + @Test + void completeHandshakeWith_Client() throws InvalidClassException { + Client client1 = new Client("Boule","private"); + Client client2 = new Client("Bill","private"); + + client1.addAccounts(account); + client2.addAccounts(account); + + assertEquals(account.getOwner().get(), client2); + assertNotEquals(account.getOwner().get(), client1); + assertFalse(client1.getAccounts().contains(account)); + assertTrue(client2.getAccounts().contains(account)); + } + } \ No newline at end of file diff --git a/src/main/test/fr/unantes/software/construction/ClientTest.java b/src/main/test/fr/unantes/software/construction/ClientTest.java new file mode 100644 index 00000000..215d9550 --- /dev/null +++ b/src/main/test/fr/unantes/software/construction/ClientTest.java @@ -0,0 +1,55 @@ +package fr.unantes.software.construction; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.InvalidClassException; + +import static org.junit.jupiter.api.Assertions.*; + +class ClientTest { + Client client; + @BeforeEach + void setUp() throws InvalidClassException { + client = new Client("Tom","private"); + } + @Test + void testCompleteHandshakeWith_Account() throws InvalidClassException { + Client client2 = new Client("Jerry","private"); + + Account[] accounts = {new Account(client,50, 0,"private"), + new Account(client,200, 0,"private"), + new Account(client,10, 0,"company") + }; + + for(Account each : accounts) { + assertEquals(client, each.getOwner().get()); + } + + for(Account each : accounts) { + client2.addAccounts(each); + } + + for(Account each : accounts) { + assertFalse(client.getAccounts().contains(each)); + assertEquals(client2, each.getOwner().get()); + } + } + + @Test + void testBidirectionalAddWith_Account() throws InvalidClassException { + Account[] accounts = {new Account(client,50, 0,"private"), + new Account(client,200, 0,"private"), + new Account(client,10, 0,"company") + }; + + for(Account each : accounts) { + client.addAccounts(each); + } + + for(Account each : accounts) { + assertTrue(client.getAccounts().contains(each)); + assertEquals(client, each.getOwner().get()); + } + } +} \ No newline at end of file -- GitLab From 73c75b1944a87b39333d50e19ec5d716958c1009 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Sat, 21 Mar 2020 15:04:31 +0100 Subject: [PATCH 042/120] Modified current classes to match new association tests --- .../software/construction/Account.java | 24 ++++++------ .../unantes/software/construction/Client.java | 39 ++++++++----------- .../references/ManyToOneReference.java | 8 +++- 3 files changed, 35 insertions(+), 36 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/Account.java b/src/main/java/fr/unantes/software/construction/Account.java index f7078298..3370fdb8 100755 --- a/src/main/java/fr/unantes/software/construction/Account.java +++ b/src/main/java/fr/unantes/software/construction/Account.java @@ -13,6 +13,12 @@ public class Account { public String type; private float balance; private float overdraft; + public final OneToManyReference owner = new OneToManyReference(this) { + @Override + public ManyToOneReference oppositeFor(Client target) { + return target.getAccounts(); + } + }; public ManyToOneReference operations = new ManyToOneReference(this) { @Override public OneToManyReference oppositeFor(Operation target) { @@ -25,7 +31,7 @@ public class Account { * The method also initializes the history with a new empty Vector */ public Account(Client p, float amount, float overdraft, String type) throws InvalidClassException { - this.owner = p; + owner.set(p); this.balance = amount; this.overdraft = overdraft; this.type = type; @@ -119,20 +125,12 @@ public class Account { return id; } - /** - * - * @uml.property name="owner" - * @uml.associationEnd inverse="accounts:fr.unantes.software.construction.Client" multiplicity="(0 1)" - * - */ - public Client owner; - /** * * @uml.property name="owner" * */ - public Client getOwner() { + public OneToManyReference getOwner() { return owner; } @@ -142,9 +140,9 @@ public class Account { * */ public void setOwner(Client owner) { - if (owner.role.equals("private") && !this.type.equals("private")) return; - if (owner.role.equals("company") && !this.type.equals("company")) return; - this.owner = owner; + if (owner.getRole().equals("private") && !this.type.equals("private")) return; + if (owner.getRole().equals("company") && !this.type.equals("company")) return; + getOwner().set(owner); } public void addHistory(Operation o) { diff --git a/src/main/java/fr/unantes/software/construction/Client.java b/src/main/java/fr/unantes/software/construction/Client.java index 1c3f8b12..9a19ed89 100644 --- a/src/main/java/fr/unantes/software/construction/Client.java +++ b/src/main/java/fr/unantes/software/construction/Client.java @@ -3,6 +3,8 @@ package fr.unantes.software.construction; import fr.unantes.software.construction.address.Address; import fr.unantes.software.construction.address.Card; +import fr.unantes.software.construction.references.ManyToOneReference; +import fr.unantes.software.construction.references.OneToManyReference; import fr.unantes.software.construction.references.SingleReference; import java.io.InvalidClassException; @@ -10,7 +12,12 @@ public class Client { public String name; public String role; - public Account[] accounts; + public final ManyToOneReference accounts = new ManyToOneReference(this) { + @Override + public OneToManyReference oppositeFor(Account target) { + return target.getOwner(); + } + }; private short accountSize = 0; public Card card; private OneToOneAssociation refAddress = new OneToOneAssociation<>(this); @@ -36,10 +43,8 @@ public class Client { if (!role.equals("private") && !role.equals("company")) { throw new InvalidClassException("Invalid role supplied. A person can only be private or company"); } - this.name = name; this.role = role; - accounts = new Account[100]; } public Address getAddress(){ @@ -73,7 +78,7 @@ public class Client { * * @uml.property name="accounts" */ - public Account[] getAccounts() { + public ManyToOneReference getAccounts() { return accounts; } @@ -82,7 +87,7 @@ public class Client { * @uml.property name="accounts" */ public void setAccounts(Account[] value) { - accounts = value; + //accounts = value; } /** @@ -90,18 +95,15 @@ public class Client { * @uml.property name="accounts" */ public void addAccounts(Account element) { - accounts[accountSize++] = element; + accounts.add(element); } /** * * @uml.property name="accounts" */ - public boolean removeAccounts(Account element) { - for (int i = 0; i < accountSize; i++) { - if (element == accounts [i]) accounts[i] = null; - } - return true; + public void removeAccounts(Account element) { + accounts.remove(element); } /** @@ -109,11 +111,7 @@ public class Client { * @uml.property name="accounts" */ public boolean isAccountsEmpty() { - if (accountSize == 0) { - return true; - } else { - return false; - } + return accounts.size() == 0; } /** @@ -129,10 +127,7 @@ public class Client { * @uml.property name="accounts" */ public boolean containsAccounts(Account element) { - for (int i = 0; i < accountSize; i++) { - if (accounts[accountSize] == element) return true; - } - return false; + return accounts.contains(element); } @@ -141,14 +136,14 @@ public class Client { * @uml.property name="accounts" */ public int accountsSize() { - return accounts.length; + return accounts.size(); } /** * * @uml.property name="accounts" */ - public Account[] accountsToArray() { + public ManyToOneReference accountsToArray() { return accounts; } diff --git a/src/main/java/fr/unantes/software/construction/references/ManyToOneReference.java b/src/main/java/fr/unantes/software/construction/references/ManyToOneReference.java index 77efb476..8892813a 100644 --- a/src/main/java/fr/unantes/software/construction/references/ManyToOneReference.java +++ b/src/main/java/fr/unantes/software/construction/references/ManyToOneReference.java @@ -15,6 +15,10 @@ public abstract class ManyToOneReference { return targets; } + public T get(int i) { + return targets.get(i); + } + public boolean contains(T value){ return this.targets.contains(value); } @@ -33,7 +37,9 @@ public abstract class ManyToOneReference { } this.basicRemove(value); } - + public int size(){ + return targets.size(); + } public void basicRemove(T value){ this.targets.remove(value); -- GitLab From ea4352d86924f35cb714e3c0eade22175520e648 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Sat, 21 Mar 2020 15:05:53 +0100 Subject: [PATCH 043/120] Modified classes affected by new behavior of Account & Client --- .../unantes/software/construction/Bank.java | 699 +++++++++--------- .../construction/ui/TextualUserInterface.java | 9 +- .../software/construction/BankTest.java | 4 +- 3 files changed, 355 insertions(+), 357 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/Bank.java b/src/main/java/fr/unantes/software/construction/Bank.java index 3a8335f0..4b0d990a 100755 --- a/src/main/java/fr/unantes/software/construction/Bank.java +++ b/src/main/java/fr/unantes/software/construction/Bank.java @@ -1,351 +1,348 @@ -package fr.unantes.software.construction; - -import fr.unantes.software.construction.address.AddressBook; - -import java.io.InvalidClassException; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.List; -import org.apache.commons.lang3.Validate; - -public class Bank { - private AddressBook ab; - - /** - * @uml.property name="clients" - * @uml.associationEnd inverse="bank:fr.unantes.software.construction.Client" multiplicity="(0 -1)" - */ - private List clients = new ArrayList<>(); - - /** - * this is a counter that is incremented each time a new account is created - */ - private int accountNumbers; - - /** - * @uml.property name="accounts" - * @uml.associationEnd aggregation="composite" inverse="bank:fr.unantes.software.construction.Account" multiplicity="(0 -1)" - */ - private List accounts = new ArrayList<>(); - - /** - * this constructor initializes the attributes : accountNumbers is initially 0, - * accounts and clients and initialized with new empty Lists - */ - public Bank() { - this.accountNumbers = 0; - ab = new AddressBook(); - } - - /** - * @uml.property name="accountNumbers" - */ - public int getAccountNumbers() { - return accountNumbers; - } - - /** - * @uml.property name="accountNumbers" - */ - public void setAccountNumbers(int accountNumbers) { - this.accountNumbers = accountNumbers; - } - - /** - * @uml.property name="clients" - */ - public List getClients() { - return clients; - } - - /** - * @uml.property name="clients" - */ - public void setClients(List value) { - clients = value; - } - - /** - * @uml.property name="clients" - * @return - */ - public Iterator clientsIterator() { - return clients.iterator(); - } - - /** - * @uml.property name="clients" - */ - public boolean addClients(Client element) { - Validate.notNull(element); - return clients.add(element); - } - - /** - * @uml.property name="clients" - */ - public boolean removeClients(Client element) { - Validate.notNull(element); - return clients.remove(element); - } - - /** - * @uml.property name="clients" - */ - public boolean isClientsEmpty() { - return clients.isEmpty(); - } - - /** - * @uml.property name="clients" - */ - public void clearClients() { - clients.clear(); - } - - /** - * @uml.property name="clients" - */ - public boolean containsClients(Client element) { - Validate.notNull(element); - return clients.contains(element); - } - - /** - * @uml.property name="clients" - */ - public boolean containsAllClients(List elements) { - Validate.notNull(elements); - Validate.notEmpty(elements); - return clients.containsAll(elements); - } - - /** - * @uml.property name="clients" - */ - public int clientsSize() { - return clients.size(); - } - - /** - * @uml.property name="clients" - */ - public Client[] clientsToArray() { - return (Client[]) clients - .toArray(new Client[clients.size()]); - } - - /** - * Creates an account for the person named name. - * If no client has this name, a new client object is created and - * is added to the list of clients, then the account is created - * If the client exists the account is created, added to the bank's - * and the client's list of accounts - */ - public int addAccount(String name, float amount, float overdraft, String type) { - Validate.notNull(name); - Validate.notNull(type); - Client p = getClient(name); - //if a client named name already exists in the bank's set of clients - if (p!=null){ - Account a = null; - try { - a = new Account(p, amount, overdraft, type); - } catch (InvalidClassException e) { - e.printStackTrace(); - } - p.addAccounts(a); - this.addAccounts(a); - } - return accountNumbers; - } - - /** - * Closes the account number accountNumber. - * If the account exists, it is removed form the bank's list of accounts and from the owner's list of accounts. - * If the account does not exist, an Exception is thrown. - */ - public void closeAccount(int accountNumber) throws AccountNumberDoesNotExistException { - Account a=getAccount(accountNumber); - if (a!=null){ - a.getOwner().removeAccounts(a); - this.removeAccounts(a); - } - else{ - throw new AccountNumberDoesNotExistException("The account number "+accountNumber+" does not exist. Impossible to close this account"); - } - } - - /** - * Looks for a person named name in the set of clients. - * Returns the Client object corresponding to the client if it exists - * Returns null if there is no client named name - */ - public Client getClient(String name) { - Iterator it = this.clientsIterator(); - while (it.hasNext()){ - Client p = (Client)it.next(); - if(p.getName().equals(name)){ - return p; - } - - } - return null; - } - - /** - * Looks for an account with the number accountNumber in the set of accounts - * Returns the account if it exists - * Returns null if no account has the number accountNumber - * The assumption is that there cannot be several accounts with the same number - */ - public Account getAccount(int accountNumber) { - Iterator it = this.accountsIterator(); - while (it.hasNext()){ - Account a = (Account)it.next(); - if(a.getId()==accountNumber) { - return a; - } - } - return null; - } - - /** - * Deposits the amount on the account number accountNumber - * Throws an exception if there is no account number accountNumber - */ - public void deposit(int accountNumber, float amount) throws AccountNumberDoesNotExistException { - Account a = getAccount(accountNumber); - if (a!=null){ - a.deposit(amount); - } - else{ - throw new AccountNumberDoesNotExistException("The account number "+accountNumber+" does not exist. Impossible to deposit"); - } - } - - /** - * Withdraws the amount from the account number accountNumber - * Throws an exception if there is no account number accountNumber - */ - public void withdraw(int accountNumber, float amount) throws Exception { - Account a = getAccount(accountNumber); - if (a!=null){ - a.withdraw(amount); - } - else{ - throw new AccountNumberDoesNotExistException("The account number "+accountNumber+" does not exist. Impossible to withdraw"); - - } - } - - /** - * Returns the collection of accounts of the client named name - * If there is no client named name, the method returns null - */ - public Account[] getAccountsOfClient(String name) { - Client client = getClient(name); - if (client!=null){ - return client.accountsToArray(); - } - else{ - return new Account[]{}; - } - } - - /** - * - * @uml.property name="accounts" - */ - public List getAccounts() { - return accounts; - } - - /** - * - * @uml.property name="accounts" - */ - public void setAccounts(List value) { - accounts = value; - } - - /** - * - * @uml.property name="accounts" - */ - public Iterator accountsIterator() { - return accounts.iterator(); - } - - /** - * - * @uml.property name="accounts" - */ - public boolean addAccounts(Account element) { - Validate.notNull(element); - return accounts.add(element); - } - - /** - * - * @uml.property name="accounts" - */ - public boolean removeAccounts(Account element) { - Validate.notNull(element); - return accounts.remove(element); - } - - /** - * - * @uml.property name="accounts" - */ - public boolean isAccountsEmpty() { - return accounts.isEmpty(); - } - - /** - * - * @uml.property name="accounts" - */ - public void clearAccounts() { - accounts.clear(); - } - - /** - * - * @uml.property name="accounts" - */ - public boolean containsAccounts(Account element) { - Validate.notNull(element); - return accounts.contains(element); - } - - /** - * - * @uml.property name="accounts" - */ - public boolean containsAllAccounts(List elements) { - Validate.notNull(elements); - return accounts.containsAll(elements); - } - - /** - * - * @uml.property name="accounts" - */ - public int accountsSize() { - return accounts.size(); - } - - /** - * - * @uml.property name="accounts" - */ - public Account[] accountsToArray() { - return (Account[]) accounts - .toArray(new Account[accounts.size()]); - } - -} - +package fr.unantes.software.construction; + +import fr.unantes.software.construction.address.AddressBook; + +import java.io.InvalidClassException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import fr.unantes.software.construction.references.ManyToOneReference; +import org.apache.commons.lang3.Validate; + +public class Bank { + private AddressBook ab; + + /** + * @uml.property name="clients" + * @uml.associationEnd inverse="bank:fr.unantes.software.construction.Client" multiplicity="(0 -1)" + */ + private List clients = new ArrayList<>(); + + /** + * this is a counter that is incremented each time a new account is created + */ + private int accountNumbers; + + /** + * @uml.property name="accounts" + * @uml.associationEnd aggregation="composite" inverse="bank:fr.unantes.software.construction.Account" multiplicity="(0 -1)" + */ + private List accounts = new ArrayList<>(); + + /** + * this constructor initializes the attributes : accountNumbers is initially 0, + * accounts and clients and initialized with new empty Lists + */ + public Bank() { + this.accountNumbers = 0; + ab = new AddressBook(); + } + + /** + * @uml.property name="accountNumbers" + */ + public int getAccountNumbers() { + return accountNumbers; + } + + /** + * @uml.property name="accountNumbers" + */ + public void setAccountNumbers(int accountNumbers) { + this.accountNumbers = accountNumbers; + } + + /** + * @uml.property name="clients" + */ + public List getClients() { + return clients; + } + + /** + * @uml.property name="clients" + */ + public void setClients(List value) { + clients = value; + } + + /** + * @uml.property name="clients" + * @return + */ + public Iterator clientsIterator() { + return clients.iterator(); + } + + /** + * @uml.property name="clients" + */ + public boolean addClients(Client element) { + Validate.notNull(element); + return clients.add(element); + } + + /** + * @uml.property name="clients" + */ + public boolean removeClients(Client element) { + Validate.notNull(element); + return clients.remove(element); + } + + /** + * @uml.property name="clients" + */ + public boolean isClientsEmpty() { + return clients.isEmpty(); + } + + /** + * @uml.property name="clients" + */ + public void clearClients() { + clients.clear(); + } + + /** + * @uml.property name="clients" + */ + public boolean containsClients(Client element) { + Validate.notNull(element); + return clients.contains(element); + } + + /** + * @uml.property name="clients" + */ + public boolean containsAllClients(List elements) { + Validate.notNull(elements); + Validate.notEmpty(elements); + return clients.containsAll(elements); + } + + /** + * @uml.property name="clients" + */ + public int clientsSize() { + return clients.size(); + } + + /** + * @uml.property name="clients" + */ + public Client[] clientsToArray() { + return (Client[]) clients + .toArray(new Client[clients.size()]); + } + + /** + * Creates an account for the person named name. + * If no client has this name, a new client object is created and + * is added to the list of clients, then the account is created + * If the client exists the account is created, added to the bank's + * and the client's list of accounts + */ + public int addAccount(String name, float amount, float overdraft, String type) { + Validate.notNull(name); + Validate.notNull(type); + Client p = getClient(name); + //if a client named name already exists in the bank's set of clients + if (p!=null){ + Account a = null; + try { + a = new Account(p, amount, overdraft, type); + } catch (InvalidClassException e) { + e.printStackTrace(); + } + p.addAccounts(a); + this.addAccounts(a); + } + return accountNumbers; + } + + /** + * Closes the account number accountNumber. + * If the account exists, it is removed form the bank's list of accounts and from the owner's list of accounts. + * If the account does not exist, an Exception is thrown. + */ + public void closeAccount(int accountNumber) throws AccountNumberDoesNotExistException { + Account a=getAccount(accountNumber); + if (a!=null){ + a.getOwner().get().removeAccounts(a); + this.removeAccounts(a); + } + else{ + throw new AccountNumberDoesNotExistException("The account number "+accountNumber+" does not exist. Impossible to close this account"); + } + } + + /** + * Looks for a person named name in the set of clients. + * Returns the Client object corresponding to the client if it exists + * Returns null if there is no client named name + */ + public Client getClient(String name) { + Iterator it = this.clientsIterator(); + while (it.hasNext()){ + Client p = (Client)it.next(); + if(p.getName().equals(name)){ + return p; + } + + } + return null; + } + + /** + * Looks for an account with the number accountNumber in the set of accounts + * Returns the account if it exists + * Returns null if no account has the number accountNumber + * The assumption is that there cannot be several accounts with the same number + */ + public Account getAccount(int accountNumber) { + Iterator it = this.accountsIterator(); + while (it.hasNext()){ + Account a = (Account)it.next(); + if(a.getId()==accountNumber) { + return a; + } + } + return null; + } + + /** + * Deposits the amount on the account number accountNumber + * Throws an exception if there is no account number accountNumber + */ + public void deposit(int accountNumber, float amount) throws AccountNumberDoesNotExistException { + Account a = getAccount(accountNumber); + if (a!=null){ + a.deposit(amount); + } + else{ + throw new AccountNumberDoesNotExistException("The account number "+accountNumber+" does not exist. Impossible to deposit"); + } + } + + /** + * Withdraws the amount from the account number accountNumber + * Throws an exception if there is no account number accountNumber + */ + public void withdraw(int accountNumber, float amount) throws Exception { + Account a = getAccount(accountNumber); + if (a!=null){ + a.withdraw(amount); + } + else{ + throw new AccountNumberDoesNotExistException("The account number "+accountNumber+" does not exist. Impossible to withdraw"); + + } + } + + /** + * Returns the collection of accounts of the client named name + * If there is no client named name, the method returns null + */ + public ManyToOneReference getAccountsOfClient(String name) { + Client client = getClient(name); + Validate.notNull(client); + return client.accountsToArray(); + } + + /** + * + * @uml.property name="accounts" + */ + public List getAccounts() { + return accounts; + } + + /** + * + * @uml.property name="accounts" + */ + public void setAccounts(List value) { + accounts = value; + } + + /** + * + * @uml.property name="accounts" + */ + public Iterator accountsIterator() { + return accounts.iterator(); + } + + /** + * + * @uml.property name="accounts" + */ + public boolean addAccounts(Account element) { + Validate.notNull(element); + return accounts.add(element); + } + + /** + * + * @uml.property name="accounts" + */ + public boolean removeAccounts(Account element) { + Validate.notNull(element); + return accounts.remove(element); + } + + /** + * + * @uml.property name="accounts" + */ + public boolean isAccountsEmpty() { + return accounts.isEmpty(); + } + + /** + * + * @uml.property name="accounts" + */ + public void clearAccounts() { + accounts.clear(); + } + + /** + * + * @uml.property name="accounts" + */ + public boolean containsAccounts(Account element) { + Validate.notNull(element); + return accounts.contains(element); + } + + /** + * + * @uml.property name="accounts" + */ + public boolean containsAllAccounts(List elements) { + Validate.notNull(elements); + return accounts.containsAll(elements); + } + + /** + * + * @uml.property name="accounts" + */ + public int accountsSize() { + return accounts.size(); + } + + /** + * + * @uml.property name="accounts" + */ + public Account[] accountsToArray() { + return (Account[]) accounts + .toArray(new Account[accounts.size()]); + } + +} + diff --git a/src/main/java/fr/unantes/software/construction/ui/TextualUserInterface.java b/src/main/java/fr/unantes/software/construction/ui/TextualUserInterface.java index 4d7a376b..c7b594d1 100755 --- a/src/main/java/fr/unantes/software/construction/ui/TextualUserInterface.java +++ b/src/main/java/fr/unantes/software/construction/ui/TextualUserInterface.java @@ -4,6 +4,7 @@ import fr.unantes.software.construction.Account; import fr.unantes.software.construction.Bank; import fr.unantes.software.construction.Client; import fr.unantes.software.construction.Operation; +import fr.unantes.software.construction.references.ManyToOneReference; import java.io.BufferedReader; import java.io.InputStreamReader; @@ -168,7 +169,7 @@ public class TextualUserInterface { Iterator it = bank.accountsIterator(); Account acc= (Account)it.next();; while(it.hasNext()){ - System.out.println("Account number "+acc.getId()+" is owned by "+acc.getOwner().getName()); + System.out.println("Account number "+acc.getId()+" is owned by "+acc.getOwner().get().getName()); System.out.println(" The balance is :"+acc.getBalance()); System.out.println(" The overdraft is :"+acc.getOverdraft()); } @@ -181,10 +182,10 @@ public class TextualUserInterface { public static void displayAccountsOfClient() { System.out.println("Name of the client:"); String name = readLine(); - Account[] accounts = bank.getAccountsOfClient(name); + ManyToOneReference accounts = bank.getAccountsOfClient(name); if (accounts!=null){ - for (int i = 0; i Date: Sat, 21 Mar 2020 19:21:14 +0100 Subject: [PATCH 044/120] added unit test to check Group and GroupList's behavior --- .../construction/address/GroupListTest.java | 140 ++++++++++++++++++ .../construction/address/GroupTest.java | 64 ++++++++ 2 files changed, 204 insertions(+) create mode 100644 src/main/test/fr/unantes/software/construction/address/GroupListTest.java create mode 100644 src/main/test/fr/unantes/software/construction/address/GroupTest.java diff --git a/src/main/test/fr/unantes/software/construction/address/GroupListTest.java b/src/main/test/fr/unantes/software/construction/address/GroupListTest.java new file mode 100644 index 00000000..90ab1d85 --- /dev/null +++ b/src/main/test/fr/unantes/software/construction/address/GroupListTest.java @@ -0,0 +1,140 @@ +package fr.unantes.software.construction.address; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.internal.matchers.Null; + +import static org.junit.jupiter.api.Assertions.*; + +class GroupListTest { + + GroupList groupList; + Group someGroup; + + @BeforeEach + void setUp() { + groupList = new GroupList(); + someGroup = new Group("a Group",""); + } + + @Test + public void testAdd_newValue_Succeed(){ + assertDoesNotThrow(() -> groupList.add(someGroup)); + assertTrue(groupList.find(someGroup)); + } + + @Test + public void testAdd_alreadyContainedValue_noDuplicate(){ + groupList.add(someGroup); + int currentSize = groupList.size(); + + groupList.add(someGroup); + assertEquals(currentSize,groupList.size()); + } + + @Test + public void testAdd_NullValue_ExceptionThrown(){ + int currentSize = groupList.size(); + assertThrows(Exception.class, () -> groupList.add(null)); + assertEquals(currentSize,groupList.size()); + } + + @Test + public void testDelete_ContainedValue_Succeed(){ + groupList.add(someGroup); + groupList.delete(someGroup); + + assertFalse(groupList.find(someGroup)); + } + + @Test + public void testDelete_ValueContainedByAnotherGroup_NoEffect(){ + GroupList anotherList = new GroupList(); + anotherList.add(someGroup); + + int currentSize = groupList.size(); + assertFalse(groupList.find(someGroup)); + + groupList.delete(someGroup); + assertTrue(anotherList.find(someGroup)); + assertEquals(currentSize, groupList.size()); + } + + @Test + public void testFind_ContainedValue_ReturnTrue(){ + groupList.add(someGroup); + assertTrue(groupList.find(someGroup)); + } + + @Test + public void testFind_NotContainedValue_ReturnFalse(){ + groupList.add(new Group("anotherGroup", "")); + assertFalse(groupList.find(someGroup)); + } + + @Test + public void testMerge_TwoDifferentLists_ReturnListWithBothValue(){ + groupList.add(someGroup); + + Group anotherGroup = new Group("secondGroup", ""); + GroupList anotherList = new GroupList(); + anotherList.add(anotherGroup); + + GroupList mergedLists = groupList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someGroup)); + assertTrue(mergedLists.find(anotherGroup)); + assertEquals(2, mergedLists.size()); + } + + @Test + public void testMerge_SameLists_NoChange(){ + groupList.add(someGroup); + + GroupList mergedLists = groupList.merge(groupList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someGroup)); + assertEquals(groupList.size(), mergedLists.size()); + } + + @Test + public void testMerge_ListsWithSharedValues_NoDuplicate(){ + Group anotherGroup = new Group("secondGroup", ""); + + groupList.add(someGroup); + groupList.add(anotherGroup); + + GroupList anotherList = new GroupList(); + anotherList.add(anotherGroup); + + GroupList mergedLists = groupList.merge(anotherList); + + assertNotNull(mergedLists); + assertEquals(2, mergedLists.size()); + + + } + @Test + public void testMerge_EmptyGroupList_SameGroupList(){ + GroupList anotherList = new GroupList(); + + groupList.add(someGroup); + + GroupList mergedLists = groupList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someGroup)); + assertEquals(1, mergedLists.size()); + } + + @Test + public void testMerge_NullGroupList_ExceptionThrown(){ + groupList.add(someGroup); + + assertThrows(NullPointerException.class, ()->groupList.merge(null)); + } + + +} \ No newline at end of file diff --git a/src/main/test/fr/unantes/software/construction/address/GroupTest.java b/src/main/test/fr/unantes/software/construction/address/GroupTest.java new file mode 100644 index 00000000..5717928b --- /dev/null +++ b/src/main/test/fr/unantes/software/construction/address/GroupTest.java @@ -0,0 +1,64 @@ +package fr.unantes.software.construction.address; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class GroupTest { + Group group; + @BeforeEach + void setUp() { + group = new Group("testGroup",""); + } + + @Test + void testConstructor_NotNullName_Succeed(){ + assertDoesNotThrow(() -> new Group("groupWithName","")); + } + + @Test + void testConstructor_NullName_ExceptionThrown(){ + assertThrows(Exception.class, () -> new Group(null,"")); + } + + @Test + void testSetName_NonNullValue_Succeed(){ + assertDoesNotThrow(() -> group.setName("anotherName")); + assertEquals("anotherName",group.getName()); + } + + @Test + void testSetName_NullValue_ExceptionThrown(){ + assertThrows(Exception.class, () -> group.setName(null)); + assertNotNull(group.getName()); + } + + @Test + void testSetComment_AnyValue_Succeed(){ + group.setComment("a comment"); + assertEquals("a comment",group.getComment()); + group.setComment(null); + assertNull(group.getComment()); + } + + @Test + void testMerge_hasSameName_Succeed(){ + Group anotherGroup = new Group("testGroup",""); + Group mergedGroup = group.merge(anotherGroup); + assertNotNull(mergedGroup); + assertEquals(mergedGroup.getName(),group.getName()); + assertEquals(mergedGroup.getName(),anotherGroup.getName()); + } + + @Test + void testMerge_hasDifferentName_returnNull(){ + Group anotherGroup = new Group("notSameNameGroup",""); + assertNotEquals(group.getName(),anotherGroup.getName()); + + Group mergedGroup = group.merge(anotherGroup); + + assertNull(mergedGroup); + } + +} \ No newline at end of file -- GitLab From 4122ff6dfa5a7ff927215856edd9bfca31dc061a Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Sat, 21 Mar 2020 19:22:47 +0100 Subject: [PATCH 045/120] Fixed Group, GroupList methods to behave according to tests --- .../software/construction/address/Group.java | 4 ++++ .../software/construction/address/GroupList.java | 13 +++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/address/Group.java b/src/main/java/fr/unantes/software/construction/address/Group.java index 17b9b8be..119641b0 100755 --- a/src/main/java/fr/unantes/software/construction/address/Group.java +++ b/src/main/java/fr/unantes/software/construction/address/Group.java @@ -1,5 +1,7 @@ package fr.unantes.software.construction.address; +import org.apache.commons.lang3.Validate; + /** * * @author @@ -18,6 +20,7 @@ public class Group { } public Group(String name, String comment) { + Validate.notNull(name); this.name = name; this.comment = comment; } @@ -44,6 +47,7 @@ public class Group { * nom du groupe */ public void setName(String name) { + Validate.notNull(name); this.name = name; } diff --git a/src/main/java/fr/unantes/software/construction/address/GroupList.java b/src/main/java/fr/unantes/software/construction/address/GroupList.java index c78aa4d6..0c223f90 100755 --- a/src/main/java/fr/unantes/software/construction/address/GroupList.java +++ b/src/main/java/fr/unantes/software/construction/address/GroupList.java @@ -1,5 +1,7 @@ package fr.unantes.software.construction.address; +import org.apache.commons.lang3.Validate; + import java.util.*; public class GroupList { @@ -39,6 +41,7 @@ public class GroupList { * element a add dans la liste */ public void add(Group group) { + Validate.notNull(group); if (!find(group)) groups.add(group); } @@ -54,6 +57,10 @@ public class GroupList { System.out.println("le groupe n'existe pas"); } + protected int size() { + return groups.size(); + } + /** * @param group * c'est l'element recherche @@ -78,6 +85,7 @@ public class GroupList { */ public GroupList merge(GroupList groups) { GroupList res = new GroupList(); + Group nextGroup; /* * on met toute les adresses de la premiere liste dans la liste de @@ -94,8 +102,9 @@ public class GroupList { */ for (Enumeration e1 = groups.get().elements(); e1 .hasMoreElements();) { - if (!(res.find((Group) e1.nextElement()))) { - res.add((Group) e1.nextElement()); + nextGroup = (Group) e1.nextElement(); + if (!(res.find(nextGroup))) { + res.add(nextGroup); } } return res; -- GitLab From 92be99ebaeafff6334fbbe708f827106a0aedf72 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Sat, 21 Mar 2020 20:21:35 +0100 Subject: [PATCH 046/120] Modified bidirectionals tests to suits UML definition --- .../software/construction/AccountTest.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/test/fr/unantes/software/construction/AccountTest.java b/src/main/test/fr/unantes/software/construction/AccountTest.java index f44ede50..a3953bc6 100644 --- a/src/main/test/fr/unantes/software/construction/AccountTest.java +++ b/src/main/test/fr/unantes/software/construction/AccountTest.java @@ -151,15 +151,16 @@ class AccountTest { @Test void setOwner() throws InvalidClassException { - Client oldClient = account.getOwner().get(); + Client oldClient = account.getOwner().get(0); Client newClient = new Client("Timmy", "private"); - assertNotEquals(account.getOwner(), newClient); - assertEquals(account.getOwner().get(), oldClient); + + assertFalse(account.getOwner().contains(newClient)); + assertTrue(account.getOwner().contains(oldClient)); account.setOwner(newClient); - assertNotEquals(account.getOwner().get(), oldClient); - assertEquals(account.getOwner().get(), newClient); + assertTrue(account.getOwner().contains(newClient)); + assertTrue(account.getOwner().contains(oldClient)); } @Test @@ -170,9 +171,9 @@ class AccountTest { client1.addAccounts(account); client2.addAccounts(account); - assertEquals(account.getOwner().get(), client2); - assertNotEquals(account.getOwner().get(), client1); - assertFalse(client1.getAccounts().contains(account)); + assertTrue(account.getOwner().contains(client1)); + assertTrue(account.getOwner().contains(client2)); + assertTrue(client1.getAccounts().contains(account)); assertTrue(client2.getAccounts().contains(account)); } -- GitLab From 6d0b1530a0829b5ad6cd7582e2b1d1d469afcbfe Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Sat, 21 Mar 2020 20:23:01 +0100 Subject: [PATCH 047/120] Created new classe for Multiple to Multiple values referenced --- .../references/MultipleReference.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/main/java/fr/unantes/software/construction/references/MultipleReference.java diff --git a/src/main/java/fr/unantes/software/construction/references/MultipleReference.java b/src/main/java/fr/unantes/software/construction/references/MultipleReference.java new file mode 100644 index 00000000..eff5fd23 --- /dev/null +++ b/src/main/java/fr/unantes/software/construction/references/MultipleReference.java @@ -0,0 +1,51 @@ +package fr.unantes.software.construction.references; + +import java.util.ArrayList; +import java.util.List; + +public abstract class MultipleReference { + final private List targets = new ArrayList<>(); + final private C container; + + public MultipleReference(C container) { + this.container = container; + } + + public List get() { + return targets; + } + + public T get(int i) { + return targets.get(i); + } + + public boolean contains(T value){ + return this.targets.contains(value); + } + + public void add(T value){ + if(!oppositeFor(value).contains(this.container)) oppositeFor(value).basicAdd(this.container); + if(!contains(value)) this.basicAdd(value); + } + + public void remove(T value) { + if(oppositeFor(value).contains(this.container)){ + oppositeFor(value).basicRemove(this.container); + } + this.basicRemove(value); + } + public int size(){ + return targets.size(); + } + + public void basicRemove(T value){ + this.targets.remove(value); + } + + public void basicAdd(T value){ + this.targets.add(value); + } + + public abstract MultipleReference oppositeFor(T target); + +} -- GitLab From 2f0623f9649971895aaba67deeeae3b510e49491 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Sat, 21 Mar 2020 20:23:53 +0100 Subject: [PATCH 048/120] Modified Account and Client to match new bidirectional association --- .../fr/unantes/software/construction/Account.java | 13 +++++++------ .../fr/unantes/software/construction/Client.java | 9 +++++---- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/Account.java b/src/main/java/fr/unantes/software/construction/Account.java index 3370fdb8..e0e507bd 100755 --- a/src/main/java/fr/unantes/software/construction/Account.java +++ b/src/main/java/fr/unantes/software/construction/Account.java @@ -1,6 +1,7 @@ package fr.unantes.software.construction; import fr.unantes.software.construction.references.ManyToOneReference; +import fr.unantes.software.construction.references.MultipleReference; import fr.unantes.software.construction.references.OneToManyReference; import org.apache.commons.lang3.Validate; @@ -13,11 +14,11 @@ public class Account { public String type; private float balance; private float overdraft; - public final OneToManyReference owner = new OneToManyReference(this) { + public final MultipleReference owner = new MultipleReference(this) { @Override - public ManyToOneReference oppositeFor(Client target) { + public MultipleReference oppositeFor(Client target) { return target.getAccounts(); - } + } }; public ManyToOneReference operations = new ManyToOneReference(this) { @Override @@ -31,7 +32,7 @@ public class Account { * The method also initializes the history with a new empty Vector */ public Account(Client p, float amount, float overdraft, String type) throws InvalidClassException { - owner.set(p); + owner.add(p); this.balance = amount; this.overdraft = overdraft; this.type = type; @@ -130,7 +131,7 @@ public class Account { * @uml.property name="owner" * */ - public OneToManyReference getOwner() { + public MultipleReference getOwner() { return owner; } @@ -142,7 +143,7 @@ public class Account { public void setOwner(Client owner) { if (owner.getRole().equals("private") && !this.type.equals("private")) return; if (owner.getRole().equals("company") && !this.type.equals("company")) return; - getOwner().set(owner); + getOwner().add(owner); } public void addHistory(Operation o) { diff --git a/src/main/java/fr/unantes/software/construction/Client.java b/src/main/java/fr/unantes/software/construction/Client.java index 9a19ed89..9af5f755 100644 --- a/src/main/java/fr/unantes/software/construction/Client.java +++ b/src/main/java/fr/unantes/software/construction/Client.java @@ -4,6 +4,7 @@ import fr.unantes.software.construction.address.Address; import fr.unantes.software.construction.address.Card; import fr.unantes.software.construction.references.ManyToOneReference; +import fr.unantes.software.construction.references.MultipleReference; import fr.unantes.software.construction.references.OneToManyReference; import fr.unantes.software.construction.references.SingleReference; import java.io.InvalidClassException; @@ -12,9 +13,9 @@ public class Client { public String name; public String role; - public final ManyToOneReference accounts = new ManyToOneReference(this) { + public final MultipleReference accounts = new MultipleReference(this) { @Override - public OneToManyReference oppositeFor(Account target) { + public MultipleReference oppositeFor(Account target) { return target.getOwner(); } }; @@ -78,7 +79,7 @@ public class Client { * * @uml.property name="accounts" */ - public ManyToOneReference getAccounts() { + public MultipleReference getAccounts() { return accounts; } @@ -143,7 +144,7 @@ public class Client { * * @uml.property name="accounts" */ - public ManyToOneReference accountsToArray() { + public MultipleReference accountsToArray() { return accounts; } -- GitLab From c5c8ed3ad58dd37f114e78083a8e7825c09808c8 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Sat, 21 Mar 2020 20:24:38 +0100 Subject: [PATCH 049/120] Fixed classes impacted by new reference between Account<->Client --- src/main/java/fr/unantes/software/construction/Bank.java | 7 ++++--- .../software/construction/ui/TextualUserInterface.java | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/Bank.java b/src/main/java/fr/unantes/software/construction/Bank.java index 4b0d990a..1c3856ad 100755 --- a/src/main/java/fr/unantes/software/construction/Bank.java +++ b/src/main/java/fr/unantes/software/construction/Bank.java @@ -8,6 +8,7 @@ import java.util.Iterator; import java.util.List; import fr.unantes.software.construction.references.ManyToOneReference; +import fr.unantes.software.construction.references.MultipleReference; import org.apache.commons.lang3.Validate; public class Bank { @@ -168,9 +169,9 @@ public class Bank { * If the account does not exist, an Exception is thrown. */ public void closeAccount(int accountNumber) throws AccountNumberDoesNotExistException { - Account a=getAccount(accountNumber); + Account a = getAccount(accountNumber); if (a!=null){ - a.getOwner().get().removeAccounts(a); + a.getOwner().get().remove(a); this.removeAccounts(a); } else{ @@ -245,7 +246,7 @@ public class Bank { * Returns the collection of accounts of the client named name * If there is no client named name, the method returns null */ - public ManyToOneReference getAccountsOfClient(String name) { + public MultipleReference getAccountsOfClient(String name) { Client client = getClient(name); Validate.notNull(client); return client.accountsToArray(); diff --git a/src/main/java/fr/unantes/software/construction/ui/TextualUserInterface.java b/src/main/java/fr/unantes/software/construction/ui/TextualUserInterface.java index c7b594d1..3de1efaa 100755 --- a/src/main/java/fr/unantes/software/construction/ui/TextualUserInterface.java +++ b/src/main/java/fr/unantes/software/construction/ui/TextualUserInterface.java @@ -5,6 +5,7 @@ import fr.unantes.software.construction.Bank; import fr.unantes.software.construction.Client; import fr.unantes.software.construction.Operation; import fr.unantes.software.construction.references.ManyToOneReference; +import fr.unantes.software.construction.references.MultipleReference; import java.io.BufferedReader; import java.io.InputStreamReader; @@ -167,9 +168,9 @@ public class TextualUserInterface { */ public static void displayAccounts() { Iterator it = bank.accountsIterator(); - Account acc= (Account)it.next();; + Account acc = (Account)it.next();; while(it.hasNext()){ - System.out.println("Account number "+acc.getId()+" is owned by "+acc.getOwner().get().getName()); + for(int i=0; i< acc.getOwner().size(); i++) System.out.println("Account number "+acc.getId()+" is owned by "+acc.getOwner().get(i).getName()); System.out.println(" The balance is :"+acc.getBalance()); System.out.println(" The overdraft is :"+acc.getOverdraft()); } @@ -182,7 +183,7 @@ public class TextualUserInterface { public static void displayAccountsOfClient() { System.out.println("Name of the client:"); String name = readLine(); - ManyToOneReference accounts = bank.getAccountsOfClient(name); + MultipleReference accounts = bank.getAccountsOfClient(name); if (accounts!=null){ for (int i = 0; i Date: Sat, 21 Mar 2020 23:35:18 +0100 Subject: [PATCH 050/120] Added unit tests to check Mail and MailList behavior --- .../construction/address/MailListTest.java | 211 ++++++++++++++++++ .../construction/address/MailTest.java | 81 +++++++ 2 files changed, 292 insertions(+) create mode 100644 src/main/test/fr/unantes/software/construction/address/MailListTest.java create mode 100644 src/main/test/fr/unantes/software/construction/address/MailTest.java diff --git a/src/main/test/fr/unantes/software/construction/address/MailListTest.java b/src/main/test/fr/unantes/software/construction/address/MailListTest.java new file mode 100644 index 00000000..c4b7f471 --- /dev/null +++ b/src/main/test/fr/unantes/software/construction/address/MailListTest.java @@ -0,0 +1,211 @@ +package fr.unantes.software.construction.address; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.Vector; + +import static org.junit.jupiter.api.Assertions.*; + +class MailListTest { + + MailList mailList; + Mail someMail; + + @BeforeEach + void setUp() { + mailList = new MailList(); + someMail = new Mail("someHome@mail.com","someWork@mail.com"); + } + + @Test + void testSet_ListOfMails_addMailsToCurrentList(){ + Vector anotherList = new Vector(); + Mail[] mails = { new Mail(null,null), + new Mail("home1@mail.com",null), + new Mail(null, "work1@mail.co.jp"), + new Mail("home2@mail.fr","work2@mail.fr") + }; + + for(Mail each : mails){ + anotherList.add(each); + } + + mailList.set(anotherList); + + for(Mail each : mails){ + assertTrue(mailList.find(each)); + } + } + + @Test + void testSet_NullValue_ExceptionThrown(){ + assertThrows(Exception.class, ()->mailList.set(null)); + } + + @Test + void testAdd_NewMail_addMailToList(){ + mailList.add(someMail); + + assertTrue(mailList.find(someMail)); + } + + @Test + void testAdd_AlreadyExistingHomeMail_Fusion(){ + Mail oneMail = new Mail("someHome@mail.com",null); + Mail anotherMail = new Mail("someHome@mail.com","anotherWork@mail.com"); + + assertEquals(oneMail.getHome(),anotherMail.getHome()); + + mailList.add(oneMail); + mailList.add(anotherMail); + + assertTrue(mailList.find(oneMail)); + assertEquals("anotherWork@mail.com", oneMail.getWork()); + assertEquals("someHome@mail.com",oneMail.getHome()); + assertEquals(1,mailList.size()); + } + + @Test + void testAdd_AlreadyExistingWorkMail_NoFusion(){ + Mail oneMail = new Mail(null,"someWork@mail.com"); + Mail anotherMail = new Mail("anotherHome@mail.com","someWork@mail.com"); + + assertEquals(oneMail.getWork(),anotherMail.getWork()); + + mailList.add(oneMail); + mailList.add(anotherMail); + + assertTrue(mailList.find(oneMail)); + assertEquals("someWork@mail.com", oneMail.getWork()); + assertNotEquals("anotherHome@mail.com",oneMail.getHome()); + assertEquals(2,mailList.size()); + } + + @Test + void testAdd_Null_ExceptionThrown(){ + assertThrows(NullPointerException.class, () -> mailList.add(null)); + } + + @Test + void testDelete_ExistingMail_Succeed(){ + mailList.add(someMail); + + mailList.delete(someMail); + assertFalse(mailList.find(someMail)); + assertEquals(0,mailList.size()); + } + + @Test + void testDelete_NotContainedMail_NoEffect(){ + MailList anotherList = new MailList(); + Mail anotherMail = new Mail(null,null); + + mailList.add(someMail); + anotherList.add(anotherMail); + + mailList.delete(anotherMail); + + assertTrue(mailList.find(someMail)); + assertFalse(mailList.find(anotherMail)); + + assertTrue(anotherList.find(anotherMail)); + assertEquals(1,anotherList.size()); + } + + @Test + void testDelete_NullValue_ExceptionThrown(){ + assertThrows(NullPointerException.class, () -> mailList.delete(null)); + } + + @Test + void testFind_NoMailInCommon_ReturnFalse(){ + Mail anotherMail = new Mail("anotherHome@mail.com","anotherWork@mail.com"); + + mailList.add(someMail); + assertFalse(mailList.find(anotherMail)); + } + + @Test + void testFind_HomeMailInCommon_ReturnTrue(){ + Mail anotherMail = new Mail("someHome@mail.com","anotherWork@mail.com"); + + mailList.add(someMail); + assertTrue(mailList.find(anotherMail)); + } + + @Test + void testFind_WorkMailInCommon_ReturnFalse(){ + Mail anotherMail = new Mail("anotherHome@mail.com","someWork@mail.com"); + + mailList.add(someMail); + assertFalse(mailList.find(anotherMail)); + } + + @Test + public void testMerge_TwoDifferentLists_ReturnListWithBothValue(){ + mailList.add(someMail); + + Mail anotherMail = new Mail("anotherHome@mail.com", "anotherWork@mail.com"); + MailList anotherList = new MailList(); + anotherList.add(anotherMail); + + MailList mergedLists = mailList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someMail)); + assertTrue(mergedLists.find(anotherMail)); + assertEquals(2, mergedLists.size()); + } + + @Test + public void testMerge_SameLists_NoChange(){ + mailList.add(someMail); + + MailList mergedLists = mailList.merge(mailList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someMail)); + assertEquals(mailList.size(), mergedLists.size()); + } + + @Test + public void testMerge_ListsWithSharedValues_NoDuplicate(){ + Mail anotherMail = new Mail("anotherHome@mail.com", "anotherWork@mail.com"); + + + mailList.add(someMail); + mailList.add(anotherMail); + + MailList anotherList = new MailList(); + anotherList.add(anotherMail); + + MailList mergedLists = mailList.merge(anotherList); + + assertNotNull(mergedLists); + assertEquals(2, mergedLists.size()); + + + } + @Test + public void testMerge_EmptyMailList_SameGroupList(){ + MailList anotherList = new MailList(); + + mailList.add(someMail); + + MailList mergedLists = mailList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someMail)); + assertEquals(1, mergedLists.size()); + } + + @Test + public void testMerge_NullGroupList_ExceptionThrown(){ + mailList.add(someMail); + + assertThrows(NullPointerException.class, ()->mailList.merge(null)); + } + + +} \ No newline at end of file diff --git a/src/main/test/fr/unantes/software/construction/address/MailTest.java b/src/main/test/fr/unantes/software/construction/address/MailTest.java new file mode 100644 index 00000000..22f105b3 --- /dev/null +++ b/src/main/test/fr/unantes/software/construction/address/MailTest.java @@ -0,0 +1,81 @@ +package fr.unantes.software.construction.address; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class MailTest { + + Mail someMail; + + @BeforeEach + void setUp() { + someMail = new Mail(null,null); + } + + @Test + void testSetWork_addNewMail_OnlyInstanciateWorkAttribute(){ + someMail.setWork("work@someMail.io"); + + assertEquals(null,someMail.getHome()); + assertEquals("work@someMail.io", someMail.getWork()); + + } + + @Test + void testSetHome_addNewMail_InstanciateHomeAttribute(){ + someMail.setHome("home@someMail.com"); + + assertNull(someMail.getWork()); + assertEquals("home@someMail.com", someMail.getHome()); + } + + + @Test + void testFusion_WorkAndHomeMails_OnlyInstanciateHomeAttribute(){ + someMail.setWork("work@mail.io"); + Mail anotherMail = new Mail("home@mail.com",null); + + someMail.fusion(anotherMail); + + assertEquals("work@mail.io", someMail.getWork()); + assertEquals("home@mail.com", someMail.getHome()); + } + + @Test + void testFusion_HomeAndWorkMails_OnlyInstanciateWorkAttribute(){ + someMail.setHome("home@mail.com"); + Mail anotherMail = new Mail(null,"work@mail.io"); + + someMail.fusion(anotherMail); + + assertEquals("work@mail.io", someMail.getWork()); + assertEquals("home@mail.com", someMail.getHome()); + } + + @Test + void testFusion_TwoHomeMails_NoChange(){ + someMail.setHome("home1@mail.com"); + Mail anotherMail = new Mail("home2@mail.com",null); + + someMail.fusion(anotherMail); + + assertEquals("home1@mail.com", someMail.getHome()); + } + + @Test + void testFusion_TwoWorkMails_NoChange(){ + someMail.setWork("work1@mail.io"); + Mail anotherMail = new Mail(null,"work1@mail.io"); + + someMail.fusion(anotherMail); + + assertEquals("work1@mail.io", someMail.getWork()); + } + + @Test + void testFusion_WithNullObject_ExceptionThrown(){ + assertThrows(Exception.class, ()->someMail.fusion(null)); + } +} \ No newline at end of file -- GitLab From 8ce93cb32ac5a35e828b67d68a8923bf679a3193 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Sat, 21 Mar 2020 23:36:31 +0100 Subject: [PATCH 051/120] Modified Mail and MailList to suits their associated tests --- .../software/construction/address/Mail.java | 2 ++ .../construction/address/MailList.java | 26 ++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/address/Mail.java b/src/main/java/fr/unantes/software/construction/address/Mail.java index bd2dd1b1..9e830f59 100755 --- a/src/main/java/fr/unantes/software/construction/address/Mail.java +++ b/src/main/java/fr/unantes/software/construction/address/Mail.java @@ -1,5 +1,7 @@ package fr.unantes.software.construction.address; +import org.apache.commons.lang3.Validate; + public class Mail { private String home; diff --git a/src/main/java/fr/unantes/software/construction/address/MailList.java b/src/main/java/fr/unantes/software/construction/address/MailList.java index c796dec6..f0803f6a 100755 --- a/src/main/java/fr/unantes/software/construction/address/MailList.java +++ b/src/main/java/fr/unantes/software/construction/address/MailList.java @@ -7,6 +7,8 @@ package fr.unantes.software.construction.address; * @date 17/12/2004. */ +import org.apache.commons.lang3.Validate; + import java.util.*; public class MailList { @@ -51,8 +53,17 @@ public class MailList { * mail a add dans la liste */ public void add(Mail mail) { + Validate.notNull(mail); if (!find(mail)) mails.add(mail); + else{ + Mail nextMail; + for (Enumeration e = mails.elements(); e.hasMoreElements();) { + nextMail = (Mail) e.nextElement(); + if (nextMail.getHome()==mail.getHome()) + nextMail.fusion(mail); + } + } // si existe deja faire la fusion des deux dans celle deja enregistree // dans le vecteur. /** @@ -66,6 +77,7 @@ public class MailList { * mail a supprimer de la liste */ public void delete(Mail mail) { + Validate.notNull(mail); if (find(mail)) mails.remove(mail); else @@ -78,8 +90,10 @@ public class MailList { */ public boolean find(Mail mail) { boolean res = false; + Mail nextMail; for (Enumeration e = mails.elements(); e.hasMoreElements();) { - if (((Mail) e.nextElement()).getHome().equals(mail.getHome())) + nextMail = (Mail) e.nextElement(); + if (nextMail.getHome()==mail.getHome()) res = true; } return res; @@ -95,6 +109,7 @@ public class MailList { */ public MailList merge(MailList mails) { MailList res = new MailList(); + Mail nextMail; /** * on met toute les adresses de la premiere liste dans la liste de @@ -110,8 +125,9 @@ public class MailList { */ for (Enumeration e1 = mails.get().elements(); e1 .hasMoreElements();) { - if (!(res.find((Mail) e1.nextElement()))) { - res.add((Mail) e1.nextElement()); + nextMail = (Mail) e1.nextElement(); + if (!(res.find(nextMail))) { + res.add(nextMail); } } return res; @@ -137,4 +153,8 @@ public class MailList { } return res; } + + protected int size(){ + return mails.size(); + } } -- GitLab From f74b5ba89b806bb3042fb30b93d492237f26b3d6 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Sat, 21 Mar 2020 23:38:58 +0100 Subject: [PATCH 052/120] Changed Mail attributes name to enhance lisibility --- .../software/construction/address/Mail.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/address/Mail.java b/src/main/java/fr/unantes/software/construction/address/Mail.java index 9e830f59..7f3640a8 100755 --- a/src/main/java/fr/unantes/software/construction/address/Mail.java +++ b/src/main/java/fr/unantes/software/construction/address/Mail.java @@ -7,9 +7,9 @@ public class Mail { private String home; private String work; - public Mail(String mail, String com) { - home = mail; - work = com; + public Mail(String home, String work) { + this.home = home; + this.work = work; } /** @@ -27,29 +27,29 @@ public class Mail { } /** - * @param mail + * @param home */ - public void setHome(String mail) { - home = mail; + public void setHome(String home) { + this.home = home; } /** - * @param com + * @param work */ - public void setWork(String com) { - work = com; + public void setWork(String work) { + this.work = work; } /** * Cree un nouvel objet Mail, fusion des deux mails. * - * @param m mail a faire fusionner avec l'objet mail courant. + * @param mail mail a faire fusionner avec l'objet mail courant. */ - public void fusion(Mail m) { + public void fusion(Mail mail) { if (home == null) - home = m.getHome(); + home = mail.getHome(); if (work == null) - work = m.getWork(); + work = mail.getWork(); } public String toXML() { -- GitLab From 335f3d0eb50020bdc4ebf97d235671a8cc1753c4 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Sat, 21 Mar 2020 23:47:06 +0100 Subject: [PATCH 053/120] Added test to check City behaviour --- .../construction/address/CityTest.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/main/test/fr/unantes/software/construction/address/CityTest.java diff --git a/src/main/test/fr/unantes/software/construction/address/CityTest.java b/src/main/test/fr/unantes/software/construction/address/CityTest.java new file mode 100644 index 00000000..df093d63 --- /dev/null +++ b/src/main/test/fr/unantes/software/construction/address/CityTest.java @@ -0,0 +1,41 @@ +package fr.unantes.software.construction.address; + +import org.apache.commons.lang3.Validate; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class CityTest { + + City city; + + @BeforeEach + void setUp() { + city = new City("Korea","Busan"); + } + + @Test + void testSetCountry_SomeValue_Succeed() { + city.setCountry("notKorea"); + assertEquals("notKorea", city.getCountry()); + } + + @Test + void testSetCountry_NullValue_ExceptionThrown(){ + assertThrows(NullPointerException.class, () -> city.setCountry(null)); + assertEquals("Korea",city.getCountry()); + } + + @Test + void testSetName_SomeValue_Succeed(){ + city.setName("Seoul"); + assertEquals("Seoul", city.getName()); + } + + @Test + void testSetName_NullValue_ExceptionThrown(){ + assertThrows(NullPointerException.class, () -> city.setName(null)); + assertEquals("Busan",city.getName()); + } +} \ No newline at end of file -- GitLab From c195e5abec1f3d68dd9d1d86f3be360d7fa2eccf Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Sat, 21 Mar 2020 23:47:41 +0100 Subject: [PATCH 054/120] Modified City class to match associated tests --- .../java/fr/unantes/software/construction/address/City.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/fr/unantes/software/construction/address/City.java b/src/main/java/fr/unantes/software/construction/address/City.java index 00cf4ae8..2864e325 100644 --- a/src/main/java/fr/unantes/software/construction/address/City.java +++ b/src/main/java/fr/unantes/software/construction/address/City.java @@ -1,5 +1,7 @@ package fr.unantes.software.construction.address; +import org.apache.commons.lang3.Validate; + /** * A city */ @@ -8,6 +10,8 @@ public class City { public String name; public City(String country, String name) { + Validate.notNull(country); + Validate.notNull(name); this.country = country; this.name = name; } @@ -17,6 +21,7 @@ public class City { } public void setCountry(String country) { + Validate.notNull(country); this.country = country; } @@ -25,6 +30,7 @@ public class City { } public void setName(String name) { + Validate.notNull(name); this.name = name; } -- GitLab From de30346ad7ded1db181fa2c0c29b7d05c504ddef Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Sun, 22 Mar 2020 09:33:06 +0100 Subject: [PATCH 055/120] Added missin tests for set() method in GroupListTest --- .../construction/address/GroupListTest.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/main/test/fr/unantes/software/construction/address/GroupListTest.java b/src/main/test/fr/unantes/software/construction/address/GroupListTest.java index 90ab1d85..e631a9b7 100644 --- a/src/main/test/fr/unantes/software/construction/address/GroupListTest.java +++ b/src/main/test/fr/unantes/software/construction/address/GroupListTest.java @@ -4,6 +4,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.internal.matchers.Null; +import java.util.Vector; + import static org.junit.jupiter.api.Assertions.*; class GroupListTest { @@ -17,6 +19,31 @@ class GroupListTest { someGroup = new Group("a Group",""); } + @Test + void testSet_ListOfGroups_addGroupsToCurrentList(){ + Vector anotherList = new Vector(); + Group[] groups = { someGroup, + new Group("Group1",null), + new Group("Group2","Comment2"), + }; + + for(Group each : groups){ + anotherList.add(each); + } + + groupList.set(anotherList); + + for(Group each : groups){ + assertTrue(groupList.find(each)); + } + } + + @Test + void testSet_NullValue_ExceptionThrown(){ + assertThrows(Exception.class, ()->groupList.set(null)); + } + + @Test public void testAdd_newValue_Succeed(){ assertDoesNotThrow(() -> groupList.add(someGroup)); -- GitLab From 5395f4f18575a9f56018c86738aedd01d3f6a00a Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Sun, 22 Mar 2020 10:07:11 +0100 Subject: [PATCH 056/120] Added test for Phone & PhoneList to check their behavior --- .../construction/address/PhoneListTest.java | 180 ++++++++++++++++++ .../construction/address/PhoneTest.java | 89 +++++++++ 2 files changed, 269 insertions(+) create mode 100644 src/main/test/fr/unantes/software/construction/address/PhoneListTest.java create mode 100644 src/main/test/fr/unantes/software/construction/address/PhoneTest.java diff --git a/src/main/test/fr/unantes/software/construction/address/PhoneListTest.java b/src/main/test/fr/unantes/software/construction/address/PhoneListTest.java new file mode 100644 index 00000000..536d375e --- /dev/null +++ b/src/main/test/fr/unantes/software/construction/address/PhoneListTest.java @@ -0,0 +1,180 @@ +package fr.unantes.software.construction.address; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.Vector; + +import static org.junit.jupiter.api.Assertions.*; + +class PhoneListTest { + + PhoneList phoneList = new PhoneList(); + Phone somePhone; + + @BeforeEach + void setUp() { + somePhone = new Phone(0600000000,"some comment"); + } + + @Test + void testSet_ListOfPhones_addPhonesToCurrentList(){ + Vector anotherList = new Vector(); + Phone[] phones = { somePhone, + new Phone(0600000001,null), + new Phone(0600000010,"another comment") + }; + + for(Phone each : phones){ + anotherList.add(each); + } + + phoneList.set(anotherList); + + for(Phone each : phones){ + assertTrue(phoneList.find(each)); + } + } + + @Test + void testSet_NullValue_ExceptionThrown(){ + assertThrows(Exception.class, ()->phoneList.set(null)); + } + + @Test + void testAdd_NewPhone_addPhoneToList(){ + phoneList.add(somePhone); + + assertTrue(phoneList.find(somePhone)); + } + + @Test + void testAdd_AlreadyExistingPhone_Fusion(){ + Phone onePhone = new Phone(somePhone.getPhoneNumber(), null); + Phone anotherPhone = new Phone(somePhone.getPhoneNumber(), "a different comment"); + + phoneList.add(onePhone); + phoneList.add(anotherPhone); + + assertTrue(phoneList.find(onePhone)); + assertEquals(1,phoneList.get().size()); + } + + @Test + void testAdd_Null_ExceptionThrown(){ + assertThrows(NullPointerException.class, () -> phoneList.add(null)); + } + + @Test + void testDelete_ExistingMail_Succeed(){ + phoneList.add(somePhone); + + phoneList.delete(somePhone); + assertFalse(phoneList.find(somePhone)); + assertEquals(0,phoneList.get().size()); + } + + @Test + void testDelete_NotContainedMail_NoEffect(){ + PhoneList anotherList = new PhoneList(); + Phone anotherPhone = new Phone(0606060606,"another comment"); + + phoneList.add(somePhone); + anotherList.add(anotherPhone); + + phoneList.delete(anotherPhone); + + assertTrue(phoneList.find(somePhone)); + assertFalse(phoneList.find(anotherPhone)); + + assertTrue(anotherList.find(anotherPhone)); + assertEquals(1,anotherList.get().size()); + } + + @Test + void testDelete_NullValue_ExceptionThrown(){ + assertThrows(NullPointerException.class, () -> phoneList.delete(null)); + } + + @Test + void testFind_NoPhoneInCommon_ReturnFalse(){ + Phone anotherPhone = new Phone(0606060606,"another comment"); + + phoneList.add(somePhone); + assertFalse(phoneList.find(anotherPhone)); + } + + @Test + void testFind_PhoneNumberInCommon_ReturnTrue(){ + Phone anotherPhone = new Phone(somePhone.getPhoneNumber(),"another comment"); + + phoneList.add(somePhone); + assertTrue(phoneList.find(anotherPhone)); + } + + + @Test + public void testMerge_TwoDifferentLists_ReturnListWithBothValue(){ + phoneList.add(somePhone); + + PhoneList anotherList = new PhoneList(); + Phone anotherPhone = new Phone(0606060606,"another comment"); + anotherList.add(anotherPhone); + + PhoneList mergedLists = phoneList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(somePhone)); + assertTrue(mergedLists.find(anotherPhone)); + assertEquals(2, mergedLists.get().size()); + } + + @Test + public void testMerge_SameLists_NoChange(){ + phoneList.add(somePhone); + + PhoneList mergedLists = phoneList.merge(phoneList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(somePhone)); + assertEquals(phoneList.get().size(), mergedLists.get().size()); + } + + @Test + public void testMerge_ListsWithSharedValues_NoDuplicate(){ + PhoneList anotherList = new PhoneList(); + Phone anotherPhone = new Phone(0606060606,"another comment"); + + + phoneList.add(somePhone); + phoneList.add(anotherPhone); + + anotherList.add(anotherPhone); + + PhoneList mergedLists = phoneList.merge(anotherList); + + assertNotNull(mergedLists); + assertEquals(2, mergedLists.get().size()); + + + } + @Test + public void testMerge_EmptyPhoneList_SameGroupList(){ + PhoneList anotherList = new PhoneList(); + + phoneList.add(somePhone); + + PhoneList mergedLists = phoneList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(somePhone)); + assertEquals(1, mergedLists.get().size()); + } + + @Test + public void testMerge_NullGroupList_ExceptionThrown(){ + phoneList.add(somePhone); + assertThrows(NullPointerException.class, ()->phoneList.merge(null)); + } + +} \ No newline at end of file diff --git a/src/main/test/fr/unantes/software/construction/address/PhoneTest.java b/src/main/test/fr/unantes/software/construction/address/PhoneTest.java new file mode 100644 index 00000000..47ce3d01 --- /dev/null +++ b/src/main/test/fr/unantes/software/construction/address/PhoneTest.java @@ -0,0 +1,89 @@ +package fr.unantes.software.construction.address; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class PhoneTest { + + Phone somePhone; + + @BeforeEach + void setUp() { + somePhone = new Phone(0642424242,"some ambiguous comment"); + } + + @Test + void testSetPhoneNumber_PositiveValue_Succeed(){ + Integer newValue = 0242424242; + assertDoesNotThrow(()->somePhone.setPhoneNumber(newValue)); + assertEquals(newValue, somePhone.getPhoneNumber()); + + } + + @Test + void testSetPhone_NegativeValue_ExceptionThrown(){ + Integer oldValue = somePhone.getPhoneNumber(); + Integer newValue = -42; + + assertThrows(Exception.class,()->somePhone.setPhoneNumber(newValue)); + assertEquals(oldValue, somePhone.getPhoneNumber()); + } + @Test + void testSetPhone_NullValue_ExceptionThrown(){ + Integer oldValue = 0642424242; + + assertThrows(Exception.class,()->somePhone.setPhoneNumber(null)); + assertEquals(oldValue, somePhone.getPhoneNumber()); + } + + @Test + void testSetComment_AnyStringValue_Succeed(){ + somePhone.setComment("an even more ambiguous comment"); + assertEquals("an even more ambiguous comment", somePhone.getComment()); + + somePhone.setComment(null); + assertEquals(null, somePhone.getComment()); + } + + @Test + void testMerge_TwoValidPhones_KeepFirstValues(){ + Integer oldValue = somePhone.getPhoneNumber(); + Phone anotherPhone = new Phone(0666666666,"another ambiguous comment"); + + Phone mergedPhone = somePhone.merge(anotherPhone); + assertEquals(oldValue, mergedPhone.getPhoneNumber()); + assertEquals("some ambiguous comment",mergedPhone.getComment()); + } + + @Test + void testMerge_CurrentNumberIsZero_ReturnOtherPhoneNumber(){ + somePhone.setPhoneNumber(0); + + Phone anotherPhone = new Phone(0666666666,"another ambiguous comment"); + Integer anotherPhoneNumber = anotherPhone.getPhoneNumber(); + + Phone mergedPhone = somePhone.merge(anotherPhone); + + assertEquals(anotherPhoneNumber, mergedPhone.getPhoneNumber()); + assertEquals("some ambiguous comment",mergedPhone.getComment()); + } + + @Test + void testMerge_CurrentCommentIsNull_ReturnOtherPhoneComment(){ + somePhone.setComment(null); + + Phone anotherPhone = new Phone(0666666666,"another ambiguous comment"); + + Phone mergedPhone = somePhone.merge(anotherPhone); + + assertEquals(somePhone.getPhoneNumber(), mergedPhone.getPhoneNumber()); + assertEquals(anotherPhone.getComment(),mergedPhone.getComment()); + } + + @Test + void testMerge_NullValue_ExceptionThrown(){ + assertThrows(NullPointerException.class, ()-> somePhone.merge(null)); + } +} \ No newline at end of file -- GitLab From fba0bd690a113084b7ceed1562af6be52e65b1d8 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Sun, 22 Mar 2020 10:07:49 +0100 Subject: [PATCH 057/120] Modified Phone and PhoneList to match tests preconditions --- .../unantes/software/construction/address/Phone.java | 7 +++++++ .../software/construction/address/PhoneList.java | 12 +++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/address/Phone.java b/src/main/java/fr/unantes/software/construction/address/Phone.java index 11b96d27..eef93155 100755 --- a/src/main/java/fr/unantes/software/construction/address/Phone.java +++ b/src/main/java/fr/unantes/software/construction/address/Phone.java @@ -1,5 +1,7 @@ package fr.unantes.software.construction.address; +import org.apache.commons.lang3.Validate; + import javax.annotation.Nonnull; /** @@ -13,6 +15,8 @@ public class Phone { protected String comment; public Phone(Integer phoneNumber, String comment) { + Validate.notNull(phoneNumber); + Validate.isTrue(phoneNumber>=0); this.phoneNumber = phoneNumber; this.comment = comment; } @@ -35,6 +39,8 @@ public class Phone { * @param phoneNumber */ public void setPhoneNumber(Integer phoneNumber) { + Validate.notNull(phoneNumber); + Validate.isTrue(phoneNumber>=0); this.phoneNumber = phoneNumber; } @@ -52,6 +58,7 @@ public class Phone { * @param phone tel a faire fusionner avec l'objet tel courant. */ public Phone merge(Phone phone) { + Validate.notNull(phone); int i = (phoneNumber == 0 ? phone.phoneNumber : phoneNumber); String s = (comment == null ? phone.comment : comment); diff --git a/src/main/java/fr/unantes/software/construction/address/PhoneList.java b/src/main/java/fr/unantes/software/construction/address/PhoneList.java index 83626f89..9c89b7c6 100755 --- a/src/main/java/fr/unantes/software/construction/address/PhoneList.java +++ b/src/main/java/fr/unantes/software/construction/address/PhoneList.java @@ -1,5 +1,7 @@ package fr.unantes.software.construction.address; +import org.apache.commons.lang3.Validate; + import java.util.*; public class PhoneList { @@ -42,6 +44,7 @@ public class PhoneList { * @param phone adresse a add dans la liste */ public void add(Phone phone) { + Validate.notNull(phone); if (!find(phone)) phones.add(phone); // si existe deja faire la fusion des deux dans celle deja enregistrer @@ -56,6 +59,7 @@ public class PhoneList { * @param phone telephone a supprimer de la liste */ public void delete(Phone phone) { + Validate.notNull(phone); if (find(phone)) phones.remove(phone); else @@ -77,11 +81,12 @@ public class PhoneList { /** * Fusion entre 2 listes dans une 3eme que l'on cree. * - * @param l 2eme liste a faire fusionner + * @param phones 2eme liste a faire fusionner * @return La 3eme liste fusion de la liste courante et de la liste passee en parametre */ public PhoneList merge(PhoneList phones) { PhoneList res = new PhoneList(); + Phone nextPhone; /** * on met toute les adresses de la premiere liste dans la liste de @@ -97,8 +102,9 @@ public class PhoneList { */ for (Enumeration e1 = phones.get().elements(); e1 .hasMoreElements();) { - if (!(res.find((Phone) e1.nextElement()))) { - res.add((Phone) e1.nextElement()); + nextPhone = (Phone) e1.nextElement(); + if (!(res.find(nextPhone))) { + res.add(nextPhone); } } return res; -- GitLab From 1356ef2db89afbf93fe9a0a303d9336c3e1b9eac Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Sun, 22 Mar 2020 15:40:23 +0100 Subject: [PATCH 058/120] Implemented missing tests in AccountTest --- .../software/construction/AccountTest.java | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/main/test/fr/unantes/software/construction/AccountTest.java b/src/main/test/fr/unantes/software/construction/AccountTest.java index a3953bc6..04856152 100644 --- a/src/main/test/fr/unantes/software/construction/AccountTest.java +++ b/src/main/test/fr/unantes/software/construction/AccountTest.java @@ -76,12 +76,17 @@ class AccountTest { @Test void testDeposit_success_addOperationToHistory() { - //TODO + int oldSize = account.getHistory().size(); + account.deposit(50); + + assertEquals(oldSize+1,account.getHistory().size()); } @Test void testDeposit_exception_identicalHistory() { - //TODO + int oldSize = account.getHistory().size(); + assertThrows(Exception.class, ()-> account.deposit(-500)); + assertEquals(oldSize,account.getHistory().size()); } @Test @@ -110,13 +115,18 @@ class AccountTest { @Test - void testWithdraw_success_addOperationToHistory() { - //TODO + void testWithdraw_success_addOperationToHistory() throws Exception { + int oldSize = account.getHistory().size(); + account.withdraw(50); + + assertEquals(oldSize+1,account.getHistory().size()); } @Test - void testWithdraw_success_identicalHistory() { - //TODO + void testWithdraw_exception_identicalHistory() { + int oldSize = account.getHistory().size(); + assertThrows(Exception.class, ()-> account.withdraw(-500)); + assertEquals(oldSize,account.getHistory().size()); } -- GitLab From e9b2b9a781ae0261d6cf2669d7a8b1e9fcd13be1 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Sun, 22 Mar 2020 16:11:23 +0100 Subject: [PATCH 059/120] Added tests to check behavior for Address related classes --- .../construction/address/AddressBookTest.java | 107 +++++++++++ .../construction/address/AddressListTest.java | 167 ++++++++++++++++++ .../address/CompanyAddressTest.java | 144 +++++++++++++++ .../address/PrivateAddressTest.java | 130 ++++++++++++++ 4 files changed, 548 insertions(+) create mode 100644 src/main/test/fr/unantes/software/construction/address/AddressBookTest.java create mode 100644 src/main/test/fr/unantes/software/construction/address/AddressListTest.java create mode 100644 src/main/test/fr/unantes/software/construction/address/CompanyAddressTest.java create mode 100644 src/main/test/fr/unantes/software/construction/address/PrivateAddressTest.java diff --git a/src/main/test/fr/unantes/software/construction/address/AddressBookTest.java b/src/main/test/fr/unantes/software/construction/address/AddressBookTest.java new file mode 100644 index 00000000..ae25f4a5 --- /dev/null +++ b/src/main/test/fr/unantes/software/construction/address/AddressBookTest.java @@ -0,0 +1,107 @@ +package fr.unantes.software.construction.address; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class AddressBookTest { + CardList someList; + Card someCard; + AddressBook addressBook; + + @BeforeEach + void setUp(){ + someList = new CardList(); + someCard = new PrivateCard("Chaussette","Louis"); + someList.add(someCard); + addressBook = new AddressBook(); + } + + @Test + void testSetCards_ValidCardList_Succeed(){ + assertDoesNotThrow(()->addressBook.setCards(someList)); + + assertEquals(someList.contains(someCard), addressBook.getCards().contains(someCard)); + } + + @Test + void testSetCards_NullValue_ExceptionThrown(){ + assertThrows(NullPointerException.class, ()-> addressBook.setCards(null)); + } + + @Test + void testSetName_AnyStringValue_Suceed(){ + assertDoesNotThrow(()->addressBook.setName("name")); + assertEquals("name",addressBook.getName()); + + } + + @Test + public void testMerge_TwoDifferentLists_ReturnListWithBothValue(){ + addressBook.setCards(someList); + + AddressBook anotherBook = new AddressBook(); + CardList anotherList = new CardList(); + Card anotherCard = new PrivateCard("Marco","Polo"); + + anotherList.add(anotherCard); + anotherBook.setCards(anotherList); + + AddressBook mergedLists = addressBook.merge(anotherBook,"new name"); + + assertNotNull(mergedLists); + assertTrue(mergedLists.getCards().contains(someCard)); + assertTrue(mergedLists.getCards().contains(anotherCard)); + assertEquals(2, mergedLists.getCards().get().size()); + } + + @Test + public void testMerge_SameLists_NoChange(){ + addressBook.setCards(someList); + + AddressBook mergedLists = addressBook.merge(addressBook,""); + + assertNotNull(mergedLists); + assertTrue(mergedLists.getCards().contains(someCard)); + assertEquals(addressBook.getCards().get().size(), mergedLists.getCards().get().size()); + } + + @Test + public void testMerge_ListsWithSharedValues_NoDuplicate(){ + addressBook.setCards(someList); + + AddressBook anotherBook = new AddressBook(); + CardList anotherList = new CardList(); + Card anotherCard = new PrivateCard("Marco","Polo"); + + anotherList.add(someCard); + anotherList.add(anotherCard); + anotherBook.setCards(anotherList); + + AddressBook mergedLists = addressBook.merge(anotherBook, ""); + + assertNotNull(mergedLists); + assertEquals(2, mergedLists.getCards().get().size()); + + + } + @Test + public void testMerge_EmptyGroupList_SameGroupList(){ + addressBook.setCards(someList); + AddressBook anotherBook = new AddressBook(); + + AddressBook mergedLists = addressBook.merge(anotherBook,""); + + assertNotNull(mergedLists); + assertTrue(mergedLists.getCards().contains(someCard)); + assertEquals(1, mergedLists.getCards().get().size()); + } + + @Test + public void testMerge_NullGroupList_ExceptionThrown(){ + + assertThrows(NullPointerException.class, ()->addressBook.merge(null,"")); + } + +} \ No newline at end of file diff --git a/src/main/test/fr/unantes/software/construction/address/AddressListTest.java b/src/main/test/fr/unantes/software/construction/address/AddressListTest.java new file mode 100644 index 00000000..5d68e3fd --- /dev/null +++ b/src/main/test/fr/unantes/software/construction/address/AddressListTest.java @@ -0,0 +1,167 @@ +package fr.unantes.software.construction.address; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.Vector; + +import static org.junit.jupiter.api.Assertions.*; + +class AddressListTest { + + AddressList addressList; + Address someAddress; + + @BeforeEach + void setUp() { + addressList = new AddressList(); + someAddress = new PrivateAddress(1,"Some Private Street", new City("Groenland","Qeqertarsuaq"),0,null); + } + + @Test + void testSet_ListOfGroups_addGroupsToCurrentList(){ + Vector anotherList = new Vector(); + Address[] addresses = { someAddress, + new PrivateAddress(1,"Another Private Street", new City("Norvege","Honningsvag"),0,null), + new CompanyAddress(1,"A Company Street", new City("Australie","Pine Creek"),0,null,null) + }; + + for(Address each : addresses){ + anotherList.add(each); + } + + addressList.set(anotherList); + + for(Address each : addresses){ + assertTrue(addressList.find(each)); + } + } + + @Test + void testSet_NullValue_ExceptionThrown(){ + assertThrows(Exception.class, ()->addressList.set(null)); + } + + + @Test + public void testAdd_newValue_Succeed(){ + assertDoesNotThrow(() -> addressList.add(someAddress)); + assertTrue(addressList.find(someAddress)); + } + + @Test + public void testAdd_alreadyContainedValue_noDuplicate(){ + addressList.add(someAddress); + int currentSize = addressList.get().size(); + + addressList.add(someAddress); + assertEquals(currentSize,addressList.get().size()); + } + + @Test + public void testAdd_NullValue_ExceptionThrown(){ + int currentSize = addressList.get().size(); + assertThrows(Exception.class, () -> addressList.add(null)); + assertEquals(currentSize,addressList.get().size()); + } + + @Test + public void testDelete_ContainedValue_Succeed(){ + addressList.add(someAddress); + addressList.delete(someAddress); + + assertFalse(addressList.find(someAddress)); + } + + @Test + public void testDelete_ValueContainedByAnotherGroup_NoEffect(){ + AddressList anotherList = new AddressList(); + anotherList.add(someAddress); + + int currentSize = addressList.get().size(); + assertFalse(addressList.find(someAddress)); + + addressList.delete(someAddress); + assertTrue(anotherList.find(someAddress)); + assertEquals(currentSize, addressList.get().size()); + } + + @Test + public void testFind_ContainedValue_ReturnTrue(){ + addressList.add(someAddress); + assertTrue(addressList.find(someAddress)); + } + + @Test + public void testFind_NotContainedValue_ReturnFalse(){ + addressList.add(new PrivateAddress(1,"Another Private Street", new City("Norvege","Honningsvag"),0,null)); + assertFalse(addressList.find(someAddress)); + } + + @Test + public void testMerge_TwoDifferentLists_ReturnListWithBothValue(){ + addressList.add(someAddress); + + Address anotherAddress = new PrivateAddress(1,"Another Private Street", new City("Norvege","Honningsvag"),0,null); + AddressList anotherList = new AddressList(); + anotherList.add(anotherAddress); + + AddressList mergedLists = addressList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someAddress)); + assertTrue(mergedLists.find(anotherAddress)); + assertEquals(2, mergedLists.get().size()); + } + + @Test + public void testMerge_SameLists_NoChange(){ + addressList.add(someAddress); + + AddressList mergedLists = addressList.merge(addressList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someAddress)); + assertEquals(addressList.get().size(), mergedLists.get().size()); + } + + @Test + public void testMerge_ListsWithSharedValues_NoDuplicate(){ + Address anotherAddress = new PrivateAddress(1,"Another Private Street", new City("Norvege","Honningsvag"),0,null); + + addressList.add(someAddress); + addressList.add(anotherAddress); + + AddressList anotherList = new AddressList(); + anotherList.add(anotherAddress); + + AddressList mergedLists = addressList.merge(anotherList); + + assertNotNull(mergedLists); + assertEquals(2, mergedLists.get().size()); + + + } + @Test + public void testMerge_EmptyGroupList_SameGroupList(){ + AddressList anotherList = new AddressList(); + + addressList.add(someAddress); + + AddressList mergedLists = addressList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someAddress)); + assertEquals(1, mergedLists.get().size()); + } + + @Test + public void testMerge_NullGroupList_ExceptionThrown(){ + addressList.add(someAddress); + + assertThrows(NullPointerException.class, ()->addressList.merge(null)); + } + + + +} \ No newline at end of file diff --git a/src/main/test/fr/unantes/software/construction/address/CompanyAddressTest.java b/src/main/test/fr/unantes/software/construction/address/CompanyAddressTest.java new file mode 100644 index 00000000..5963ae1e --- /dev/null +++ b/src/main/test/fr/unantes/software/construction/address/CompanyAddressTest.java @@ -0,0 +1,144 @@ +package fr.unantes.software.construction.address; + +import fr.unantes.software.construction.Client; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.InvalidClassException; + +import static org.junit.jupiter.api.Assertions.*; + +class CompanyAddressTest { + CompanyAddress companyAddress; + + @BeforeEach + void setUp() { + companyAddress = new CompanyAddress(161,"Buikslotermeerplein ",new City("Netherlands","Amsterdam"),1025,null,null); + } + /** + * Related to superclass Address + */ + @Test + void test_CompleteHandshakeWith_Client() throws InvalidClassException { + CompanyAddress anotherCompanyAddress = new CompanyAddress(2,"boulevard de l'Industrie",new City("France", "Anger"),49000,null,null); + + Client client1 = new Client("Blender Foundation", "company"); + Client client2 = new Client("Scania","company"); + + + companyAddress.getRefClient().set(client1); + anotherCompanyAddress.getRefClient().set(client2); + + companyAddress.getRefClient().set(client2); + + assertFalse(client1.getAddressRef().isSet()); + assertFalse(anotherCompanyAddress.getRefClient().isSet()); + assertEquals(companyAddress, client2.getAddressRef().get()); + } + + @Test + void testSetZipCode_PositiveIntegerValue_Succeed(){ + Integer newValue = 574050; + assertDoesNotThrow(()->companyAddress.setZipCode(newValue)); + assertEquals(newValue, companyAddress.getZipCode()); + } + + @Test + void testSetZipCode_NegativeIntegerValue_ExceptionThrown(){ + Integer oldValue = companyAddress.getZipCode(); + + assertThrows(IllegalArgumentException.class,()->companyAddress.setZipCode(-5)); + assertEquals(oldValue, companyAddress.getZipCode()); + } + + @Test + void testSetZipCode_NullValue_ExceptionThrown(){ + Integer oldValue = companyAddress.getZipCode(); + + assertThrows(NullPointerException.class,()->companyAddress.setZipCode(null)); + assertEquals(oldValue, companyAddress.getZipCode()); + } + + @Test + void testSetStreet_SomeStringValue_Succeed(){ + String newValue = "Buikslotermeerplein"; + + assertDoesNotThrow(()->companyAddress.setStreet(newValue)); + assertEquals(newValue, companyAddress.getStreet()); + } + + @Test + void testSetStreet_NullValue_ExceptionThrown(){ + String oldValue = companyAddress.getStreet(); + + assertThrows(NullPointerException.class,()->companyAddress.setStreet(null)); + assertEquals(oldValue, companyAddress.getStreet()); + } + + @Test + void testSetLocality_AnyStringValue_Succeed(){ + String newValue = "un lieu-dit"; + + assertDoesNotThrow(()->companyAddress.setLocality(newValue)); + assertEquals(newValue, companyAddress.getLocality()); + + assertDoesNotThrow(()->companyAddress.setLocality(null)); + assertEquals(null, companyAddress.getLocality()); + } + + @Test + void testSetCity_SomeCity_Succeed(){ + City newCity = new City("Netherlands","not Amsterdam"); + + assertDoesNotThrow(()->companyAddress.setCity(newCity)); + assertEquals(newCity, companyAddress.getCity()); + } + + @Test + void testSetCity_NullValue_ExceptionThrown(){ + City oldCity = companyAddress.getCity(); + + assertThrows(NullPointerException.class,()->companyAddress.setCity(null)); + assertEquals(oldCity, companyAddress.getCity()); + } + + + @Test + void testSetStreetNumber_PositiveIntegerValue_Succeed(){ + Integer newValue = 160; + assertDoesNotThrow(()->companyAddress.setStreetNumber(newValue)); + assertEquals(newValue, companyAddress.getStreetNumber()); + } + + @Test + void testSetStreetNumber_NegativeIntegerValue_ExceptionThrown(){ + Integer oldValue = companyAddress.getStreetNumber(); + + assertThrows(IllegalArgumentException.class,()->companyAddress.setStreetNumber(-5)); + assertEquals(oldValue, companyAddress.getStreetNumber()); + } + + @Test + void testSetStreetNumber_NullValue_ExceptionThrown(){ + Integer oldValue = companyAddress.getStreetNumber(); + + assertThrows(NullPointerException.class,()->companyAddress.setStreetNumber(null)); + assertEquals(oldValue, companyAddress.getStreetNumber()); + } + + + /** + * Related to Company Address + */ + + @Test + void testSetZone_AnyStringValue_Succeed(){ + String newValue = "une zone"; + + assertDoesNotThrow(()->companyAddress.setZone(newValue)); + assertEquals(newValue, companyAddress.getZone()); + + assertDoesNotThrow(()->companyAddress.setZone(null)); + assertEquals(null, companyAddress.getZone()); + } +} \ No newline at end of file diff --git a/src/main/test/fr/unantes/software/construction/address/PrivateAddressTest.java b/src/main/test/fr/unantes/software/construction/address/PrivateAddressTest.java new file mode 100644 index 00000000..d3da61ab --- /dev/null +++ b/src/main/test/fr/unantes/software/construction/address/PrivateAddressTest.java @@ -0,0 +1,130 @@ +package fr.unantes.software.construction.address; + +import fr.unantes.software.construction.Client; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.InvalidClassException; + +import static org.junit.jupiter.api.Assertions.*; + +class PrivateAddressTest { + PrivateAddress privateAddress; + + @BeforeEach + void setUp() { + privateAddress = new PrivateAddress(712,"Red Bark Lane",new City("United-States","Henderson"),89011,null); + + } + /* + * Related to superclass Address + */ + + @Test + void test_CompleteHandshakeWith_Client() throws InvalidClassException { + PrivateAddress anotherPersonalAddress = new PrivateAddress(742,"Evergreen Terrasse",new City("United-States", "Springfield"),0,null); + + Client client1 = new Client("Tom", "private"); + Client client2 = new Client("Jerry","private"); + + + privateAddress.getRefClient().set(client1); + anotherPersonalAddress.getRefClient().set(client2); + + privateAddress.getRefClient().set(client2); + + assertFalse(client1.getAddressRef().isSet()); + assertFalse(anotherPersonalAddress.getRefClient().isSet()); + assertEquals(privateAddress, client2.getAddressRef().get()); + } + + @Test + void testSetZipCode_PositiveIntegerValue_Succeed(){ + Integer newValue = 574050; + assertDoesNotThrow(()->privateAddress.setZipCode(newValue)); + assertEquals(newValue, privateAddress.getZipCode()); + } + + @Test + void testSetZipCode_NegativeIntegerValue_ExceptionThrown(){ + Integer oldValue = privateAddress.getZipCode(); + + assertThrows(IllegalArgumentException.class,()->privateAddress.setZipCode(-5)); + assertEquals(oldValue, privateAddress.getZipCode()); + } + + @Test + void testSetZipCode_NullValue_ExceptionThrown(){ + Integer oldValue = privateAddress.getZipCode(); + + assertThrows(NullPointerException.class,()->privateAddress.setZipCode(null)); + assertEquals(oldValue, privateAddress.getZipCode()); + } + + @Test + void testSetStreet_SomeStringValue_Succeed(){ + String newValue = "Buikslotermeerplein"; + + assertDoesNotThrow(()->privateAddress.setStreet(newValue)); + assertEquals(newValue, privateAddress.getStreet()); + } + + @Test + void testSetStreet_NullValue_ExceptionThrown(){ + String oldValue = privateAddress.getStreet(); + + assertThrows(NullPointerException.class,()->privateAddress.setStreet(null)); + assertEquals(oldValue, privateAddress.getStreet()); + } + + @Test + void testSetLocality_AnyStringValue_Succeed(){ + String newValue = "un lieu-dit"; + + assertDoesNotThrow(()->privateAddress.setLocality(newValue)); + assertEquals(newValue, privateAddress.getLocality()); + + assertDoesNotThrow(()->privateAddress.setLocality(null)); + assertEquals(null, privateAddress.getLocality()); + } + + @Test + void testSetCity_SomeCity_Succeed(){ + City newCity = new City("Netherlands","not Amsterdam"); + + assertDoesNotThrow(()->privateAddress.setCity(newCity)); + assertEquals(newCity, privateAddress.getCity()); + } + + @Test + void testSetCity_NullValue_ExceptionThrown(){ + City oldCity = privateAddress.getCity(); + + assertThrows(NullPointerException.class,()->privateAddress.setCity(null)); + assertEquals(oldCity, privateAddress.getCity()); + } + + + @Test + void testSetStreetNumber_PositiveIntegerValue_Succeed(){ + Integer newValue = 160; + assertDoesNotThrow(()->privateAddress.setStreetNumber(newValue)); + assertEquals(newValue, privateAddress.getStreetNumber()); + } + + @Test + void testSetStreetNumber_NegativeIntegerValue_ExceptionThrown(){ + Integer oldValue = privateAddress.getStreetNumber(); + + assertThrows(IllegalArgumentException.class,()->privateAddress.setStreetNumber(-5)); + assertEquals(oldValue, privateAddress.getStreetNumber()); + } + + @Test + void testSetStreetNumber_NullValue_ExceptionThrown(){ + Integer oldValue = privateAddress.getStreetNumber(); + + assertThrows(NullPointerException.class,()->privateAddress.setStreetNumber(null)); + assertEquals(oldValue, privateAddress.getStreetNumber()); + } +} \ No newline at end of file -- GitLab From 3bb7e2e677b2fd836f64205e083f45a9959e06f6 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Sun, 22 Mar 2020 16:12:03 +0100 Subject: [PATCH 060/120] Fixed issues with set() and unset() methods --- .../construction/references/SingleReference.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/references/SingleReference.java b/src/main/java/fr/unantes/software/construction/references/SingleReference.java index 8c506a6b..a3ccb828 100644 --- a/src/main/java/fr/unantes/software/construction/references/SingleReference.java +++ b/src/main/java/fr/unantes/software/construction/references/SingleReference.java @@ -27,19 +27,16 @@ public abstract class SingleReference implements Reference{ } public void unset(){ - if (isSet()) return; - else { - this.oppositeFor(target).unset(); + if (!isSet()) return; + this.oppositeFor(target).basicUnset(); this.basicUnset(); - oppositeFor(target).basicSet(container); - } } public void set(T newTarget){ - this.unset(); - oppositeFor(target).unset(); + if (isSet()) this.unset(); + if (oppositeFor(newTarget).isSet()) oppositeFor(newTarget).unset(); + oppositeFor(newTarget).basicSet(container); this.basicSet(newTarget); - oppositeFor(target).basicUnset(); } public abstract SingleReference oppositeFor(T target); -- GitLab From ad0eb68bcbab156919d1a5e32008e403b77105ec Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Sun, 22 Mar 2020 16:13:07 +0100 Subject: [PATCH 061/120] Altered SingleReferences behavior to match bidirectional tests --- .../unantes/software/construction/Client.java | 37 +- .../construction/address/Address.java | 334 +++++++++--------- 2 files changed, 196 insertions(+), 175 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/Client.java b/src/main/java/fr/unantes/software/construction/Client.java index 9af5f755..865fbc35 100644 --- a/src/main/java/fr/unantes/software/construction/Client.java +++ b/src/main/java/fr/unantes/software/construction/Client.java @@ -2,32 +2,35 @@ package fr.unantes.software.construction; import fr.unantes.software.construction.address.Address; import fr.unantes.software.construction.address.Card; - -import fr.unantes.software.construction.references.ManyToOneReference; import fr.unantes.software.construction.references.MultipleReference; -import fr.unantes.software.construction.references.OneToManyReference; import fr.unantes.software.construction.references.SingleReference; import java.io.InvalidClassException; public class Client { - public String name; - public String role; - public final MultipleReference accounts = new MultipleReference(this) { + private String name; + private String role; + private final MultipleReference accounts = new MultipleReference(this) { @Override public MultipleReference oppositeFor(Account target) { return target.getOwner(); } }; private short accountSize = 0; - public Card card; - private OneToOneAssociation refAddress = new OneToOneAssociation<>(this); + private Card card; + private SingleReference refAddress = new SingleReference(this) { + @Override + public SingleReference oppositeFor(Address target) { + return target.getRefClient(); + } + }; + /* + public OneToOneAssociation refAddress = new OneToOneAssociation<>(this); - /** - * Inner class to describe Bidirectional Monovalued Association between Address & Client - */ - private class OneToOneAssociation extends - SingleReference { + // Inner class to describe Bidirectional Monovalued Association between Address & Client + + public class OneToOneAssociation extends + SingleReference { public OneToOneAssociation(Client a) { super(a); @@ -38,7 +41,7 @@ public class Client { return refAddress; } } - + */ public Client(String name, String role) throws InvalidClassException { if (!role.equals("private") && !role.equals("company")) { @@ -49,7 +52,11 @@ public class Client { } public Address getAddress(){ - return (Address)this.refAddress.get(); + return (Address) refAddress.get(); + } + + public SingleReference getAddressRef(){ + return refAddress; } public void setAddress(Address add){ diff --git a/src/main/java/fr/unantes/software/construction/address/Address.java b/src/main/java/fr/unantes/software/construction/address/Address.java index ead13f52..12c0c7f4 100755 --- a/src/main/java/fr/unantes/software/construction/address/Address.java +++ b/src/main/java/fr/unantes/software/construction/address/Address.java @@ -1,161 +1,175 @@ -package fr.unantes.software.construction.address; - -import fr.unantes.software.construction.Client; -import fr.unantes.software.construction.references.SingleReference; - -/** - * - * @author - * @version 1.0 - * @date 17/12/2004. - */ -public abstract class Address { - - protected Integer streetNumber; - protected String streetName; - protected City city; - protected Integer zipCode; - protected String locality; //Lieu-dit - protected OneToOneAssociation refClient = new OneToOneAssociation<>(this); - - /** - * Inner class to describe Bidirectional Monovalued Association between Address & Client - */ - protected class OneToOneAssociation extends - SingleReference { - - public OneToOneAssociation(Address a) { - super(a); - } - - @Override - public SingleReference oppositeFor(Object target) { - return refClient; - } - } - - public OneToOneAssociation getRefClient() { - return refClient; - } - - public void setRefClient(OneToOneAssociation refClient) { - this.refClient = refClient; - } - - public Address() { - streetNumber = 0; - zipCode = 0; - } - - /** - * - * @param streetNumber le numero de la voie - * @param street le nom de la rue - * @param city le nom de la ville - * @param zipCode le numero de code postal - */ - public Address(Integer streetNumber, String street, City city, Integer zipCode, - String locality) { - this.streetNumber = streetNumber; - this.streetName = street; - this.city = city; - this.zipCode = zipCode; - this.locality = locality; - } - - /** - * - * - * @param address une adresse - */ - //TODO this is a copy constructor, doesn't it violate the 1-1 associationwith Client ? - public Address(Address address) { - this.streetNumber = address.getStreetNumber(); - this.streetName = address.getStreet(); - this.city = address.getCity(); - this.zipCode = address.getZipCode(); - } - - - /* - * @return streetNumber le numero de la voie - */ - public Integer getStreetNumber() { - return streetNumber; - } - - /* - * @return streetName le nom de la rue - */ - public String getStreet() { - return streetName; - } - - /* - * @return city le nom de la ville - */ - public City getCity() { - return city; - } - - /** - * @return zipCode le numero du code postal - */ - public int getZipCode() { - return zipCode; - } - - /** - * @return _lieu_dit le nom du lieu dit - */ - public String getLocality() { - return locality; - } - - /** - * @param streetNumber - */ - public void setStreetNumber(Integer streetNumber) { - this.streetNumber = streetNumber; - } - - /** - * @param street le nom de la rue - */ - public void setStreet(String street) { - streetName = street; - } - - /** - * @param locality le nom du lieu dit - */ - public void setLocality(String locality) { - this.locality = locality; - } - - /** - * @param city - * le nom de la ville - */ - public void setCity(City city) { - this.city = city; - } - - /** - * @param zipCode le numero de code postal - */ - public void setZipCode(int zipCode) { - this.zipCode = zipCode; - } - - /** - * - */ - public String toString() { - return ("" + streetNumber + ", " + streetName + " " + city + " " + zipCode - ); - } - - - public abstract String toXML(); +package fr.unantes.software.construction.address; + +import fr.unantes.software.construction.Client; + +import fr.unantes.software.construction.references.SingleReference; +import org.apache.commons.lang3.Validate; + +/** + * + * @author + * @version 1.0 + * @date 17/12/2004. + */ +public abstract class Address { + + protected Integer streetNumber; + protected String streetName; + protected City city; + protected Integer zipCode; + protected String locality; //Lieu-dit + private SingleReference refClient = new SingleReference(this) { + @Override + public SingleReference oppositeFor(Client target) { + return target.getAddressRef(); + } + }; + /* + protected OneToOneAssociation refClient = new OneToOneAssociation<>(this); + + // Inner class to describe Bidirectional Monovalued Association between Address & Client + + protected class OneToOneAssociation extends + SingleReference { + + public OneToOneAssociation(Address a) { + super(a); + } + + @Override + public SingleReference oppositeFor(Object target) { + return refClient; + } + } + */ + + + + + + public SingleReference getRefClient() { + return refClient; + } + + public void setRefClient(SingleReference refClient) { + this.refClient = refClient; + } + + /** + * + * @param streetNumber le numero de la voie + * @param street le nom de la rue + * @param city le nom de la ville + * @param zipCode le numero de code postal + */ + public Address(Integer streetNumber, String street, City city, Integer zipCode, + String locality) { + this.streetNumber = streetNumber; + this.streetName = street; + this.city = city; + this.zipCode = zipCode; + this.locality = locality; + } + + /** + * + * + * @param address une adresse + */ + //TODO this is a copy constructor, doesn't it violate the 1-1 associationwith Client ? + public Address(Address address) { + this.streetNumber = address.getStreetNumber(); + this.streetName = address.getStreet(); + this.city = address.getCity(); + this.zipCode = address.getZipCode(); + } + + + /* + * @return streetNumber le numero de la voie + */ + public Integer getStreetNumber() { + return streetNumber; + } + + /* + * @return streetName le nom de la rue + */ + public String getStreet() { + return streetName; + } + + /* + * @return city le nom de la ville + */ + public City getCity() { + return city; + } + + /** + * @return zipCode le numero du code postal + */ + public Integer getZipCode() { + return zipCode; + } + + /** + * @return _lieu_dit le nom du lieu dit + */ + public String getLocality() { + return locality; + } + + /** + * @param streetNumber + */ + public void setStreetNumber(Integer streetNumber) { + Validate.notNull(streetName); + Validate.isTrue(streetNumber>=1); + this.streetNumber = streetNumber; + } + + /** + * @param street le nom de la rue + */ + public void setStreet(String street) { + Validate.notNull(street); + streetName = street; + } + + /** + * @param locality le nom du lieu dit + */ + public void setLocality(String locality) { + this.locality = locality; + } + + /** + * @param city + * le nom de la ville + */ + public void setCity(City city) { + Validate.notNull(city); + this.city = city; + } + + /** + * @param zipCode le numero de code postal + */ + public void setZipCode(Integer zipCode) { + Validate.notNull(zipCode); + Validate.isTrue(zipCode>=0); + this.zipCode = zipCode; + } + + /** + * + */ + public String toString() { + return ("" + streetNumber + ", " + streetName + " " + city + " " + zipCode + ); + } + + + public abstract String toXML(); } \ No newline at end of file -- GitLab From 9448f54ac30d91c44be6a4ec8a85ccab239f13fe Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Sun, 22 Mar 2020 16:14:02 +0100 Subject: [PATCH 062/120] Modified Address and related classes to match their tests --- .../construction/address/AddressBook.java | 4 +++- .../construction/address/AddressList.java | 23 +++++++++++-------- .../construction/address/CompanyAddress.java | 10 ++++---- .../construction/address/PrivateAddress.java | 9 +++----- 4 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/address/AddressBook.java b/src/main/java/fr/unantes/software/construction/address/AddressBook.java index 175968e6..4cd58dd8 100755 --- a/src/main/java/fr/unantes/software/construction/address/AddressBook.java +++ b/src/main/java/fr/unantes/software/construction/address/AddressBook.java @@ -1,5 +1,6 @@ package fr.unantes.software.construction.address; + /** * * @author @@ -48,8 +49,9 @@ public class AddressBook { * @return */ public AddressBook merge(AddressBook addressBook, String name) { - AddressBook newBook = new AddressBook(); CardList newCard = this.cards.merge(addressBook.getCards()); + AddressBook newBook = new AddressBook(); + newBook.setName(name); newBook.setCards(newCard); return newBook; diff --git a/src/main/java/fr/unantes/software/construction/address/AddressList.java b/src/main/java/fr/unantes/software/construction/address/AddressList.java index a17d4dbc..244268b9 100755 --- a/src/main/java/fr/unantes/software/construction/address/AddressList.java +++ b/src/main/java/fr/unantes/software/construction/address/AddressList.java @@ -7,6 +7,8 @@ package fr.unantes.software.construction.address; * @date 17/12/2004. */ +import org.apache.commons.lang3.Validate; + import java.util.*; public class AddressList { @@ -33,7 +35,7 @@ public class AddressList { /** Accesseur */ /** - * @return _listeAdresse + * @return addresses */ public Vector get() { return addresses; @@ -54,14 +56,15 @@ public class AddressList { * @param address adresse a add dans la liste */ public void add(Address address) { + Validate.notNull(address); if (!find(address)) addresses.add(address); } /** - * @param address adresse a remove de la liste + * @param address adresse a delete de la liste */ - public void remove(Address address) { + public void delete(Address address) { if (find(address)) addresses.remove(address); else @@ -76,14 +79,15 @@ public class AddressList { } /** - * fusion entre 2 listes dans une nouvelle. + * merge entre 2 listes dans une nouvelle. * - * @param l l'autre liste. - * @return une nouvelle liste, fusion des deux autres. + * @param addresses l'autre liste. + * @return une nouvelle liste, merge des deux autres. * */ - public AddressList fusion(AddressList addresses) { + public AddressList merge(AddressList addresses) { AddressList newAddressList = new AddressList(); + Address nextAddress; /** * on met toute les addresses de la premiere liste dans la liste de @@ -100,8 +104,9 @@ public class AddressList { */ for (Enumeration e1 = addresses.get().elements(); e1 .hasMoreElements();) { - if (!(newAddressList.find((Address) e1.nextElement()))) { - newAddressList.add((Address) e1.nextElement()); + nextAddress = (Address) e1.nextElement(); + if (!(newAddressList.find(nextAddress))) { + newAddressList.add(nextAddress); } } return newAddressList; diff --git a/src/main/java/fr/unantes/software/construction/address/CompanyAddress.java b/src/main/java/fr/unantes/software/construction/address/CompanyAddress.java index 88597d13..cc1617e0 100755 --- a/src/main/java/fr/unantes/software/construction/address/CompanyAddress.java +++ b/src/main/java/fr/unantes/software/construction/address/CompanyAddress.java @@ -16,10 +16,10 @@ public class CompanyAddress extends Address { /** * Constructeur vide - */ + *//* public CompanyAddress() { super(); - } + }*/ /** * @@ -41,11 +41,9 @@ public class CompanyAddress extends Address { * @param address une adresse */ public CompanyAddress(CompanyAddress address) { + super(address); + locality = address.getLocality(); zone = address.getZone(); - streetNumber = address.getStreetNumber(); - streetName = address.getStreet(); - city = address.getCity(); - zipCode = address.getZipCode(); } /** diff --git a/src/main/java/fr/unantes/software/construction/address/PrivateAddress.java b/src/main/java/fr/unantes/software/construction/address/PrivateAddress.java index 45af3df2..bbab3e33 100755 --- a/src/main/java/fr/unantes/software/construction/address/PrivateAddress.java +++ b/src/main/java/fr/unantes/software/construction/address/PrivateAddress.java @@ -8,11 +8,11 @@ package fr.unantes.software.construction.address; public class PrivateAddress extends Address { private String locality; - +/* public PrivateAddress() { super(); } - +*/ /** * * @@ -32,11 +32,8 @@ public class PrivateAddress extends Address { * @param address une adresse */ public PrivateAddress(PrivateAddress address) { - streetNumber = address.getStreetNumber(); - streetName = address.getStreet(); + super(address); locality = address.getLocality(); - city = address.getCity(); - zipCode = address.getZipCode(); } /** Les accesseurs */ -- GitLab From 1dbf3ef7cd72d9e5481d970a13663731da633099 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Sun, 22 Mar 2020 16:15:01 +0100 Subject: [PATCH 063/120] Modified classes impacted by new behavior of Address and related --- .../software/construction/address/CardList.java | 11 +++++++---- .../software/construction/address/CompanyCard.java | 2 +- .../software/construction/address/PrivateCard.java | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/address/CardList.java b/src/main/java/fr/unantes/software/construction/address/CardList.java index 1ec8af43..de953fab 100755 --- a/src/main/java/fr/unantes/software/construction/address/CardList.java +++ b/src/main/java/fr/unantes/software/construction/address/CardList.java @@ -70,20 +70,23 @@ public class CardList { */ public CardList merge(CardList cards){ CardList res = new CardList(); + Card nextCard, nextCard1; boolean r; for (Enumeration e = this.cards.elements(); e.hasMoreElements() ;) { r =false; + nextCard = (Card)e.nextElement(); for (Enumeration e1 = cards.get().elements(); e1.hasMoreElements() ;) { - if(((Card)e.nextElement()).identicalCard((Card)e1.nextElement())){ - res.add(((Card)e.nextElement()).merge((Card)e1.nextElement())); + nextCard1 = (Card)e1.nextElement(); + if((nextCard).identicalCard(nextCard1)){ + res.add((nextCard).merge(nextCard1)); r = true; } else{ - res.add((Card)e1.nextElement()); + res.add(nextCard1); } } - if (!r) res.add((Card)e.nextElement()); + if (!r) res.add(nextCard); } return res; } diff --git a/src/main/java/fr/unantes/software/construction/address/CompanyCard.java b/src/main/java/fr/unantes/software/construction/address/CompanyCard.java index 8ca0d8e5..2561bd24 100755 --- a/src/main/java/fr/unantes/software/construction/address/CompanyCard.java +++ b/src/main/java/fr/unantes/software/construction/address/CompanyCard.java @@ -25,7 +25,7 @@ public class CompanyCard extends Card { card.setIdentification(identification); card.setCompanyName(companyName); - newCard.setAddresses(addresses.fusion(card.getAddresses())); + newCard.setAddresses(addresses.merge(card.getAddresses())); newCard.setPhones(phones.merge(card.getPhones())); newCard.setMails(mails.merge(card.getMails())); newCard.setGroups(groups.merge(card.getGroups())); diff --git a/src/main/java/fr/unantes/software/construction/address/PrivateCard.java b/src/main/java/fr/unantes/software/construction/address/PrivateCard.java index 970a6663..db960bd5 100755 --- a/src/main/java/fr/unantes/software/construction/address/PrivateCard.java +++ b/src/main/java/fr/unantes/software/construction/address/PrivateCard.java @@ -80,7 +80,7 @@ public class PrivateCard extends Card { newCard.setPrenom(card.getFirstName()); else newCard.setPrenom(firstName); - newCard.setAddresses(addresses.fusion(card.getAddresses())); + newCard.setAddresses(addresses.merge(card.getAddresses())); newCard.setPhones(phones.merge(card.getPhones())); newCard.setMails(mails.merge(card.getMails())); newCard.setGroups(groups.merge(card.getGroups())); -- GitLab From f495ca706ab8cdb0f0a2d9c9ce7732af0d6771d3 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Mon, 23 Mar 2020 16:58:52 +0100 Subject: [PATCH 064/120] Added unit test to check Card and related classes behavior --- .../construction/address/CardListTest.java | 164 +++++++++++ .../construction/address/CompanyCardTest.java | 266 +++++++++++++++++ .../construction/address/PrivateCardTest.java | 276 ++++++++++++++++++ 3 files changed, 706 insertions(+) create mode 100644 src/main/test/fr/unantes/software/construction/address/CardListTest.java create mode 100644 src/main/test/fr/unantes/software/construction/address/CompanyCardTest.java create mode 100644 src/main/test/fr/unantes/software/construction/address/PrivateCardTest.java diff --git a/src/main/test/fr/unantes/software/construction/address/CardListTest.java b/src/main/test/fr/unantes/software/construction/address/CardListTest.java new file mode 100644 index 00000000..e2e0fbea --- /dev/null +++ b/src/main/test/fr/unantes/software/construction/address/CardListTest.java @@ -0,0 +1,164 @@ +package fr.unantes.software.construction.address; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.Vector; + +import static org.junit.jupiter.api.Assertions.*; + +class CardListTest { + CardList cardList; + Card someCard; + @BeforeEach + void setUp() { + cardList = new CardList(); + someCard = new PrivateCard("John","Doe"); + } + + @Test + void testSet_ListOfCards_addCardsToCurrentList(){ + Vector anotherList = new Vector(); + Card[] cards = { someCard, + new PrivateCard("Tom","Joe"), + new CompanyCard("JohnDoe Corp.") + }; + + for(Card each : cards){ + anotherList.add(each); + } + + cardList.set(anotherList); + + for(Card each : cards){ + assertTrue(cardList.find(each)); + } + } + + @Test + void testSet_NullValue_ExceptionThrown(){ + assertThrows(Exception.class, ()-> cardList.set(null)); + } + + + @Test + public void testAdd_newValue_Succeed(){ + assertDoesNotThrow(() -> cardList.add(someCard)); + assertTrue(cardList.find(someCard)); + } + + @Test + public void testAdd_alreadyContainedValue_noDuplicate(){ + cardList.add(someCard); + int currentSize = cardList.get().size(); + + cardList.add(someCard); + assertEquals(currentSize, cardList.get().size()); + } + + @Test + public void testAdd_NullValue_ExceptionThrown(){ + int currentSize = cardList.get().size(); + assertThrows(Exception.class, () -> cardList.add(null)); + assertEquals(currentSize, cardList.get().size()); + } + + @Test + public void testDelete_ContainedValue_Succeed(){ + cardList.add(someCard); + cardList.delete(someCard); + + assertFalse(cardList.find(someCard)); + } + + @Test + public void testDelete_ValueContainedByAnotherGroup_NoEffect(){ + CardList anotherList = new CardList(); + anotherList.add(someCard); + + int currentSize = cardList.get().size(); + assertFalse(cardList.find(someCard)); + + cardList.delete(someCard); + assertTrue(anotherList.find(someCard)); + assertEquals(currentSize, cardList.get().size()); + } + + @Test + public void testFind_ContainedValue_ReturnTrue(){ + cardList.add(someCard); + assertTrue(cardList.find(someCard)); + } + + @Test + public void testFind_NotContainedValue_ReturnFalse(){ + cardList.add(new PrivateCard("Tom","Joe")); + assertFalse(cardList.find(someCard)); + } + + @Test + public void testMerge_TwoDifferentLists_ReturnListWithBothValue(){ + cardList.add(someCard); + + Card anotherCard = new PrivateCard("Tom", "Joe"); + CardList anotherList = new CardList(); + anotherList.add(anotherCard); + + CardList mergedLists = cardList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someCard)); + assertTrue(mergedLists.find(anotherCard)); + assertEquals(2, mergedLists.get().size()); + } + + @Test + public void testMerge_SameLists_NoChange(){ + cardList.add(someCard); + + CardList mergedLists = cardList.merge(cardList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someCard)); + assertEquals(cardList.get().size(), mergedLists.get().size()); + } + + @Test + public void testMerge_ListsWithSharedValues_NoDuplicate(){ + Card anotherCard = new PrivateCard("Tom", "Joe"); + + cardList.add(someCard); + cardList.add(anotherCard); + + CardList anotherList = new CardList(); + anotherList.add(anotherCard); + + CardList mergedLists = cardList.merge(anotherList); + + assertNotNull(mergedLists); + assertEquals(2, mergedLists.get().size()); + + + } + @Test + public void testMerge_EmptyCardList_SameCardList(){ + CardList anotherList = new CardList(); + + cardList.add(someCard); + + CardList mergedLists = cardList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someCard)); + assertEquals(1, mergedLists.get().size()); + } + + @Test + public void testMerge_NullCardList_ExceptionThrown(){ + cardList.add(someCard); + + assertThrows(NullPointerException.class, ()-> cardList.merge(null)); + } + + +} \ No newline at end of file diff --git a/src/main/test/fr/unantes/software/construction/address/CompanyCardTest.java b/src/main/test/fr/unantes/software/construction/address/CompanyCardTest.java new file mode 100644 index 00000000..8e745aa0 --- /dev/null +++ b/src/main/test/fr/unantes/software/construction/address/CompanyCardTest.java @@ -0,0 +1,266 @@ +package fr.unantes.software.construction.address; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.internal.matchers.Null; + +import static org.junit.jupiter.api.Assertions.*; + +class CompanyCardTest { + CompanyCard companyCard; + AddressList someAddresses; CompanyAddress anAddress; + PhoneList somePhones; Phone aPhone; + MailList someMails; Mail aMail; + GroupList someGroups; Group aGroup; + + + @BeforeEach + void setUp() { + companyCard = new CompanyCard("companyName"); + + someAddresses = new AddressList(); + somePhones = new PhoneList(); + someMails = new MailList(); + someGroups = new GroupList(); + + anAddress = new CompanyAddress(1, "Some Company Street", new City("Groenland", "Qeqertarsuaq"), 0, null,null); + someAddresses.add(anAddress); + companyCard.setAddresses(someAddresses); + aPhone = new Phone(0202020202, ""); + somePhones.add(aPhone); + companyCard.setPhones(somePhones); + aMail = new Mail(null, "work@mail.io"); + someMails.add(aMail); + companyCard.setMails(someMails); + aGroup = new Group("someName", ""); + someGroups.add(aGroup); + companyCard.setGroups(someGroups); + } + + /* + * Superclass related tests + */ + @Test + void testSetAddresses_SomeAddressList_Succeed(){ + AddressList someList = new AddressList(); + companyCard.setAddresses(someList); + + assertEquals(someList, companyCard.getAddresses()); + } + + @Test + void testSetAddresses_NullValue_ExceptionThrown(){ + assertThrows(NullPointerException.class, ()-> companyCard.setAddresses(null)); + assertNotEquals(null, companyCard.getAddresses()); + } + + @Test + void testSetPhones_SomePhoneList_Succeed(){ + PhoneList someList = new PhoneList(); + companyCard.setPhones(someList); + + assertEquals(someList, companyCard.getPhones()); + } + + @Test + void testSetPhones_NullValue_ExceptionThrown(){ + assertThrows(NullPointerException.class, ()-> companyCard.setPhones(null)); + assertNotEquals(null, companyCard.getPhones()); + } + + @Test + void testSetMails_SomeMailList_Succeed(){ + MailList someList = new MailList(); + companyCard.setMails(someList); + + assertEquals(someList, companyCard.getMails()); + } + + @Test + void testSetMails_NullValue_ExceptionThrown(){ + assertThrows(NullPointerException.class, ()-> companyCard.setMails(null)); + assertNotEquals(null, companyCard.getMails()); + } + + @Test + void testSetGroups_SomeGroupList_Succeed(){ + GroupList someList = new GroupList(); + companyCard.setGroups(someList); + + assertEquals(someList, companyCard.getGroups()); + } + + @Test + void testSetGroups_NullValue_ExceptionThrown(){ + assertThrows(NullPointerException.class, ()-> companyCard.setGroups(null)); + assertNotEquals(null, companyCard.getGroups()); + } + + @Test + void testSetIdentification_AnyStringValue_Succeed(){ + companyCard.setIdentification("id002"); + + assertEquals("id002", companyCard.getIdentification()); + + } + + @Test + void testSetIdentification_NullValue_ExceptionThrown(){ + assertThrows(NullPointerException.class, ()-> companyCard.setIdentification(null)); + assertNotEquals(null, companyCard.getIdentification()); + } + + @Test + void testIdenticalCard_SameCardId_ReturnTrue(){ + CompanyCard anotherCard = new CompanyCard("companyName"); + + assertEquals(anotherCard.getIdentification(), companyCard.getIdentification()); + assertTrue(companyCard.identicalCard(anotherCard)); + } + + @Test + void testIdenticalCard_DifferentCardId_ReturnFalse(){ + CompanyCard anotherCard = new CompanyCard("001"); + + assertNotEquals(anotherCard.getIdentification(), companyCard.getIdentification()); + assertFalse(companyCard.identicalCard(anotherCard)); + } + + /* + * CompanyCard + */ + @Test + void testSetCompanyName_SomeStringValue_Succeed(){ + companyCard.setCompanyName("some Company"); + assertEquals("some Company", companyCard.getCompanyName()); + } + + @Test + void testSetCompanyName_NullValue_ExceptionThrown(){ + String oldName = companyCard.getCompanyName(); + assertThrows(NullPointerException.class, ()->companyCard.setCompanyName(null)); + assertEquals(oldName, companyCard.getCompanyName()); + } + + @Test + void testMerge_CompanyCardWithSameId_ReturnPrivateCardWithBothValues(){ + CompanyCard anotherCard = new CompanyCard("companyName"); + + AddressList anotherAddresses = new AddressList(); + PhoneList anotherPhones = new PhoneList(); + MailList anotherMails = new MailList(); + GroupList anotherGroups = new GroupList(); + + CompanyAddress anotherAddress = new CompanyAddress(1, "Another Company Street", new City("France", "Angouleme"), 16000, null,null); + anotherAddresses.add(anotherAddress); + anotherCard.setAddresses(anotherAddresses); + Phone anotherPhone = new Phone(0642424242, ""); + anotherPhones.add(anotherPhone); + anotherCard.setPhones(anotherPhones); + Mail anotherMail = new Mail("anotherHome@mail.com", null); + anotherMails.add(anotherMail); + anotherCard.setMails(anotherMails); + Group anotherGroup = new Group("anotherName", ""); + anotherGroups.add(anotherGroup); + anotherCard.setGroups(anotherGroups); + + CompanyCard mergedCard = (CompanyCard) companyCard.merge(anotherCard); + + assertTrue(mergedCard.getAddresses().find(anAddress)); + assertTrue(mergedCard.getAddresses().find(anotherAddress)); + assertEquals(2,mergedCard.getAddresses().get().size()); + + assertTrue(mergedCard.getPhones().find(aPhone)); + assertTrue(mergedCard.getPhones().find(anotherPhone)); + assertEquals(2,mergedCard.getPhones().get().size()); + + assertTrue(mergedCard.getMails().find(aMail)); + assertTrue(mergedCard.getMails().find(anotherMail)); + assertEquals(2,mergedCard.getMails().get().size()); + + assertTrue(mergedCard.getGroups().find(aGroup)); + assertTrue(mergedCard.getGroups().find(anotherGroup)); + assertEquals(2,mergedCard.getGroups().get().size()); + + assertEquals(companyCard.getIdentification(),mergedCard.getIdentification()); + } + + @Test + void testMerge_SameCompanyCard_NoChange(){ + CompanyCard mergedCard = (CompanyCard) companyCard.merge(companyCard); + + assertTrue(mergedCard.getAddresses().find(anAddress)); + assertEquals(1,mergedCard.getAddresses().get().size()); + + assertTrue(mergedCard.getPhones().find(aPhone)); + assertEquals(1,mergedCard.getPhones().get().size()); + + assertTrue(mergedCard.getMails().find(aMail)); + assertEquals(1,mergedCard.getMails().get().size()); + + assertTrue(mergedCard.getGroups().find(aGroup)); + assertEquals(1,mergedCard.getGroups().get().size()); + } + + @Test + void testMerge_CompanyCardsWithSharedValues_NoDuplicate(){ + CompanyCard anotherCard = new CompanyCard("companyName"); + + AddressList anotherAddresses = new AddressList(); + PhoneList anotherPhones = new PhoneList(); + MailList anotherMails = new MailList(); + GroupList anotherGroups = new GroupList(); + CompanyAddress anotherAddress = new CompanyAddress(1, "Another Private Street", new City("France", "Angouleme"), 16000, null,null); + Phone anotherPhone = new Phone(0642424242, ""); + Mail anotherMail = new Mail("anotherHome@mail.com", null); + Group anotherGroup = new Group("anotherName", ""); + + anotherAddresses.add(anotherAddress); + anotherPhones.add(anotherPhone); + anotherMails.add(anotherMail); + anotherGroups.add(anotherGroup); + + anotherCard.setAddresses(someAddresses); + anotherCard.setPhones(somePhones); + anotherCard.setMails(someMails); + anotherCard.setGroups(someGroups); + anotherCard.setAddresses(anotherAddresses); + anotherCard.setPhones(anotherPhones); + anotherCard.setMails(anotherMails); + anotherCard.setGroups(anotherGroups); + + CompanyCard mergedCard = (CompanyCard) companyCard.merge(anotherCard); + + assertTrue(mergedCard.getAddresses().find(anAddress)); + assertTrue(mergedCard.getAddresses().find(anotherAddress)); + assertEquals(2,mergedCard.getAddresses().get().size()); + + assertTrue(mergedCard.getPhones().find(aPhone)); + assertTrue(mergedCard.getPhones().find(anotherPhone)); + assertEquals(2,mergedCard.getPhones().get().size()); + + assertTrue(mergedCard.getMails().find(aMail)); + assertTrue(mergedCard.getMails().find(anotherMail)); + assertEquals(2,mergedCard.getMails().get().size()); + + assertTrue(mergedCard.getGroups().find(aGroup)); + assertTrue(mergedCard.getGroups().find(anotherGroup)); + assertEquals(2,mergedCard.getGroups().get().size()); + } + + @Test + void testMergeCompanyCard_AnyCompanyCard_ReturnNull(){ + assertNull(companyCard.mergePrivateCard(new PrivateCard(null))); + } + + @Test + void testMergeCompanyCard_SomeCompanyCard_KeepCurrentAttributes(){ + CompanyCard anotherCard = new CompanyCard("companyName"); + companyCard.setCompanyName("JohnDoe Inc."); + anotherCard.setCompanyName("TomJoe Corp."); + + CompanyCard mergedCard = companyCard.mergeCompanyCard(anotherCard); + + assertEquals(companyCard.getCompanyName(),mergedCard.getCompanyName()); + } +} \ No newline at end of file diff --git a/src/main/test/fr/unantes/software/construction/address/PrivateCardTest.java b/src/main/test/fr/unantes/software/construction/address/PrivateCardTest.java new file mode 100644 index 00000000..2233af30 --- /dev/null +++ b/src/main/test/fr/unantes/software/construction/address/PrivateCardTest.java @@ -0,0 +1,276 @@ +package fr.unantes.software.construction.address; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class PrivateCardTest { + + PrivateCard someCard; + AddressList someAddresses; PrivateAddress anAddress; + PhoneList somePhones; Phone aPhone; + MailList someMails; Mail aMail; + GroupList someGroups; Group aGroup; + + + @BeforeEach + void setUp() { + someCard = new PrivateCard("000"); + + someAddresses = new AddressList(); + somePhones = new PhoneList(); + someMails = new MailList(); + someGroups = new GroupList(); + + anAddress = new PrivateAddress(1, "Some Private Street", new City("Groenland", "Qeqertarsuaq"), 0, null); + someAddresses.add(anAddress); + someCard.setAddresses(someAddresses); + aPhone = new Phone(0202020202, ""); + somePhones.add(aPhone); + someCard.setPhones(somePhones); + aMail = new Mail("someHome@mail.com", null); + someMails.add(aMail); + someCard.setMails(someMails); + aGroup = new Group("someName", ""); + someGroups.add(aGroup); + someCard.setGroups(someGroups); + } + + /* + * Superclass related tests + */ + @Test + void testSetAddresses_SomeAddressList_Succeed(){ + AddressList someList = new AddressList(); + someCard.setAddresses(someList); + + assertEquals(someList,someCard.getAddresses()); + } + + @Test + void testSetAddresses_NullValue_ExceptionThrown(){ + assertThrows(NullPointerException.class, ()-> someCard.setAddresses(null)); + assertNotEquals(null, someCard.getAddresses()); + } + + @Test + void testSetPhones_SomePhoneList_Succeed(){ + PhoneList someList = new PhoneList(); + someCard.setPhones(someList); + + assertEquals(someList, someCard.getPhones()); + } + + @Test + void testSetPhones_NullValue_ExceptionThrown(){ + assertThrows(NullPointerException.class, ()-> someCard.setPhones(null)); + assertNotEquals(null, someCard.getPhones()); + } + + @Test + void testSetMails_SomeMailList_Succeed(){ + MailList someList = new MailList(); + someCard.setMails(someList); + + assertEquals(someList,someCard.getMails()); + } + + @Test + void testSetMails_NullValue_ExceptionThrown(){ + assertThrows(NullPointerException.class, ()-> someCard.setMails(null)); + assertNotEquals(null, someCard.getMails()); + } + + @Test + void testSetGroups_SomeGroupList_Succeed(){ + GroupList someList = new GroupList(); + someCard.setGroups(someList); + + assertEquals(someList,someCard.getGroups()); + } + + @Test + void testSetGroups_NullValue_ExceptionThrown(){ + assertThrows(NullPointerException.class, ()-> someCard.setGroups(null)); + assertNotEquals(null, someCard.getGroups()); + } + + @Test + void testSetIdentification_AnyStringValue_Succeed(){ + someCard.setIdentification("id002"); + + assertEquals("id002",someCard.getIdentification()); + + } + + @Test + void testSetIdentification_NullValue_ExceptionThrown(){ + assertThrows(NullPointerException.class, ()-> someCard.setIdentification(null)); + assertNotEquals(null, someCard.getIdentification()); + } + + @Test + void testIdenticalCard_SameCardId_ReturnTrue(){ + PrivateCard anotherCard = new PrivateCard("000"); + + assertEquals(anotherCard.getIdentification(),someCard.getIdentification()); + assertTrue(someCard.identicalCard(anotherCard)); + } + + @Test + void testIdenticalCard_DifferentCardId_ReturnFalse(){ + PrivateCard anotherCard = new PrivateCard("001"); + + assertNotEquals(anotherCard.getIdentification(),someCard.getIdentification()); + assertFalse(someCard.identicalCard(anotherCard)); + } + + /* + * PrivateCard + */ + @Test + void testSetLastName_AnyStringValue_Succeed(){ + someCard.setLastName("someone"); + assertEquals("someone",someCard.getLastName()); + + someCard.setLastName(null); + assertNull(someCard.getLastName()); + } + + + @Test + void testSetFirstName_AnyStringValue_Succeed(){ + someCard.setFirstName("someone"); + assertEquals("someone",someCard.getFirstName()); + + someCard.setFirstName(null); + assertNull(someCard.getFirstName()); + } + + @Test + void testMerge_PrivateCardWithSameId_ReturnPrivateCardWithBothValues(){ + PrivateCard anotherCard = new PrivateCard("000"); + + AddressList anotherAddresses = new AddressList(); + PhoneList anotherPhones = new PhoneList(); + MailList anotherMails = new MailList(); + GroupList anotherGroups = new GroupList(); + + PrivateAddress anotherAddress = new PrivateAddress(1, "Another Private Street", new City("France", "Angouleme"), 16000, null); + anotherAddresses.add(anotherAddress); + anotherCard.setAddresses(anotherAddresses); + Phone anotherPhone = new Phone(0642424242, ""); + anotherPhones.add(anotherPhone); + anotherCard.setPhones(anotherPhones); + Mail anotherMail = new Mail("anotherHome@mail.com", null); + anotherMails.add(anotherMail); + anotherCard.setMails(anotherMails); + Group anotherGroup = new Group("anotherName", ""); + anotherGroups.add(anotherGroup); + anotherCard.setGroups(anotherGroups); + + PrivateCard mergedCard = (PrivateCard) someCard.merge(anotherCard); + + assertTrue(mergedCard.getAddresses().find(anAddress)); + assertTrue(mergedCard.getAddresses().find(anotherAddress)); + assertEquals(2,mergedCard.getAddresses().get().size()); + + assertTrue(mergedCard.getPhones().find(aPhone)); + assertTrue(mergedCard.getPhones().find(anotherPhone)); + assertEquals(2,mergedCard.getPhones().get().size()); + + assertTrue(mergedCard.getMails().find(aMail)); + assertTrue(mergedCard.getMails().find(anotherMail)); + assertEquals(2,mergedCard.getMails().get().size()); + + assertTrue(mergedCard.getGroups().find(aGroup)); + assertTrue(mergedCard.getGroups().find(anotherGroup)); + assertEquals(2,mergedCard.getGroups().get().size()); + + assertEquals(someCard.getIdentification(),mergedCard.getIdentification()); + } + + @Test + void testMerge_SamePrivateCard_NoChange(){ + PrivateCard mergedCard = (PrivateCard) someCard.merge(someCard); + + assertTrue(mergedCard.getAddresses().find(anAddress)); + assertEquals(1,mergedCard.getAddresses().get().size()); + + assertTrue(mergedCard.getPhones().find(aPhone)); + assertEquals(1,mergedCard.getPhones().get().size()); + + assertTrue(mergedCard.getMails().find(aMail)); + assertEquals(1,mergedCard.getMails().get().size()); + + assertTrue(mergedCard.getGroups().find(aGroup)); + assertEquals(1,mergedCard.getGroups().get().size()); + } + + @Test + void testMerge_PrivateCardsWithSharedValues_NoDuplicate(){ + PrivateCard anotherCard = new PrivateCard("000"); + + AddressList anotherAddresses = new AddressList(); + PhoneList anotherPhones = new PhoneList(); + MailList anotherMails = new MailList(); + GroupList anotherGroups = new GroupList(); + PrivateAddress anotherAddress = new PrivateAddress(1, "Another Private Street", new City("France", "Angouleme"), 16000, null); + Phone anotherPhone = new Phone(0642424242, ""); + Mail anotherMail = new Mail("anotherHome@mail.com", null); + Group anotherGroup = new Group("anotherName", ""); + + anotherAddresses.add(anotherAddress); + anotherPhones.add(anotherPhone); + anotherMails.add(anotherMail); + anotherGroups.add(anotherGroup); + + anotherCard.setAddresses(someAddresses); + anotherCard.setPhones(somePhones); + anotherCard.setMails(someMails); + anotherCard.setGroups(someGroups); + anotherCard.setAddresses(anotherAddresses); + anotherCard.setPhones(anotherPhones); + anotherCard.setMails(anotherMails); + anotherCard.setGroups(anotherGroups); + + PrivateCard mergedCard = (PrivateCard) someCard.merge(anotherCard); + + assertTrue(mergedCard.getAddresses().find(anAddress)); + assertTrue(mergedCard.getAddresses().find(anotherAddress)); + assertEquals(2,mergedCard.getAddresses().get().size()); + + assertTrue(mergedCard.getPhones().find(aPhone)); + assertTrue(mergedCard.getPhones().find(anotherPhone)); + assertEquals(2,mergedCard.getPhones().get().size()); + + assertTrue(mergedCard.getMails().find(aMail)); + assertTrue(mergedCard.getMails().find(anotherMail)); + assertEquals(2,mergedCard.getMails().get().size()); + + assertTrue(mergedCard.getGroups().find(aGroup)); + assertTrue(mergedCard.getGroups().find(anotherGroup)); + assertEquals(2,mergedCard.getGroups().get().size()); + } + + @Test + void testMergeCompanyCard_AnyCompanyCard_ExceptionThrown(){ + assertThrows(NullPointerException.class, ()-> someCard.mergeCompanyCard(new CompanyCard(null))); + } + + @Test + void testMergePrivateCard_SomePrivateCard_KeepCurrentAttributes(){ + PrivateCard anotherCard = new PrivateCard("000"); + someCard.setFirstName("John"); + someCard.setLastName("Doe"); + + anotherCard.setFirstName("Tom"); + anotherCard.setLastName("Joe"); + + PrivateCard mergedCard = someCard.mergePrivateCard(anotherCard); + + assertEquals(someCard.getFirstName(),mergedCard.getFirstName()); + assertEquals(someCard.getLastName(),mergedCard.getLastName()); + } +} \ No newline at end of file -- GitLab From 9f63ec7a599f66a66dcb057761d876c9722a5932 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Mon, 23 Mar 2020 17:02:37 +0100 Subject: [PATCH 065/120] Modified Card and related classes to match preconditions --- .../fr/unantes/software/construction/address/Card.java | 9 +++++++-- .../software/construction/address/CardList.java | 9 ++++++--- .../software/construction/address/CompanyCard.java | 9 +++++++-- .../software/construction/address/PrivateCard.java | 10 +++++----- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/address/Card.java b/src/main/java/fr/unantes/software/construction/address/Card.java index 15735096..31d51416 100755 --- a/src/main/java/fr/unantes/software/construction/address/Card.java +++ b/src/main/java/fr/unantes/software/construction/address/Card.java @@ -1,6 +1,7 @@ package fr.unantes.software.construction.address; import fr.unantes.software.construction.Client; +import org.apache.commons.lang3.Validate; /** * @author @@ -57,6 +58,7 @@ public abstract class Card { * @param addresses */ public void setAddresses(AddressList addresses) { + Validate.notNull(addresses); this.addresses = addresses; } @@ -64,6 +66,7 @@ public abstract class Card { * @param phones */ public void setPhones(PhoneList phones) { + Validate.notNull(phones); this.phones = phones; } @@ -71,6 +74,7 @@ public abstract class Card { * @param mails */ public void setMails(MailList mails) { + Validate.notNull(mails); this.mails = mails; } @@ -78,6 +82,7 @@ public abstract class Card { * @param groups */ public void setGroups(GroupList groups) { + Validate.notNull(groups); this.groups = groups; } @@ -90,7 +95,7 @@ public abstract class Card { public abstract CompanyCard mergeCompanyCard(CompanyCard card); - public abstract PrivateCard fusionFichePart(PrivateCard card); + public abstract PrivateCard mergePrivateCard(PrivateCard card); public abstract String toXML(); @@ -99,7 +104,6 @@ public abstract class Card { return (identification.equals(card.getIdentification())); } - /** * @return _nomF nom de la fiche */ @@ -109,6 +113,7 @@ public abstract class Card { public void setIdentification(String str) { + Validate.notNull(str); identification = str; } diff --git a/src/main/java/fr/unantes/software/construction/address/CardList.java b/src/main/java/fr/unantes/software/construction/address/CardList.java index de953fab..ac0015bf 100755 --- a/src/main/java/fr/unantes/software/construction/address/CardList.java +++ b/src/main/java/fr/unantes/software/construction/address/CardList.java @@ -1,5 +1,7 @@ package fr.unantes.software.construction.address; +import org.apache.commons.lang3.Validate; + import java.util.*; public class CardList { @@ -46,19 +48,20 @@ public class CardList { * @param card fiche à add dans la liste */ public void add(Card card){ - if(!contains(card)) cards.add(card); + Validate.notNull(card); + if(!find(card)) cards.add(card); } /** * @param card fiche à supprimer de la liste */ public void delete(Card card){ - if (contains(card)) cards.remove(card); + if (find(card)) cards.remove(card); } /** * @param card c'est la fiche find */ - public boolean contains(Card card){ + public boolean find(Card card){ return cards.contains(card); } diff --git a/src/main/java/fr/unantes/software/construction/address/CompanyCard.java b/src/main/java/fr/unantes/software/construction/address/CompanyCard.java index 2561bd24..1ea77706 100755 --- a/src/main/java/fr/unantes/software/construction/address/CompanyCard.java +++ b/src/main/java/fr/unantes/software/construction/address/CompanyCard.java @@ -1,5 +1,7 @@ package fr.unantes.software.construction.address; +import org.apache.commons.lang3.Validate; + public class CompanyCard extends Card { protected String companyName; @@ -7,6 +9,7 @@ public class CompanyCard extends Card { public CompanyCard(String companyName) { super(companyName); + Validate.notNull(companyName); this.companyName = companyName; } @@ -16,6 +19,7 @@ public class CompanyCard extends Card { } public void setCompanyName(String companyName) { + Validate.notNull(companyName); this.companyName = companyName; } @@ -25,6 +29,7 @@ public class CompanyCard extends Card { card.setIdentification(identification); card.setCompanyName(companyName); + newCard.setCompanyName(companyName); newCard.setAddresses(addresses.merge(card.getAddresses())); newCard.setPhones(phones.merge(card.getPhones())); newCard.setMails(mails.merge(card.getMails())); @@ -40,14 +45,14 @@ public class CompanyCard extends Card { */ public Card merge(Card card) { - Card res = new PrivateCard(identification); + Card res = new CompanyCard(identification); if (identicalCard(card)) res = card.mergeCompanyCard(this); return res; } - public PrivateCard fusionFichePart(PrivateCard card) { + public PrivateCard mergePrivateCard(PrivateCard card) { return null; } diff --git a/src/main/java/fr/unantes/software/construction/address/PrivateCard.java b/src/main/java/fr/unantes/software/construction/address/PrivateCard.java index db960bd5..549c417b 100755 --- a/src/main/java/fr/unantes/software/construction/address/PrivateCard.java +++ b/src/main/java/fr/unantes/software/construction/address/PrivateCard.java @@ -50,7 +50,7 @@ public class PrivateCard extends Card { * @param firstName * prenom de la personne de la fiche */ - public void setPrenom(String firstName) { + public void setFirstName(String firstName) { this.firstName = firstName; } @@ -64,7 +64,7 @@ public class PrivateCard extends Card { public Card merge(Card card) { Card newCard = new PrivateCard(identification); if (identicalCard(card)) - newCard = card.fusionFichePart(this); + newCard = card.mergePrivateCard(this); return newCard; } @@ -72,14 +72,14 @@ public class PrivateCard extends Card { return null; } - public PrivateCard fusionFichePart(PrivateCard card) { + public PrivateCard mergePrivateCard(PrivateCard card) { PrivateCard newCard = new PrivateCard(identification); newCard.setIdentification(identification); newCard.setLastName(lastName); if (firstName == null) - newCard.setPrenom(card.getFirstName()); + newCard.setFirstName(card.getFirstName()); else - newCard.setPrenom(firstName); + newCard.setFirstName(firstName); newCard.setAddresses(addresses.merge(card.getAddresses())); newCard.setPhones(phones.merge(card.getPhones())); newCard.setMails(mails.merge(card.getMails())); -- GitLab From a604f2712243d9d1dd194c32d106b5fe0498ec25 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Mon, 23 Mar 2020 17:04:03 +0100 Subject: [PATCH 066/120] Set temporary constructor as comment until it handle association --- .../unantes/software/construction/address/Address.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/address/Address.java b/src/main/java/fr/unantes/software/construction/address/Address.java index 12c0c7f4..baf32138 100755 --- a/src/main/java/fr/unantes/software/construction/address/Address.java +++ b/src/main/java/fr/unantes/software/construction/address/Address.java @@ -72,17 +72,18 @@ public abstract class Address { } /** - * - * + * + * * @param address une adresse */ - //TODO this is a copy constructor, doesn't it violate the 1-1 associationwith Client ? + /* + //TODO this is a copy constructor, doesn't it violate the 1-1 association with Client ? public Address(Address address) { this.streetNumber = address.getStreetNumber(); this.streetName = address.getStreet(); this.city = address.getCity(); this.zipCode = address.getZipCode(); - } + }*/ /* -- GitLab From 7f91da51b79d3b4a66900ed8681ceb4e78f498d0 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Mon, 23 Mar 2020 17:05:53 +0100 Subject: [PATCH 067/120] Set as comment Address subclass constructor that don't handle association --- .../unantes/software/construction/address/CompanyAddress.java | 4 ++-- .../unantes/software/construction/address/PrivateAddress.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/address/CompanyAddress.java b/src/main/java/fr/unantes/software/construction/address/CompanyAddress.java index cc1617e0..ac5ed5bd 100755 --- a/src/main/java/fr/unantes/software/construction/address/CompanyAddress.java +++ b/src/main/java/fr/unantes/software/construction/address/CompanyAddress.java @@ -39,12 +39,12 @@ public class CompanyAddress extends Address { /** * * @param address une adresse - */ + *//* public CompanyAddress(CompanyAddress address) { super(address); locality = address.getLocality(); zone = address.getZone(); - } + }*/ /** * @return _lieu_dit le nom du lieu dit diff --git a/src/main/java/fr/unantes/software/construction/address/PrivateAddress.java b/src/main/java/fr/unantes/software/construction/address/PrivateAddress.java index bbab3e33..1afa4088 100755 --- a/src/main/java/fr/unantes/software/construction/address/PrivateAddress.java +++ b/src/main/java/fr/unantes/software/construction/address/PrivateAddress.java @@ -30,11 +30,11 @@ public class PrivateAddress extends Address { /** * * @param address une adresse - */ + *//* public PrivateAddress(PrivateAddress address) { super(address); locality = address.getLocality(); - } + }*/ /** Les accesseurs */ -- GitLab From e2ce18d9895da7c5bab3227a73125d0ae5902399 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Mon, 23 Mar 2020 17:06:39 +0100 Subject: [PATCH 068/120] Modified classes impacted by Client changes --- .../construction/address/AddressBookTest.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/test/fr/unantes/software/construction/address/AddressBookTest.java b/src/main/test/fr/unantes/software/construction/address/AddressBookTest.java index ae25f4a5..3f84064f 100644 --- a/src/main/test/fr/unantes/software/construction/address/AddressBookTest.java +++ b/src/main/test/fr/unantes/software/construction/address/AddressBookTest.java @@ -22,7 +22,7 @@ class AddressBookTest { void testSetCards_ValidCardList_Succeed(){ assertDoesNotThrow(()->addressBook.setCards(someList)); - assertEquals(someList.contains(someCard), addressBook.getCards().contains(someCard)); + assertEquals(someList.find(someCard), addressBook.getCards().find(someCard)); } @Test @@ -51,19 +51,18 @@ class AddressBookTest { AddressBook mergedLists = addressBook.merge(anotherBook,"new name"); assertNotNull(mergedLists); - assertTrue(mergedLists.getCards().contains(someCard)); - assertTrue(mergedLists.getCards().contains(anotherCard)); + assertTrue(mergedLists.getCards().find(someCard)); + assertTrue(mergedLists.getCards().find(anotherCard)); assertEquals(2, mergedLists.getCards().get().size()); } @Test public void testMerge_SameLists_NoChange(){ addressBook.setCards(someList); - AddressBook mergedLists = addressBook.merge(addressBook,""); assertNotNull(mergedLists); - assertTrue(mergedLists.getCards().contains(someCard)); + assertTrue(mergedLists.getCards().find(someCard)); assertEquals(addressBook.getCards().get().size(), mergedLists.getCards().get().size()); } @@ -94,7 +93,7 @@ class AddressBookTest { AddressBook mergedLists = addressBook.merge(anotherBook,""); assertNotNull(mergedLists); - assertTrue(mergedLists.getCards().contains(someCard)); + assertTrue(mergedLists.getCards().find(someCard)); assertEquals(1, mergedLists.getCards().get().size()); } -- GitLab From 55daceeac31d706a1808b2cecdd86cc9958130f3 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Mon, 23 Mar 2020 18:47:54 +0100 Subject: [PATCH 069/120] Fixed ClientTest to recognize modified bidirectional association --- .../test/fr/unantes/software/construction/ClientTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/test/fr/unantes/software/construction/ClientTest.java b/src/main/test/fr/unantes/software/construction/ClientTest.java index 215d9550..488a7502 100644 --- a/src/main/test/fr/unantes/software/construction/ClientTest.java +++ b/src/main/test/fr/unantes/software/construction/ClientTest.java @@ -9,6 +9,7 @@ import static org.junit.jupiter.api.Assertions.*; class ClientTest { Client client; + @BeforeEach void setUp() throws InvalidClassException { client = new Client("Tom","private"); @@ -23,7 +24,7 @@ class ClientTest { }; for(Account each : accounts) { - assertEquals(client, each.getOwner().get()); + assertTrue(each.getOwner().contains(client)); } for(Account each : accounts) { @@ -31,8 +32,7 @@ class ClientTest { } for(Account each : accounts) { - assertFalse(client.getAccounts().contains(each)); - assertEquals(client2, each.getOwner().get()); + assertTrue(client2.getAccounts().contains(each)); } } @@ -49,7 +49,7 @@ class ClientTest { for(Account each : accounts) { assertTrue(client.getAccounts().contains(each)); - assertEquals(client, each.getOwner().get()); + assertTrue(each.getOwner().contains(client)); } } } \ No newline at end of file -- GitLab From c56e418f3d424ff2387460f1ee8bc1c97b3703c5 Mon Sep 17 00:00:00 2001 From: Gries Robin Date: Mon, 23 Mar 2020 19:17:08 +0100 Subject: [PATCH 070/120] Update BankTest to correctly call Account Iterators --- .../software/construction/BankTest.java | 22 ++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/main/test/fr/unantes/software/construction/BankTest.java b/src/main/test/fr/unantes/software/construction/BankTest.java index 8be16c45..f7bfdeb8 100644 --- a/src/main/test/fr/unantes/software/construction/BankTest.java +++ b/src/main/test/fr/unantes/software/construction/BankTest.java @@ -35,26 +35,18 @@ public class BankTest { String name = "Martin"; int a = bank.addAccount(name, 15026.33f, 0.0f, "private" ); - assertTrue(bank.getClient(name).getAccountsIterator().hasNext()); - assertEquals(15026.33f, bank.clientAccountsIterator(name).next().getBalance()); - + assertNotNull(bank.getAccountsOfClient(name)); + assertTrue(bank.getClient(name).getAccounts().get().iterator().hasNext()); + assertEquals(15026.33f, bank.getAccountsOfClient(name).get().iterator().next().getBalance()); } @Test void test_addAccount_WhenAlreadyExist() throws InvalidClassException{ - int a = bank.addAccount("Martin", 15026.33f, 0.0f, "private" ); - int b = bank.addAccount("Martin", 42.00f, 0.0f, "private" ); - Iterator it = bank.clientAccountsIterator("Martin"); - int counter = 0; - - assertTrue(bank.clientAccountsIterator("Martin").hasNext()); - - while(it.hasNext()) { - it.next(); - counter++; - } - assertEquals(2, counter); + String name = "Martin"; + int a = bank.addAccount(name, 15026.33f, 0.0f, "private" ); + int b = bank.addAccount(name, 42.00f, 0.0f, "private" ); + assertEquals(2, bank.getAccountsOfClient(name).get().size()); assertNotEquals(bank.getAccount(a), bank.getAccount(b)); } -- GitLab From 3d9d6faa0d73b70b0690f4ed6a2c4fad04ab1773 Mon Sep 17 00:00:00 2001 From: Gries Robin Date: Mon, 23 Mar 2020 19:19:00 +0100 Subject: [PATCH 071/120] remove use of toArray() in Client and Bank, Bank.accountNumber nowupdate correctly when an Account is added --- .../unantes/software/construction/Bank.java | 31 ++++++++++--------- .../unantes/software/construction/Client.java | 13 ++------ 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/Bank.java b/src/main/java/fr/unantes/software/construction/Bank.java index 1c3856ad..8eaa390d 100755 --- a/src/main/java/fr/unantes/software/construction/Bank.java +++ b/src/main/java/fr/unantes/software/construction/Bank.java @@ -7,7 +7,6 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import fr.unantes.software.construction.references.ManyToOneReference; import fr.unantes.software.construction.references.MultipleReference; import org.apache.commons.lang3.Validate; @@ -145,24 +144,27 @@ public class Bank { * If the client exists the account is created, added to the bank's * and the client's list of accounts */ - public int addAccount(String name, float amount, float overdraft, String type) { + public int addAccount(String name, float amount, float overdraft, String type) { Validate.notNull(name); Validate.notNull(type); - Client p = getClient(name); - //if a client named name already exists in the bank's set of clients - if (p!=null){ - Account a = null; - try { - a = new Account(p, amount, overdraft, type); - } catch (InvalidClassException e) { - e.printStackTrace(); + Client pending = getClient(name); + + try { + if (pending == null) { + pending = new Client(name, type); + this.addClients(pending); } - p.addAccounts(a); - this.addAccounts(a); + Account acc = new Account(pending, amount, overdraft, type); + this.addAccounts(acc); + pending.addAccounts(acc); + } catch (InvalidClassException e) { + e.printStackTrace(); } + return accountNumbers; } + /** * Closes the account number accountNumber. * If the account exists, it is removed form the bank's list of accounts and from the owner's list of accounts. @@ -187,7 +189,7 @@ public class Bank { public Client getClient(String name) { Iterator it = this.clientsIterator(); while (it.hasNext()){ - Client p = (Client)it.next(); + Client p = it.next(); if(p.getName().equals(name)){ return p; } @@ -249,7 +251,7 @@ public class Bank { public MultipleReference getAccountsOfClient(String name) { Client client = getClient(name); Validate.notNull(client); - return client.accountsToArray(); + return client.getAccounts(); } /** @@ -282,6 +284,7 @@ public class Bank { */ public boolean addAccounts(Account element) { Validate.notNull(element); + accountNumbers++; return accounts.add(element); } diff --git a/src/main/java/fr/unantes/software/construction/Client.java b/src/main/java/fr/unantes/software/construction/Client.java index 865fbc35..dbe52747 100644 --- a/src/main/java/fr/unantes/software/construction/Client.java +++ b/src/main/java/fr/unantes/software/construction/Client.java @@ -52,7 +52,7 @@ public class Client { } public Address getAddress(){ - return (Address) refAddress.get(); + return refAddress.get(); } public SingleReference getAddressRef(){ @@ -86,7 +86,7 @@ public class Client { * * @uml.property name="accounts" */ - public MultipleReference getAccounts() { + public MultipleReference getAccounts() { return accounts; } @@ -147,15 +147,6 @@ public class Client { return accounts.size(); } - /** - * - * @uml.property name="accounts" - */ - public MultipleReference accountsToArray() { - return accounts; - } - - public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; -- GitLab From 7e1d1f4f1ceb830c3a69be44e6bfb1b387196698 Mon Sep 17 00:00:00 2001 From: Gries Robin Date: Mon, 23 Mar 2020 21:33:24 +0100 Subject: [PATCH 072/120] Change attribute type to private --- .../java/fr/unantes/software/construction/address/City.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/address/City.java b/src/main/java/fr/unantes/software/construction/address/City.java index 2864e325..0a29e182 100644 --- a/src/main/java/fr/unantes/software/construction/address/City.java +++ b/src/main/java/fr/unantes/software/construction/address/City.java @@ -6,8 +6,8 @@ import org.apache.commons.lang3.Validate; * A city */ public class City { - public String country; - public String name; + private String country; + private String name; public City(String country, String name) { Validate.notNull(country); @@ -42,6 +42,7 @@ public class City { getName().equals(city.getName()); } + public int hashCode() { return getCountry().hashCode() + getName().hashCode(); } -- GitLab From 86bad659dc4afa4cead67822d56a5dc74c2fc9ef Mon Sep 17 00:00:00 2001 From: Gries Robin Date: Tue, 24 Mar 2020 20:19:30 +0100 Subject: [PATCH 073/120] Add a better abstraction of CardList and non-regression test --- .../address/nonRegression/ListOf.java | 104 +++++++++++ .../address/nonRegression/ListOfCard.java | 172 ++++++++++++++++++ 2 files changed, 276 insertions(+) create mode 100644 src/main/test/fr/unantes/software/construction/address/nonRegression/ListOf.java create mode 100644 src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfCard.java diff --git a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOf.java b/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOf.java new file mode 100644 index 00000000..7056db9e --- /dev/null +++ b/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOf.java @@ -0,0 +1,104 @@ +package fr.unantes.software.construction.address.nonRegression; + +import java.util.ArrayList; +import java.util.List; +import org.apache.commons.lang3.Validate; + +/** + * Issues #12 + * all classes called FooList have the same methods and could be replace + * with a simple List<Foo> + * + * Tests have been made for the original classes FooList and thus can be used for + * non-regression testing + * + * This class is used as an adapter to translate the methods of the java ArrayList to FooList, + * so that Tests can then be run using a List<Foo> and validate that the behavior + * stay the same. + */ +public class ListOf { + private List targetList; + + /** + * Empty constructor + */ + public ListOf(){ + targetList = new ArrayList(); + } + + /** + * Copy constructor + * @param otherList List to copy + */ + public ListOf(ListOf otherList){ + targetList = otherList.targetList; + } + + /** + * Note that the original FooList used a Vector, obviously we are replacing it with a List + * as it is better abstraction + * @return a List of element + */ + public List get() { + return targetList; + } + + public void set(List newTargetList){ + targetList = newTargetList; + } + public void add(T elt){ + //add() methods in FooList all check that elt doesn't exist yet, + // so they are actually Set instead of List + if(this.targetList.contains(elt)){ return; } + targetList.add(elt); + } + public void delete(T elt){ + targetList.remove(elt); + } + public boolean find(T elt){ + return targetList.contains(elt); + } + + public int size(){ + return targetList.size(); + } + + /** + * Iterate on otherlist to add each element one by one to this ListOf + * @param otherList a list of elements to add to this ListOf + * @return a new ListOf containing the elements of this ListOf element and the elements of otherList + */ + public ListOf merge(ListOf otherList){ + Validate.notNull(otherList); + + ListOf newList = new ListOf(this); + + //It's slow , but speed isn't important for this test + for(T t : otherList.get()) { + if( !newList.find(t) ) { + newList.add(t); + } + } + + return newList; + } + + /** + * Delegate the merge to the methods of java.util.List, but it may have duplicates + * @param otherList a list of elements to add to this ListOf + * @return a new ListOf containing the elements of this ListOf element and the elements of otherList + */ + public ListOf delegateMerge( ListOf otherList){ + Validate.notNull(otherList); + + ListOf newList = new ListOf(this); + newList.get().addAll(otherList.get()); + + return newList; + } + + //TODO verifier / tester si les FooList force effectivemment les merge() à rendre une liste + // sans doublons + // si oui , peut etre utiliser un Set / HashSet + // +} diff --git a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfCard.java b/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfCard.java new file mode 100644 index 00000000..4f496410 --- /dev/null +++ b/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfCard.java @@ -0,0 +1,172 @@ +package fr.unantes.software.construction.address.nonRegression; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import fr.unantes.software.construction.address.Card; +import fr.unantes.software.construction.address.CompanyCard; +import fr.unantes.software.construction.address.PrivateCard; +import java.util.ArrayList; +import java.util.List; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class ListOfCard { + ListOf cardList; + Card someCard; + @BeforeEach + void setUp() { + cardList = new ListOf<>(); + someCard = new PrivateCard("John","Doe"); + } + + @Test + void testSet_ListOfCards_addCardsToCurrentList(){ + List anotherList = new ArrayList<>(); + Card[] cards = { someCard, + new PrivateCard("Tom","Joe"), + new CompanyCard("JohnDoe Corp.") + }; + + for(Card each : cards){ + anotherList.add(each); + } + + cardList.set(anotherList); + + for(Card each : cards){ + assertTrue(cardList.find(each)); + } + } + + @Test + void testSet_NullValue_ExceptionThrown(){ + assertThrows(Exception.class, ()-> cardList.set(null)); + } + + + @Test + public void testAdd_newValue_Succeed(){ + assertDoesNotThrow(() -> cardList.add(someCard)); + assertTrue(cardList.find(someCard)); + } + + @Test + public void testAdd_alreadyContainedValue_noDuplicate(){ + cardList.add(someCard); + int currentSize = cardList.get().size(); + + cardList.add(someCard); + assertEquals(currentSize, cardList.get().size()); + } + + @Test + public void testAdd_NullValue_ExceptionThrown(){ + int currentSize = cardList.get().size(); + assertThrows(Exception.class, () -> cardList.add(null)); + assertEquals(currentSize, cardList.get().size()); + } + + @Test + public void testDelete_ContainedValue_Succeed(){ + cardList.add(someCard); + cardList.delete(someCard); + + assertFalse(cardList.find(someCard)); + } + + @Test + public void testDelete_ValueContainedByAnotherGroup_NoEffect(){ + ListOf anotherList = new ListOf<>(); + anotherList.add(someCard); + + int currentSize = cardList.get().size(); + assertFalse(cardList.find(someCard)); + + cardList.delete(someCard); + assertTrue(anotherList.find(someCard)); + assertEquals(currentSize, cardList.get().size()); + } + + @Test + public void testFind_ContainedValue_ReturnTrue(){ + cardList.add(someCard); + assertTrue(cardList.find(someCard)); + } + + @Test + public void testFind_NotContainedValue_ReturnFalse(){ + cardList.add(new PrivateCard("Tom","Joe")); + assertFalse(cardList.find(someCard)); + } + + @Test + public void testMerge_TwoDifferentLists_ReturnListWithBothValue(){ + cardList.add(someCard); + + Card anotherCard = new PrivateCard("Tom", "Joe"); + ListOf anotherList = new ListOf<>(); + anotherList.add(anotherCard); + + ListOf mergedLists = cardList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someCard)); + assertTrue(mergedLists.find(anotherCard)); + assertEquals(2, mergedLists.get().size()); + } + + @Test + public void testMerge_SameLists_NoChange(){ + cardList.add(someCard); + + ListOf mergedLists = cardList.merge(cardList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someCard)); + assertEquals(cardList.get().size(), mergedLists.get().size()); + } + + @Test + public void testMerge_ListsWithSharedValues_NoDuplicate(){ + Card anotherCard = new PrivateCard("Tom", "Joe"); + + cardList.add(someCard); + cardList.add(anotherCard); + + ListOf anotherList = new ListOf<>(); + anotherList.add(anotherCard); + + ListOf mergedLists = cardList.merge(anotherList); + + assertNotNull(mergedLists); + assertEquals(2, mergedLists.get().size()); + + + } + @Test + public void testMerge_EmptyCardList_SameCardList(){ + ListOf anotherList = new ListOf<>(); + + cardList.add(someCard); + + ListOf mergedLists = cardList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someCard)); + assertEquals(1, mergedLists.get().size()); + } + + @Test + public void testMerge_NullCardList_ExceptionThrown(){ + cardList.add(someCard); + + assertThrows(NullPointerException.class, ()-> cardList.merge(null)); + } + + +} \ No newline at end of file -- GitLab From 225feb48b454d1ba0ad243f96f08e964188b8dab Mon Sep 17 00:00:00 2001 From: Gries Robin Date: Wed, 25 Mar 2020 11:35:31 +0100 Subject: [PATCH 074/120] Added non-regression tests for ListOf<> of Address, Card, Group, Mail and Phone --- .../nonRegression/ListOfAddressTest.java | 176 ++++++++++++++ .../{ListOfCard.java => ListOfCardTest.java} | 2 +- .../nonRegression/ListOfGroupTest.java | 171 ++++++++++++++ .../address/nonRegression/ListOfMailTest.java | 216 ++++++++++++++++++ .../nonRegression/ListOfPhoneTest.java | 183 +++++++++++++++ 5 files changed, 747 insertions(+), 1 deletion(-) create mode 100644 src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfAddressTest.java rename src/main/test/fr/unantes/software/construction/address/nonRegression/{ListOfCard.java => ListOfCardTest.java} (99%) create mode 100644 src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfGroupTest.java create mode 100644 src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfMailTest.java create mode 100644 src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfPhoneTest.java diff --git a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfAddressTest.java b/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfAddressTest.java new file mode 100644 index 00000000..9353da88 --- /dev/null +++ b/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfAddressTest.java @@ -0,0 +1,176 @@ +package fr.unantes.software.construction.address.nonRegression; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import fr.unantes.software.construction.address.Address; +import fr.unantes.software.construction.address.City; +import fr.unantes.software.construction.address.CompanyAddress; +import fr.unantes.software.construction.address.PrivateAddress; +import java.util.ArrayList; +import java.util.List; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class ListOfAddressTest { + + ListOf
addressList; + Address someAddress; + + @BeforeEach + void setUp() { + addressList = new ListOf<>(); + someAddress = new PrivateAddress(1,"Some Private Street", new City("Groenland","Qeqertarsuaq"),0,null); + } + + @Test + void testSet_ListOfGroups_addGroupsToCurrentList(){ + List
anotherList = new ArrayList<>(); + Address[] addresses = { someAddress, + new PrivateAddress(1,"Another Private Street", new City("Norvege","Honningsvag"),0,null), + new CompanyAddress(1,"A Company Street", new City("Australie","Pine Creek"),0,null,null) + }; + + for(Address each : addresses){ + anotherList.add(each); + } + + addressList.set(anotherList); + + for(Address each : addresses){ + assertTrue(addressList.find(each)); + } + } + + @Test + void testSet_NullValue_ExceptionThrown(){ + assertThrows(Exception.class, ()->addressList.set(null)); + } + + + @Test + public void testAdd_newValue_Succeed(){ + assertDoesNotThrow(() -> addressList.add(someAddress)); + assertTrue(addressList.find(someAddress)); + } + + @Test + public void testAdd_alreadyContainedValue_noDuplicate(){ + addressList.add(someAddress); + int currentSize = addressList.get().size(); + + addressList.add(someAddress); + assertEquals(currentSize,addressList.get().size()); + } + + @Test + public void testAdd_NullValue_ExceptionThrown(){ + int currentSize = addressList.get().size(); + assertThrows(Exception.class, () -> addressList.add(null)); + assertEquals(currentSize,addressList.get().size()); + } + + @Test + public void testDelete_ContainedValue_Succeed(){ + addressList.add(someAddress); + addressList.delete(someAddress); + + assertFalse(addressList.find(someAddress)); + } + + @Test + public void testDelete_ValueContainedByAnotherGroup_NoEffect(){ + ListOf
anotherList = new ListOf<>(); + anotherList.add(someAddress); + + int currentSize = addressList.get().size(); + assertFalse(addressList.find(someAddress)); + + addressList.delete(someAddress); + assertTrue(anotherList.find(someAddress)); + assertEquals(currentSize, addressList.get().size()); + } + + @Test + public void testFind_ContainedValue_ReturnTrue(){ + addressList.add(someAddress); + assertTrue(addressList.find(someAddress)); + } + + @Test + public void testFind_NotContainedValue_ReturnFalse(){ + addressList.add(new PrivateAddress(1,"Another Private Street", new City("Norvege","Honningsvag"),0,null)); + assertFalse(addressList.find(someAddress)); + } + + @Test + public void testMerge_TwoDifferentLists_ReturnListWithBothValue(){ + addressList.add(someAddress); + + Address anotherAddress = new PrivateAddress(1,"Another Private Street", new City("Norvege","Honningsvag"),0,null); + ListOf
anotherList = new ListOf<>(); + anotherList.add(anotherAddress); + + ListOf
mergedLists = addressList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someAddress)); + assertTrue(mergedLists.find(anotherAddress)); + assertEquals(2, mergedLists.get().size()); + } + + @Test + public void testMerge_SameLists_NoChange(){ + addressList.add(someAddress); + + ListOf
mergedLists = addressList.merge(addressList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someAddress)); + assertEquals(addressList.get().size(), mergedLists.get().size()); + } + + @Test + public void testMerge_ListsWithSharedValues_NoDuplicate(){ + Address anotherAddress = new PrivateAddress(1,"Another Private Street", new City("Norvege","Honningsvag"),0,null); + + addressList.add(someAddress); + addressList.add(anotherAddress); + + ListOf
anotherList = new ListOf<>(); + anotherList.add(anotherAddress); + + ListOf
mergedLists = addressList.merge(anotherList); + + assertNotNull(mergedLists); + assertEquals(2, mergedLists.get().size()); + + + } + @Test + public void testMerge_EmptyGroupList_SameGroupList(){ + ListOf
anotherList = new ListOf<>(); + + addressList.add(someAddress); + + ListOf
mergedLists = addressList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someAddress)); + assertEquals(1, mergedLists.get().size()); + } + + @Test + public void testMerge_NullGroupList_ExceptionThrown(){ + addressList.add(someAddress); + + assertThrows(NullPointerException.class, ()->addressList.merge(null)); + } + + + +} \ No newline at end of file diff --git a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfCard.java b/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfCardTest.java similarity index 99% rename from src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfCard.java rename to src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfCardTest.java index 4f496410..f0a234c7 100644 --- a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfCard.java +++ b/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfCardTest.java @@ -15,7 +15,7 @@ import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -class ListOfCard { +class ListOfCardTest { ListOf cardList; Card someCard; @BeforeEach diff --git a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfGroupTest.java b/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfGroupTest.java new file mode 100644 index 00000000..022ff480 --- /dev/null +++ b/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfGroupTest.java @@ -0,0 +1,171 @@ +package fr.unantes.software.construction.address.nonRegression; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import fr.unantes.software.construction.address.Group; +import java.util.Vector; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class ListOfGroupTest { + + ListOf groupList; + Group someGroup; + + @BeforeEach + void setUp() { + groupList = new ListOf(); + someGroup = new Group("a Group",""); + } + + @Test + void testSet_ListOfGroups_addGroupsToCurrentList(){ + Vector anotherList = new Vector(); + Group[] groups = { someGroup, + new Group("Group1",null), + new Group("Group2","Comment2"), + }; + + for(Group each : groups){ + anotherList.add(each); + } + + groupList.set(anotherList); + + for(Group each : groups){ + assertTrue(groupList.find(each)); + } + } + + @Test + void testSet_NullValue_ExceptionThrown(){ + assertThrows(Exception.class, ()->groupList.set(null)); + } + + + @Test + public void testAdd_newValue_Succeed(){ + assertDoesNotThrow(() -> groupList.add(someGroup)); + assertTrue(groupList.find(someGroup)); + } + + @Test + public void testAdd_alreadyContainedValue_noDuplicate(){ + groupList.add(someGroup); + int currentSize = groupList.size(); + + groupList.add(someGroup); + assertEquals(currentSize,groupList.size()); + } + + @Test + public void testAdd_NullValue_ExceptionThrown(){ + int currentSize = groupList.size(); + assertThrows(Exception.class, () -> groupList.add(null)); + assertEquals(currentSize,groupList.size()); + } + + @Test + public void testDelete_ContainedValue_Succeed(){ + groupList.add(someGroup); + groupList.delete(someGroup); + + assertFalse(groupList.find(someGroup)); + } + + @Test + public void testDelete_ValueContainedByAnotherGroup_NoEffect(){ + ListOf anotherList = new ListOf(); + anotherList.add(someGroup); + + int currentSize = groupList.size(); + assertFalse(groupList.find(someGroup)); + + groupList.delete(someGroup); + assertTrue(anotherList.find(someGroup)); + assertEquals(currentSize, groupList.size()); + } + + @Test + public void testFind_ContainedValue_ReturnTrue(){ + groupList.add(someGroup); + assertTrue(groupList.find(someGroup)); + } + + @Test + public void testFind_NotContainedValue_ReturnFalse(){ + groupList.add(new Group("anotherGroup", "")); + assertFalse(groupList.find(someGroup)); + } + + @Test + public void testMerge_TwoDifferentLists_ReturnListWithBothValue(){ + groupList.add(someGroup); + + Group anotherGroup = new Group("secondGroup", ""); + ListOf anotherList = new ListOf(); + anotherList.add(anotherGroup); + + ListOf mergedLists = groupList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someGroup)); + assertTrue(mergedLists.find(anotherGroup)); + assertEquals(2, mergedLists.size()); + } + + @Test + public void testMerge_SameLists_NoChange(){ + groupList.add(someGroup); + + ListOf mergedLists = groupList.merge(groupList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someGroup)); + assertEquals(groupList.size(), mergedLists.size()); + } + + @Test + public void testMerge_ListsWithSharedValues_NoDuplicate(){ + Group anotherGroup = new Group("secondGroup", ""); + + groupList.add(someGroup); + groupList.add(anotherGroup); + + ListOf anotherList = new ListOf(); + anotherList.add(anotherGroup); + + ListOf mergedLists = groupList.merge(anotherList); + + assertNotNull(mergedLists); + assertEquals(2, mergedLists.size()); + + + } + @Test + public void testMerge_EmptyGroupList_SameGroupList(){ + ListOf anotherList = new ListOf(); + + groupList.add(someGroup); + + ListOf mergedLists = groupList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someGroup)); + assertEquals(1, mergedLists.size()); + } + + @Test + public void testMerge_NullGroupList_ExceptionThrown(){ + groupList.add(someGroup); + + assertThrows(NullPointerException.class, ()->groupList.merge(null)); + } + + +} \ No newline at end of file diff --git a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfMailTest.java b/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfMailTest.java new file mode 100644 index 00000000..97568cfc --- /dev/null +++ b/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfMailTest.java @@ -0,0 +1,216 @@ +package fr.unantes.software.construction.address.nonRegression; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import fr.unantes.software.construction.address.Mail; +import java.util.Vector; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class ListOfMailTest { + + ListOf mailList; + Mail someMail; + + @BeforeEach + void setUp() { + mailList = new ListOf(); + someMail = new Mail("someHome@mail.com","someWork@mail.com"); + } + + @Test + void testSet_ListOfMails_addMailsToCurrentList(){ + Vector anotherList = new Vector(); + Mail[] mails = { new Mail(null,null), + new Mail("home1@mail.com",null), + new Mail(null, "work1@mail.co.jp"), + new Mail("home2@mail.fr","work2@mail.fr") + }; + + for(Mail each : mails){ + anotherList.add(each); + } + + mailList.set(anotherList); + + for(Mail each : mails){ + assertTrue(mailList.find(each)); + } + } + + @Test + void testSet_NullValue_ExceptionThrown(){ + assertThrows(Exception.class, ()->mailList.set(null)); + } + + @Test + void testAdd_NewMail_addMailToList(){ + mailList.add(someMail); + + assertTrue(mailList.find(someMail)); + } + + @Test + void testAdd_AlreadyExistingHomeMail_Fusion(){ + Mail oneMail = new Mail("someHome@mail.com",null); + Mail anotherMail = new Mail("someHome@mail.com","anotherWork@mail.com"); + + assertEquals(oneMail.getHome(),anotherMail.getHome()); + + mailList.add(oneMail); + mailList.add(anotherMail); + + assertTrue(mailList.find(oneMail)); + assertEquals("anotherWork@mail.com", oneMail.getWork()); + assertEquals("someHome@mail.com",oneMail.getHome()); + assertEquals(1,mailList.size()); + } + + @Test + void testAdd_AlreadyExistingWorkMail_NoFusion(){ + Mail oneMail = new Mail(null,"someWork@mail.com"); + Mail anotherMail = new Mail("anotherHome@mail.com","someWork@mail.com"); + + assertEquals(oneMail.getWork(),anotherMail.getWork()); + + mailList.add(oneMail); + mailList.add(anotherMail); + + assertTrue(mailList.find(oneMail)); + assertEquals("someWork@mail.com", oneMail.getWork()); + assertNotEquals("anotherHome@mail.com",oneMail.getHome()); + assertEquals(2,mailList.size()); + } + + @Test + void testAdd_Null_ExceptionThrown(){ + assertThrows(NullPointerException.class, () -> mailList.add(null)); + } + + @Test + void testDelete_ExistingMail_Succeed(){ + mailList.add(someMail); + + mailList.delete(someMail); + assertFalse(mailList.find(someMail)); + assertEquals(0,mailList.size()); + } + + @Test + void testDelete_NotContainedMail_NoEffect(){ + ListOf anotherList = new ListOf(); + Mail anotherMail = new Mail(null,null); + + mailList.add(someMail); + anotherList.add(anotherMail); + + mailList.delete(anotherMail); + + assertTrue(mailList.find(someMail)); + assertFalse(mailList.find(anotherMail)); + + assertTrue(anotherList.find(anotherMail)); + assertEquals(1,anotherList.size()); + } + + @Test + void testDelete_NullValue_ExceptionThrown(){ + assertThrows(NullPointerException.class, () -> mailList.delete(null)); + } + + @Test + void testFind_NoMailInCommon_ReturnFalse(){ + Mail anotherMail = new Mail("anotherHome@mail.com","anotherWork@mail.com"); + + mailList.add(someMail); + assertFalse(mailList.find(anotherMail)); + } + + @Test + void testFind_HomeMailInCommon_ReturnTrue(){ + Mail anotherMail = new Mail("someHome@mail.com","anotherWork@mail.com"); + + mailList.add(someMail); + assertTrue(mailList.find(anotherMail)); + } + + @Test + void testFind_WorkMailInCommon_ReturnFalse(){ + Mail anotherMail = new Mail("anotherHome@mail.com","someWork@mail.com"); + + mailList.add(someMail); + assertFalse(mailList.find(anotherMail)); + } + + @Test + public void testMerge_TwoDifferentLists_ReturnListWithBothValue(){ + mailList.add(someMail); + + Mail anotherMail = new Mail("anotherHome@mail.com", "anotherWork@mail.com"); + ListOf anotherList = new ListOf(); + anotherList.add(anotherMail); + + ListOf mergedLists = mailList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someMail)); + assertTrue(mergedLists.find(anotherMail)); + assertEquals(2, mergedLists.size()); + } + + @Test + public void testMerge_SameLists_NoChange(){ + mailList.add(someMail); + + ListOf mergedLists = mailList.merge(mailList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someMail)); + assertEquals(mailList.size(), mergedLists.size()); + } + + @Test + public void testMerge_ListsWithSharedValues_NoDuplicate(){ + Mail anotherMail = new Mail("anotherHome@mail.com", "anotherWork@mail.com"); + + + mailList.add(someMail); + mailList.add(anotherMail); + + ListOf anotherList = new ListOf(); + anotherList.add(anotherMail); + + ListOf mergedLists = mailList.merge(anotherList); + + assertNotNull(mergedLists); + assertEquals(2, mergedLists.size()); + + + } + @Test + public void testMerge_EmptyMailList_SameGroupList(){ + ListOf anotherList = new ListOf(); + + mailList.add(someMail); + + ListOf mergedLists = mailList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someMail)); + assertEquals(1, mergedLists.size()); + } + + @Test + public void testMerge_NullGroupList_ExceptionThrown(){ + mailList.add(someMail); + + assertThrows(NullPointerException.class, ()->mailList.merge(null)); + } + + +} \ No newline at end of file diff --git a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfPhoneTest.java b/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfPhoneTest.java new file mode 100644 index 00000000..1aafe15b --- /dev/null +++ b/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfPhoneTest.java @@ -0,0 +1,183 @@ +package fr.unantes.software.construction.address.nonRegression; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import fr.unantes.software.construction.address.Phone; +import java.util.Vector; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class ListOfPhoneTest { + + ListOf phoneList = new ListOf<>(); + Phone somePhone; + + @BeforeEach + void setUp() { + somePhone = new Phone(0600000000,"some comment"); + } + + @Test + void testSet_ListOfPhones_addPhonesToCurrentList(){ + Vector anotherList = new Vector<>(); + Phone[] phones = { somePhone, + new Phone(0600000001,null), + new Phone(0600000010,"another comment") + }; + + for(Phone each : phones){ + anotherList.add(each); + } + + phoneList.set(anotherList); + + for(Phone each : phones){ + assertTrue(phoneList.find(each)); + } + } + + @Test + void testSet_NullValue_ExceptionThrown(){ + assertThrows(Exception.class, ()->phoneList.set(null)); + } + + @Test + void testAdd_NewPhone_addPhoneToList(){ + phoneList.add(somePhone); + + assertTrue(phoneList.find(somePhone)); + } + + @Test + void testAdd_AlreadyExistingPhone_Fusion(){ + Phone onePhone = new Phone(somePhone.getPhoneNumber(), null); + Phone anotherPhone = new Phone(somePhone.getPhoneNumber(), "a different comment"); + + phoneList.add(onePhone); + phoneList.add(anotherPhone); + + assertTrue(phoneList.find(onePhone)); + assertEquals(1,phoneList.get().size()); + } + + @Test + void testAdd_Null_ExceptionThrown(){ + assertThrows(NullPointerException.class, () -> phoneList.add(null)); + } + + @Test + void testDelete_ExistingMail_Succeed(){ + phoneList.add(somePhone); + + phoneList.delete(somePhone); + assertFalse(phoneList.find(somePhone)); + assertEquals(0,phoneList.get().size()); + } + + @Test + void testDelete_NotContainedMail_NoEffect(){ + ListOf anotherList = new ListOf(); + Phone anotherPhone = new Phone(0606060606,"another comment"); + + phoneList.add(somePhone); + anotherList.add(anotherPhone); + + phoneList.delete(anotherPhone); + + assertTrue(phoneList.find(somePhone)); + assertFalse(phoneList.find(anotherPhone)); + + assertTrue(anotherList.find(anotherPhone)); + assertEquals(1,anotherList.get().size()); + } + + @Test + void testDelete_NullValue_ExceptionThrown(){ + assertThrows(NullPointerException.class, () -> phoneList.delete(null)); + } + + @Test + void testFind_NoPhoneInCommon_ReturnFalse(){ + Phone anotherPhone = new Phone(0606060606,"another comment"); + + phoneList.add(somePhone); + assertFalse(phoneList.find(anotherPhone)); + } + + @Test + void testFind_PhoneNumberInCommon_ReturnTrue(){ + Phone anotherPhone = new Phone(somePhone.getPhoneNumber(),"another comment"); + + phoneList.add(somePhone); + assertTrue(phoneList.find(anotherPhone)); + } + + + @Test + public void testMerge_TwoDifferentLists_ReturnListWithBothValue(){ + phoneList.add(somePhone); + + ListOf anotherList = new ListOf(); + Phone anotherPhone = new Phone(0606060606,"another comment"); + anotherList.add(anotherPhone); + + ListOf mergedLists = phoneList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(somePhone)); + assertTrue(mergedLists.find(anotherPhone)); + assertEquals(2, mergedLists.get().size()); + } + + @Test + public void testMerge_SameLists_NoChange(){ + phoneList.add(somePhone); + + ListOf mergedLists = phoneList.merge(phoneList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(somePhone)); + assertEquals(phoneList.get().size(), mergedLists.get().size()); + } + + @Test + public void testMerge_ListsWithSharedValues_NoDuplicate(){ + ListOf anotherList = new ListOf(); + Phone anotherPhone = new Phone(0606060606,"another comment"); + + + phoneList.add(somePhone); + phoneList.add(anotherPhone); + + anotherList.add(anotherPhone); + + ListOf mergedLists = phoneList.merge(anotherList); + + assertNotNull(mergedLists); + assertEquals(2, mergedLists.get().size()); + + + } + @Test + public void testMerge_EmptyPhoneList_SameGroupList(){ + ListOf anotherList = new ListOf(); + + phoneList.add(somePhone); + + ListOf mergedLists = phoneList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(somePhone)); + assertEquals(1, mergedLists.get().size()); + } + + @Test + public void testMerge_NullGroupList_ExceptionThrown(){ + phoneList.add(somePhone); + assertThrows(NullPointerException.class, ()->phoneList.merge(null)); + } + +} \ No newline at end of file -- GitLab From 2104fb3323480041c26ecb73229fdfdf477e794b Mon Sep 17 00:00:00 2001 From: Gries Robin Date: Wed, 25 Mar 2020 11:35:31 +0100 Subject: [PATCH 075/120] Added non-regression tests for ListOf<> of Address, Card, Group, Mail and Phone --- .../address/nonRegression/ListOf.java | 25 +- .../nonRegression/ListOfAddressTest.java | 176 ++++++++++++++ .../{ListOfCard.java => ListOfCardTest.java} | 2 +- .../nonRegression/ListOfGroupTest.java | 171 ++++++++++++++ .../address/nonRegression/ListOfMailTest.java | 216 ++++++++++++++++++ .../nonRegression/ListOfPhoneTest.java | 183 +++++++++++++++ 6 files changed, 765 insertions(+), 8 deletions(-) create mode 100644 src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfAddressTest.java rename src/main/test/fr/unantes/software/construction/address/nonRegression/{ListOfCard.java => ListOfCardTest.java} (99%) create mode 100644 src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfGroupTest.java create mode 100644 src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfMailTest.java create mode 100644 src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfPhoneTest.java diff --git a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOf.java b/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOf.java index 7056db9e..1e92e754 100644 --- a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOf.java +++ b/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOf.java @@ -43,16 +43,27 @@ public class ListOf { return targetList; } - public void set(List newTargetList){ - targetList = newTargetList; + public void set(List newTargetList) { + if (newTargetList == null) { + throw new NullPointerException(); + } else { + targetList = newTargetList; + } } - public void add(T elt){ - //add() methods in FooList all check that elt doesn't exist yet, - // so they are actually Set instead of List - if(this.targetList.contains(elt)){ return; } - targetList.add(elt); + public void add(T elt) throws NullPointerException { + if (elt == null) { + throw new NullPointerException(); + } else { + //add() methods in FooList all check that elt doesn't exist yet, + // so they are actually Set instead of List + if (this.targetList.contains(elt)) { + return; + } + targetList.add(elt); + } } public void delete(T elt){ + Validate.notNull(elt); targetList.remove(elt); } public boolean find(T elt){ diff --git a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfAddressTest.java b/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfAddressTest.java new file mode 100644 index 00000000..9353da88 --- /dev/null +++ b/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfAddressTest.java @@ -0,0 +1,176 @@ +package fr.unantes.software.construction.address.nonRegression; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import fr.unantes.software.construction.address.Address; +import fr.unantes.software.construction.address.City; +import fr.unantes.software.construction.address.CompanyAddress; +import fr.unantes.software.construction.address.PrivateAddress; +import java.util.ArrayList; +import java.util.List; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class ListOfAddressTest { + + ListOf
addressList; + Address someAddress; + + @BeforeEach + void setUp() { + addressList = new ListOf<>(); + someAddress = new PrivateAddress(1,"Some Private Street", new City("Groenland","Qeqertarsuaq"),0,null); + } + + @Test + void testSet_ListOfGroups_addGroupsToCurrentList(){ + List
anotherList = new ArrayList<>(); + Address[] addresses = { someAddress, + new PrivateAddress(1,"Another Private Street", new City("Norvege","Honningsvag"),0,null), + new CompanyAddress(1,"A Company Street", new City("Australie","Pine Creek"),0,null,null) + }; + + for(Address each : addresses){ + anotherList.add(each); + } + + addressList.set(anotherList); + + for(Address each : addresses){ + assertTrue(addressList.find(each)); + } + } + + @Test + void testSet_NullValue_ExceptionThrown(){ + assertThrows(Exception.class, ()->addressList.set(null)); + } + + + @Test + public void testAdd_newValue_Succeed(){ + assertDoesNotThrow(() -> addressList.add(someAddress)); + assertTrue(addressList.find(someAddress)); + } + + @Test + public void testAdd_alreadyContainedValue_noDuplicate(){ + addressList.add(someAddress); + int currentSize = addressList.get().size(); + + addressList.add(someAddress); + assertEquals(currentSize,addressList.get().size()); + } + + @Test + public void testAdd_NullValue_ExceptionThrown(){ + int currentSize = addressList.get().size(); + assertThrows(Exception.class, () -> addressList.add(null)); + assertEquals(currentSize,addressList.get().size()); + } + + @Test + public void testDelete_ContainedValue_Succeed(){ + addressList.add(someAddress); + addressList.delete(someAddress); + + assertFalse(addressList.find(someAddress)); + } + + @Test + public void testDelete_ValueContainedByAnotherGroup_NoEffect(){ + ListOf
anotherList = new ListOf<>(); + anotherList.add(someAddress); + + int currentSize = addressList.get().size(); + assertFalse(addressList.find(someAddress)); + + addressList.delete(someAddress); + assertTrue(anotherList.find(someAddress)); + assertEquals(currentSize, addressList.get().size()); + } + + @Test + public void testFind_ContainedValue_ReturnTrue(){ + addressList.add(someAddress); + assertTrue(addressList.find(someAddress)); + } + + @Test + public void testFind_NotContainedValue_ReturnFalse(){ + addressList.add(new PrivateAddress(1,"Another Private Street", new City("Norvege","Honningsvag"),0,null)); + assertFalse(addressList.find(someAddress)); + } + + @Test + public void testMerge_TwoDifferentLists_ReturnListWithBothValue(){ + addressList.add(someAddress); + + Address anotherAddress = new PrivateAddress(1,"Another Private Street", new City("Norvege","Honningsvag"),0,null); + ListOf
anotherList = new ListOf<>(); + anotherList.add(anotherAddress); + + ListOf
mergedLists = addressList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someAddress)); + assertTrue(mergedLists.find(anotherAddress)); + assertEquals(2, mergedLists.get().size()); + } + + @Test + public void testMerge_SameLists_NoChange(){ + addressList.add(someAddress); + + ListOf
mergedLists = addressList.merge(addressList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someAddress)); + assertEquals(addressList.get().size(), mergedLists.get().size()); + } + + @Test + public void testMerge_ListsWithSharedValues_NoDuplicate(){ + Address anotherAddress = new PrivateAddress(1,"Another Private Street", new City("Norvege","Honningsvag"),0,null); + + addressList.add(someAddress); + addressList.add(anotherAddress); + + ListOf
anotherList = new ListOf<>(); + anotherList.add(anotherAddress); + + ListOf
mergedLists = addressList.merge(anotherList); + + assertNotNull(mergedLists); + assertEquals(2, mergedLists.get().size()); + + + } + @Test + public void testMerge_EmptyGroupList_SameGroupList(){ + ListOf
anotherList = new ListOf<>(); + + addressList.add(someAddress); + + ListOf
mergedLists = addressList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someAddress)); + assertEquals(1, mergedLists.get().size()); + } + + @Test + public void testMerge_NullGroupList_ExceptionThrown(){ + addressList.add(someAddress); + + assertThrows(NullPointerException.class, ()->addressList.merge(null)); + } + + + +} \ No newline at end of file diff --git a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfCard.java b/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfCardTest.java similarity index 99% rename from src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfCard.java rename to src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfCardTest.java index 4f496410..f0a234c7 100644 --- a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfCard.java +++ b/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfCardTest.java @@ -15,7 +15,7 @@ import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -class ListOfCard { +class ListOfCardTest { ListOf cardList; Card someCard; @BeforeEach diff --git a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfGroupTest.java b/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfGroupTest.java new file mode 100644 index 00000000..022ff480 --- /dev/null +++ b/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfGroupTest.java @@ -0,0 +1,171 @@ +package fr.unantes.software.construction.address.nonRegression; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import fr.unantes.software.construction.address.Group; +import java.util.Vector; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class ListOfGroupTest { + + ListOf groupList; + Group someGroup; + + @BeforeEach + void setUp() { + groupList = new ListOf(); + someGroup = new Group("a Group",""); + } + + @Test + void testSet_ListOfGroups_addGroupsToCurrentList(){ + Vector anotherList = new Vector(); + Group[] groups = { someGroup, + new Group("Group1",null), + new Group("Group2","Comment2"), + }; + + for(Group each : groups){ + anotherList.add(each); + } + + groupList.set(anotherList); + + for(Group each : groups){ + assertTrue(groupList.find(each)); + } + } + + @Test + void testSet_NullValue_ExceptionThrown(){ + assertThrows(Exception.class, ()->groupList.set(null)); + } + + + @Test + public void testAdd_newValue_Succeed(){ + assertDoesNotThrow(() -> groupList.add(someGroup)); + assertTrue(groupList.find(someGroup)); + } + + @Test + public void testAdd_alreadyContainedValue_noDuplicate(){ + groupList.add(someGroup); + int currentSize = groupList.size(); + + groupList.add(someGroup); + assertEquals(currentSize,groupList.size()); + } + + @Test + public void testAdd_NullValue_ExceptionThrown(){ + int currentSize = groupList.size(); + assertThrows(Exception.class, () -> groupList.add(null)); + assertEquals(currentSize,groupList.size()); + } + + @Test + public void testDelete_ContainedValue_Succeed(){ + groupList.add(someGroup); + groupList.delete(someGroup); + + assertFalse(groupList.find(someGroup)); + } + + @Test + public void testDelete_ValueContainedByAnotherGroup_NoEffect(){ + ListOf anotherList = new ListOf(); + anotherList.add(someGroup); + + int currentSize = groupList.size(); + assertFalse(groupList.find(someGroup)); + + groupList.delete(someGroup); + assertTrue(anotherList.find(someGroup)); + assertEquals(currentSize, groupList.size()); + } + + @Test + public void testFind_ContainedValue_ReturnTrue(){ + groupList.add(someGroup); + assertTrue(groupList.find(someGroup)); + } + + @Test + public void testFind_NotContainedValue_ReturnFalse(){ + groupList.add(new Group("anotherGroup", "")); + assertFalse(groupList.find(someGroup)); + } + + @Test + public void testMerge_TwoDifferentLists_ReturnListWithBothValue(){ + groupList.add(someGroup); + + Group anotherGroup = new Group("secondGroup", ""); + ListOf anotherList = new ListOf(); + anotherList.add(anotherGroup); + + ListOf mergedLists = groupList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someGroup)); + assertTrue(mergedLists.find(anotherGroup)); + assertEquals(2, mergedLists.size()); + } + + @Test + public void testMerge_SameLists_NoChange(){ + groupList.add(someGroup); + + ListOf mergedLists = groupList.merge(groupList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someGroup)); + assertEquals(groupList.size(), mergedLists.size()); + } + + @Test + public void testMerge_ListsWithSharedValues_NoDuplicate(){ + Group anotherGroup = new Group("secondGroup", ""); + + groupList.add(someGroup); + groupList.add(anotherGroup); + + ListOf anotherList = new ListOf(); + anotherList.add(anotherGroup); + + ListOf mergedLists = groupList.merge(anotherList); + + assertNotNull(mergedLists); + assertEquals(2, mergedLists.size()); + + + } + @Test + public void testMerge_EmptyGroupList_SameGroupList(){ + ListOf anotherList = new ListOf(); + + groupList.add(someGroup); + + ListOf mergedLists = groupList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someGroup)); + assertEquals(1, mergedLists.size()); + } + + @Test + public void testMerge_NullGroupList_ExceptionThrown(){ + groupList.add(someGroup); + + assertThrows(NullPointerException.class, ()->groupList.merge(null)); + } + + +} \ No newline at end of file diff --git a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfMailTest.java b/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfMailTest.java new file mode 100644 index 00000000..97568cfc --- /dev/null +++ b/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfMailTest.java @@ -0,0 +1,216 @@ +package fr.unantes.software.construction.address.nonRegression; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import fr.unantes.software.construction.address.Mail; +import java.util.Vector; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class ListOfMailTest { + + ListOf mailList; + Mail someMail; + + @BeforeEach + void setUp() { + mailList = new ListOf(); + someMail = new Mail("someHome@mail.com","someWork@mail.com"); + } + + @Test + void testSet_ListOfMails_addMailsToCurrentList(){ + Vector anotherList = new Vector(); + Mail[] mails = { new Mail(null,null), + new Mail("home1@mail.com",null), + new Mail(null, "work1@mail.co.jp"), + new Mail("home2@mail.fr","work2@mail.fr") + }; + + for(Mail each : mails){ + anotherList.add(each); + } + + mailList.set(anotherList); + + for(Mail each : mails){ + assertTrue(mailList.find(each)); + } + } + + @Test + void testSet_NullValue_ExceptionThrown(){ + assertThrows(Exception.class, ()->mailList.set(null)); + } + + @Test + void testAdd_NewMail_addMailToList(){ + mailList.add(someMail); + + assertTrue(mailList.find(someMail)); + } + + @Test + void testAdd_AlreadyExistingHomeMail_Fusion(){ + Mail oneMail = new Mail("someHome@mail.com",null); + Mail anotherMail = new Mail("someHome@mail.com","anotherWork@mail.com"); + + assertEquals(oneMail.getHome(),anotherMail.getHome()); + + mailList.add(oneMail); + mailList.add(anotherMail); + + assertTrue(mailList.find(oneMail)); + assertEquals("anotherWork@mail.com", oneMail.getWork()); + assertEquals("someHome@mail.com",oneMail.getHome()); + assertEquals(1,mailList.size()); + } + + @Test + void testAdd_AlreadyExistingWorkMail_NoFusion(){ + Mail oneMail = new Mail(null,"someWork@mail.com"); + Mail anotherMail = new Mail("anotherHome@mail.com","someWork@mail.com"); + + assertEquals(oneMail.getWork(),anotherMail.getWork()); + + mailList.add(oneMail); + mailList.add(anotherMail); + + assertTrue(mailList.find(oneMail)); + assertEquals("someWork@mail.com", oneMail.getWork()); + assertNotEquals("anotherHome@mail.com",oneMail.getHome()); + assertEquals(2,mailList.size()); + } + + @Test + void testAdd_Null_ExceptionThrown(){ + assertThrows(NullPointerException.class, () -> mailList.add(null)); + } + + @Test + void testDelete_ExistingMail_Succeed(){ + mailList.add(someMail); + + mailList.delete(someMail); + assertFalse(mailList.find(someMail)); + assertEquals(0,mailList.size()); + } + + @Test + void testDelete_NotContainedMail_NoEffect(){ + ListOf anotherList = new ListOf(); + Mail anotherMail = new Mail(null,null); + + mailList.add(someMail); + anotherList.add(anotherMail); + + mailList.delete(anotherMail); + + assertTrue(mailList.find(someMail)); + assertFalse(mailList.find(anotherMail)); + + assertTrue(anotherList.find(anotherMail)); + assertEquals(1,anotherList.size()); + } + + @Test + void testDelete_NullValue_ExceptionThrown(){ + assertThrows(NullPointerException.class, () -> mailList.delete(null)); + } + + @Test + void testFind_NoMailInCommon_ReturnFalse(){ + Mail anotherMail = new Mail("anotherHome@mail.com","anotherWork@mail.com"); + + mailList.add(someMail); + assertFalse(mailList.find(anotherMail)); + } + + @Test + void testFind_HomeMailInCommon_ReturnTrue(){ + Mail anotherMail = new Mail("someHome@mail.com","anotherWork@mail.com"); + + mailList.add(someMail); + assertTrue(mailList.find(anotherMail)); + } + + @Test + void testFind_WorkMailInCommon_ReturnFalse(){ + Mail anotherMail = new Mail("anotherHome@mail.com","someWork@mail.com"); + + mailList.add(someMail); + assertFalse(mailList.find(anotherMail)); + } + + @Test + public void testMerge_TwoDifferentLists_ReturnListWithBothValue(){ + mailList.add(someMail); + + Mail anotherMail = new Mail("anotherHome@mail.com", "anotherWork@mail.com"); + ListOf anotherList = new ListOf(); + anotherList.add(anotherMail); + + ListOf mergedLists = mailList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someMail)); + assertTrue(mergedLists.find(anotherMail)); + assertEquals(2, mergedLists.size()); + } + + @Test + public void testMerge_SameLists_NoChange(){ + mailList.add(someMail); + + ListOf mergedLists = mailList.merge(mailList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someMail)); + assertEquals(mailList.size(), mergedLists.size()); + } + + @Test + public void testMerge_ListsWithSharedValues_NoDuplicate(){ + Mail anotherMail = new Mail("anotherHome@mail.com", "anotherWork@mail.com"); + + + mailList.add(someMail); + mailList.add(anotherMail); + + ListOf anotherList = new ListOf(); + anotherList.add(anotherMail); + + ListOf mergedLists = mailList.merge(anotherList); + + assertNotNull(mergedLists); + assertEquals(2, mergedLists.size()); + + + } + @Test + public void testMerge_EmptyMailList_SameGroupList(){ + ListOf anotherList = new ListOf(); + + mailList.add(someMail); + + ListOf mergedLists = mailList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someMail)); + assertEquals(1, mergedLists.size()); + } + + @Test + public void testMerge_NullGroupList_ExceptionThrown(){ + mailList.add(someMail); + + assertThrows(NullPointerException.class, ()->mailList.merge(null)); + } + + +} \ No newline at end of file diff --git a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfPhoneTest.java b/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfPhoneTest.java new file mode 100644 index 00000000..1aafe15b --- /dev/null +++ b/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfPhoneTest.java @@ -0,0 +1,183 @@ +package fr.unantes.software.construction.address.nonRegression; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import fr.unantes.software.construction.address.Phone; +import java.util.Vector; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class ListOfPhoneTest { + + ListOf phoneList = new ListOf<>(); + Phone somePhone; + + @BeforeEach + void setUp() { + somePhone = new Phone(0600000000,"some comment"); + } + + @Test + void testSet_ListOfPhones_addPhonesToCurrentList(){ + Vector anotherList = new Vector<>(); + Phone[] phones = { somePhone, + new Phone(0600000001,null), + new Phone(0600000010,"another comment") + }; + + for(Phone each : phones){ + anotherList.add(each); + } + + phoneList.set(anotherList); + + for(Phone each : phones){ + assertTrue(phoneList.find(each)); + } + } + + @Test + void testSet_NullValue_ExceptionThrown(){ + assertThrows(Exception.class, ()->phoneList.set(null)); + } + + @Test + void testAdd_NewPhone_addPhoneToList(){ + phoneList.add(somePhone); + + assertTrue(phoneList.find(somePhone)); + } + + @Test + void testAdd_AlreadyExistingPhone_Fusion(){ + Phone onePhone = new Phone(somePhone.getPhoneNumber(), null); + Phone anotherPhone = new Phone(somePhone.getPhoneNumber(), "a different comment"); + + phoneList.add(onePhone); + phoneList.add(anotherPhone); + + assertTrue(phoneList.find(onePhone)); + assertEquals(1,phoneList.get().size()); + } + + @Test + void testAdd_Null_ExceptionThrown(){ + assertThrows(NullPointerException.class, () -> phoneList.add(null)); + } + + @Test + void testDelete_ExistingMail_Succeed(){ + phoneList.add(somePhone); + + phoneList.delete(somePhone); + assertFalse(phoneList.find(somePhone)); + assertEquals(0,phoneList.get().size()); + } + + @Test + void testDelete_NotContainedMail_NoEffect(){ + ListOf anotherList = new ListOf(); + Phone anotherPhone = new Phone(0606060606,"another comment"); + + phoneList.add(somePhone); + anotherList.add(anotherPhone); + + phoneList.delete(anotherPhone); + + assertTrue(phoneList.find(somePhone)); + assertFalse(phoneList.find(anotherPhone)); + + assertTrue(anotherList.find(anotherPhone)); + assertEquals(1,anotherList.get().size()); + } + + @Test + void testDelete_NullValue_ExceptionThrown(){ + assertThrows(NullPointerException.class, () -> phoneList.delete(null)); + } + + @Test + void testFind_NoPhoneInCommon_ReturnFalse(){ + Phone anotherPhone = new Phone(0606060606,"another comment"); + + phoneList.add(somePhone); + assertFalse(phoneList.find(anotherPhone)); + } + + @Test + void testFind_PhoneNumberInCommon_ReturnTrue(){ + Phone anotherPhone = new Phone(somePhone.getPhoneNumber(),"another comment"); + + phoneList.add(somePhone); + assertTrue(phoneList.find(anotherPhone)); + } + + + @Test + public void testMerge_TwoDifferentLists_ReturnListWithBothValue(){ + phoneList.add(somePhone); + + ListOf anotherList = new ListOf(); + Phone anotherPhone = new Phone(0606060606,"another comment"); + anotherList.add(anotherPhone); + + ListOf mergedLists = phoneList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(somePhone)); + assertTrue(mergedLists.find(anotherPhone)); + assertEquals(2, mergedLists.get().size()); + } + + @Test + public void testMerge_SameLists_NoChange(){ + phoneList.add(somePhone); + + ListOf mergedLists = phoneList.merge(phoneList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(somePhone)); + assertEquals(phoneList.get().size(), mergedLists.get().size()); + } + + @Test + public void testMerge_ListsWithSharedValues_NoDuplicate(){ + ListOf anotherList = new ListOf(); + Phone anotherPhone = new Phone(0606060606,"another comment"); + + + phoneList.add(somePhone); + phoneList.add(anotherPhone); + + anotherList.add(anotherPhone); + + ListOf mergedLists = phoneList.merge(anotherList); + + assertNotNull(mergedLists); + assertEquals(2, mergedLists.get().size()); + + + } + @Test + public void testMerge_EmptyPhoneList_SameGroupList(){ + ListOf anotherList = new ListOf(); + + phoneList.add(somePhone); + + ListOf mergedLists = phoneList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(somePhone)); + assertEquals(1, mergedLists.get().size()); + } + + @Test + public void testMerge_NullGroupList_ExceptionThrown(){ + phoneList.add(somePhone); + assertThrows(NullPointerException.class, ()->phoneList.merge(null)); + } + +} \ No newline at end of file -- GitLab From 00114b2c1329d7c0f9cb2850e7039735a6327f02 Mon Sep 17 00:00:00 2001 From: Gries Robin Date: Tue, 24 Mar 2020 20:19:30 +0100 Subject: [PATCH 076/120] Add better abstraction and non-regression tests for AddressList, CardList, GroupList, MailList, PhoneList Add a better abstraction of CardList and non-regression test Added non-regression tests for ListOf<> of Address, Card, Group, Mail and Phone Added non-regression tests for ListOf<> of Address, Card, Group, Mail and Phone --- .../address/nonRegression/ListOf.java | 115 ++++++++++ .../nonRegression/ListOfAddressTest.java | 176 ++++++++++++++ .../address/nonRegression/ListOfCardTest.java | 172 ++++++++++++++ .../nonRegression/ListOfGroupTest.java | 171 ++++++++++++++ .../address/nonRegression/ListOfMailTest.java | 216 ++++++++++++++++++ .../nonRegression/ListOfPhoneTest.java | 183 +++++++++++++++ 6 files changed, 1033 insertions(+) create mode 100644 src/main/test/fr/unantes/software/construction/address/nonRegression/ListOf.java create mode 100644 src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfAddressTest.java create mode 100644 src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfCardTest.java create mode 100644 src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfGroupTest.java create mode 100644 src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfMailTest.java create mode 100644 src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfPhoneTest.java diff --git a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOf.java b/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOf.java new file mode 100644 index 00000000..1e92e754 --- /dev/null +++ b/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOf.java @@ -0,0 +1,115 @@ +package fr.unantes.software.construction.address.nonRegression; + +import java.util.ArrayList; +import java.util.List; +import org.apache.commons.lang3.Validate; + +/** + * Issues #12 + * all classes called FooList have the same methods and could be replace + * with a simple List<Foo> + * + * Tests have been made for the original classes FooList and thus can be used for + * non-regression testing + * + * This class is used as an adapter to translate the methods of the java ArrayList to FooList, + * so that Tests can then be run using a List<Foo> and validate that the behavior + * stay the same. + */ +public class ListOf { + private List targetList; + + /** + * Empty constructor + */ + public ListOf(){ + targetList = new ArrayList(); + } + + /** + * Copy constructor + * @param otherList List to copy + */ + public ListOf(ListOf otherList){ + targetList = otherList.targetList; + } + + /** + * Note that the original FooList used a Vector, obviously we are replacing it with a List + * as it is better abstraction + * @return a List of element + */ + public List get() { + return targetList; + } + + public void set(List newTargetList) { + if (newTargetList == null) { + throw new NullPointerException(); + } else { + targetList = newTargetList; + } + } + public void add(T elt) throws NullPointerException { + if (elt == null) { + throw new NullPointerException(); + } else { + //add() methods in FooList all check that elt doesn't exist yet, + // so they are actually Set instead of List + if (this.targetList.contains(elt)) { + return; + } + targetList.add(elt); + } + } + public void delete(T elt){ + Validate.notNull(elt); + targetList.remove(elt); + } + public boolean find(T elt){ + return targetList.contains(elt); + } + + public int size(){ + return targetList.size(); + } + + /** + * Iterate on otherlist to add each element one by one to this ListOf + * @param otherList a list of elements to add to this ListOf + * @return a new ListOf containing the elements of this ListOf element and the elements of otherList + */ + public ListOf merge(ListOf otherList){ + Validate.notNull(otherList); + + ListOf newList = new ListOf(this); + + //It's slow , but speed isn't important for this test + for(T t : otherList.get()) { + if( !newList.find(t) ) { + newList.add(t); + } + } + + return newList; + } + + /** + * Delegate the merge to the methods of java.util.List, but it may have duplicates + * @param otherList a list of elements to add to this ListOf + * @return a new ListOf containing the elements of this ListOf element and the elements of otherList + */ + public ListOf delegateMerge( ListOf otherList){ + Validate.notNull(otherList); + + ListOf newList = new ListOf(this); + newList.get().addAll(otherList.get()); + + return newList; + } + + //TODO verifier / tester si les FooList force effectivemment les merge() à rendre une liste + // sans doublons + // si oui , peut etre utiliser un Set / HashSet + // +} diff --git a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfAddressTest.java b/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfAddressTest.java new file mode 100644 index 00000000..9353da88 --- /dev/null +++ b/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfAddressTest.java @@ -0,0 +1,176 @@ +package fr.unantes.software.construction.address.nonRegression; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import fr.unantes.software.construction.address.Address; +import fr.unantes.software.construction.address.City; +import fr.unantes.software.construction.address.CompanyAddress; +import fr.unantes.software.construction.address.PrivateAddress; +import java.util.ArrayList; +import java.util.List; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class ListOfAddressTest { + + ListOf
addressList; + Address someAddress; + + @BeforeEach + void setUp() { + addressList = new ListOf<>(); + someAddress = new PrivateAddress(1,"Some Private Street", new City("Groenland","Qeqertarsuaq"),0,null); + } + + @Test + void testSet_ListOfGroups_addGroupsToCurrentList(){ + List
anotherList = new ArrayList<>(); + Address[] addresses = { someAddress, + new PrivateAddress(1,"Another Private Street", new City("Norvege","Honningsvag"),0,null), + new CompanyAddress(1,"A Company Street", new City("Australie","Pine Creek"),0,null,null) + }; + + for(Address each : addresses){ + anotherList.add(each); + } + + addressList.set(anotherList); + + for(Address each : addresses){ + assertTrue(addressList.find(each)); + } + } + + @Test + void testSet_NullValue_ExceptionThrown(){ + assertThrows(Exception.class, ()->addressList.set(null)); + } + + + @Test + public void testAdd_newValue_Succeed(){ + assertDoesNotThrow(() -> addressList.add(someAddress)); + assertTrue(addressList.find(someAddress)); + } + + @Test + public void testAdd_alreadyContainedValue_noDuplicate(){ + addressList.add(someAddress); + int currentSize = addressList.get().size(); + + addressList.add(someAddress); + assertEquals(currentSize,addressList.get().size()); + } + + @Test + public void testAdd_NullValue_ExceptionThrown(){ + int currentSize = addressList.get().size(); + assertThrows(Exception.class, () -> addressList.add(null)); + assertEquals(currentSize,addressList.get().size()); + } + + @Test + public void testDelete_ContainedValue_Succeed(){ + addressList.add(someAddress); + addressList.delete(someAddress); + + assertFalse(addressList.find(someAddress)); + } + + @Test + public void testDelete_ValueContainedByAnotherGroup_NoEffect(){ + ListOf
anotherList = new ListOf<>(); + anotherList.add(someAddress); + + int currentSize = addressList.get().size(); + assertFalse(addressList.find(someAddress)); + + addressList.delete(someAddress); + assertTrue(anotherList.find(someAddress)); + assertEquals(currentSize, addressList.get().size()); + } + + @Test + public void testFind_ContainedValue_ReturnTrue(){ + addressList.add(someAddress); + assertTrue(addressList.find(someAddress)); + } + + @Test + public void testFind_NotContainedValue_ReturnFalse(){ + addressList.add(new PrivateAddress(1,"Another Private Street", new City("Norvege","Honningsvag"),0,null)); + assertFalse(addressList.find(someAddress)); + } + + @Test + public void testMerge_TwoDifferentLists_ReturnListWithBothValue(){ + addressList.add(someAddress); + + Address anotherAddress = new PrivateAddress(1,"Another Private Street", new City("Norvege","Honningsvag"),0,null); + ListOf
anotherList = new ListOf<>(); + anotherList.add(anotherAddress); + + ListOf
mergedLists = addressList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someAddress)); + assertTrue(mergedLists.find(anotherAddress)); + assertEquals(2, mergedLists.get().size()); + } + + @Test + public void testMerge_SameLists_NoChange(){ + addressList.add(someAddress); + + ListOf
mergedLists = addressList.merge(addressList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someAddress)); + assertEquals(addressList.get().size(), mergedLists.get().size()); + } + + @Test + public void testMerge_ListsWithSharedValues_NoDuplicate(){ + Address anotherAddress = new PrivateAddress(1,"Another Private Street", new City("Norvege","Honningsvag"),0,null); + + addressList.add(someAddress); + addressList.add(anotherAddress); + + ListOf
anotherList = new ListOf<>(); + anotherList.add(anotherAddress); + + ListOf
mergedLists = addressList.merge(anotherList); + + assertNotNull(mergedLists); + assertEquals(2, mergedLists.get().size()); + + + } + @Test + public void testMerge_EmptyGroupList_SameGroupList(){ + ListOf
anotherList = new ListOf<>(); + + addressList.add(someAddress); + + ListOf
mergedLists = addressList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someAddress)); + assertEquals(1, mergedLists.get().size()); + } + + @Test + public void testMerge_NullGroupList_ExceptionThrown(){ + addressList.add(someAddress); + + assertThrows(NullPointerException.class, ()->addressList.merge(null)); + } + + + +} \ No newline at end of file diff --git a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfCardTest.java b/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfCardTest.java new file mode 100644 index 00000000..f0a234c7 --- /dev/null +++ b/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfCardTest.java @@ -0,0 +1,172 @@ +package fr.unantes.software.construction.address.nonRegression; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import fr.unantes.software.construction.address.Card; +import fr.unantes.software.construction.address.CompanyCard; +import fr.unantes.software.construction.address.PrivateCard; +import java.util.ArrayList; +import java.util.List; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class ListOfCardTest { + ListOf cardList; + Card someCard; + @BeforeEach + void setUp() { + cardList = new ListOf<>(); + someCard = new PrivateCard("John","Doe"); + } + + @Test + void testSet_ListOfCards_addCardsToCurrentList(){ + List anotherList = new ArrayList<>(); + Card[] cards = { someCard, + new PrivateCard("Tom","Joe"), + new CompanyCard("JohnDoe Corp.") + }; + + for(Card each : cards){ + anotherList.add(each); + } + + cardList.set(anotherList); + + for(Card each : cards){ + assertTrue(cardList.find(each)); + } + } + + @Test + void testSet_NullValue_ExceptionThrown(){ + assertThrows(Exception.class, ()-> cardList.set(null)); + } + + + @Test + public void testAdd_newValue_Succeed(){ + assertDoesNotThrow(() -> cardList.add(someCard)); + assertTrue(cardList.find(someCard)); + } + + @Test + public void testAdd_alreadyContainedValue_noDuplicate(){ + cardList.add(someCard); + int currentSize = cardList.get().size(); + + cardList.add(someCard); + assertEquals(currentSize, cardList.get().size()); + } + + @Test + public void testAdd_NullValue_ExceptionThrown(){ + int currentSize = cardList.get().size(); + assertThrows(Exception.class, () -> cardList.add(null)); + assertEquals(currentSize, cardList.get().size()); + } + + @Test + public void testDelete_ContainedValue_Succeed(){ + cardList.add(someCard); + cardList.delete(someCard); + + assertFalse(cardList.find(someCard)); + } + + @Test + public void testDelete_ValueContainedByAnotherGroup_NoEffect(){ + ListOf anotherList = new ListOf<>(); + anotherList.add(someCard); + + int currentSize = cardList.get().size(); + assertFalse(cardList.find(someCard)); + + cardList.delete(someCard); + assertTrue(anotherList.find(someCard)); + assertEquals(currentSize, cardList.get().size()); + } + + @Test + public void testFind_ContainedValue_ReturnTrue(){ + cardList.add(someCard); + assertTrue(cardList.find(someCard)); + } + + @Test + public void testFind_NotContainedValue_ReturnFalse(){ + cardList.add(new PrivateCard("Tom","Joe")); + assertFalse(cardList.find(someCard)); + } + + @Test + public void testMerge_TwoDifferentLists_ReturnListWithBothValue(){ + cardList.add(someCard); + + Card anotherCard = new PrivateCard("Tom", "Joe"); + ListOf anotherList = new ListOf<>(); + anotherList.add(anotherCard); + + ListOf mergedLists = cardList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someCard)); + assertTrue(mergedLists.find(anotherCard)); + assertEquals(2, mergedLists.get().size()); + } + + @Test + public void testMerge_SameLists_NoChange(){ + cardList.add(someCard); + + ListOf mergedLists = cardList.merge(cardList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someCard)); + assertEquals(cardList.get().size(), mergedLists.get().size()); + } + + @Test + public void testMerge_ListsWithSharedValues_NoDuplicate(){ + Card anotherCard = new PrivateCard("Tom", "Joe"); + + cardList.add(someCard); + cardList.add(anotherCard); + + ListOf anotherList = new ListOf<>(); + anotherList.add(anotherCard); + + ListOf mergedLists = cardList.merge(anotherList); + + assertNotNull(mergedLists); + assertEquals(2, mergedLists.get().size()); + + + } + @Test + public void testMerge_EmptyCardList_SameCardList(){ + ListOf anotherList = new ListOf<>(); + + cardList.add(someCard); + + ListOf mergedLists = cardList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someCard)); + assertEquals(1, mergedLists.get().size()); + } + + @Test + public void testMerge_NullCardList_ExceptionThrown(){ + cardList.add(someCard); + + assertThrows(NullPointerException.class, ()-> cardList.merge(null)); + } + + +} \ No newline at end of file diff --git a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfGroupTest.java b/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfGroupTest.java new file mode 100644 index 00000000..022ff480 --- /dev/null +++ b/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfGroupTest.java @@ -0,0 +1,171 @@ +package fr.unantes.software.construction.address.nonRegression; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import fr.unantes.software.construction.address.Group; +import java.util.Vector; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class ListOfGroupTest { + + ListOf groupList; + Group someGroup; + + @BeforeEach + void setUp() { + groupList = new ListOf(); + someGroup = new Group("a Group",""); + } + + @Test + void testSet_ListOfGroups_addGroupsToCurrentList(){ + Vector anotherList = new Vector(); + Group[] groups = { someGroup, + new Group("Group1",null), + new Group("Group2","Comment2"), + }; + + for(Group each : groups){ + anotherList.add(each); + } + + groupList.set(anotherList); + + for(Group each : groups){ + assertTrue(groupList.find(each)); + } + } + + @Test + void testSet_NullValue_ExceptionThrown(){ + assertThrows(Exception.class, ()->groupList.set(null)); + } + + + @Test + public void testAdd_newValue_Succeed(){ + assertDoesNotThrow(() -> groupList.add(someGroup)); + assertTrue(groupList.find(someGroup)); + } + + @Test + public void testAdd_alreadyContainedValue_noDuplicate(){ + groupList.add(someGroup); + int currentSize = groupList.size(); + + groupList.add(someGroup); + assertEquals(currentSize,groupList.size()); + } + + @Test + public void testAdd_NullValue_ExceptionThrown(){ + int currentSize = groupList.size(); + assertThrows(Exception.class, () -> groupList.add(null)); + assertEquals(currentSize,groupList.size()); + } + + @Test + public void testDelete_ContainedValue_Succeed(){ + groupList.add(someGroup); + groupList.delete(someGroup); + + assertFalse(groupList.find(someGroup)); + } + + @Test + public void testDelete_ValueContainedByAnotherGroup_NoEffect(){ + ListOf anotherList = new ListOf(); + anotherList.add(someGroup); + + int currentSize = groupList.size(); + assertFalse(groupList.find(someGroup)); + + groupList.delete(someGroup); + assertTrue(anotherList.find(someGroup)); + assertEquals(currentSize, groupList.size()); + } + + @Test + public void testFind_ContainedValue_ReturnTrue(){ + groupList.add(someGroup); + assertTrue(groupList.find(someGroup)); + } + + @Test + public void testFind_NotContainedValue_ReturnFalse(){ + groupList.add(new Group("anotherGroup", "")); + assertFalse(groupList.find(someGroup)); + } + + @Test + public void testMerge_TwoDifferentLists_ReturnListWithBothValue(){ + groupList.add(someGroup); + + Group anotherGroup = new Group("secondGroup", ""); + ListOf anotherList = new ListOf(); + anotherList.add(anotherGroup); + + ListOf mergedLists = groupList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someGroup)); + assertTrue(mergedLists.find(anotherGroup)); + assertEquals(2, mergedLists.size()); + } + + @Test + public void testMerge_SameLists_NoChange(){ + groupList.add(someGroup); + + ListOf mergedLists = groupList.merge(groupList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someGroup)); + assertEquals(groupList.size(), mergedLists.size()); + } + + @Test + public void testMerge_ListsWithSharedValues_NoDuplicate(){ + Group anotherGroup = new Group("secondGroup", ""); + + groupList.add(someGroup); + groupList.add(anotherGroup); + + ListOf anotherList = new ListOf(); + anotherList.add(anotherGroup); + + ListOf mergedLists = groupList.merge(anotherList); + + assertNotNull(mergedLists); + assertEquals(2, mergedLists.size()); + + + } + @Test + public void testMerge_EmptyGroupList_SameGroupList(){ + ListOf anotherList = new ListOf(); + + groupList.add(someGroup); + + ListOf mergedLists = groupList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someGroup)); + assertEquals(1, mergedLists.size()); + } + + @Test + public void testMerge_NullGroupList_ExceptionThrown(){ + groupList.add(someGroup); + + assertThrows(NullPointerException.class, ()->groupList.merge(null)); + } + + +} \ No newline at end of file diff --git a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfMailTest.java b/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfMailTest.java new file mode 100644 index 00000000..97568cfc --- /dev/null +++ b/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfMailTest.java @@ -0,0 +1,216 @@ +package fr.unantes.software.construction.address.nonRegression; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import fr.unantes.software.construction.address.Mail; +import java.util.Vector; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class ListOfMailTest { + + ListOf mailList; + Mail someMail; + + @BeforeEach + void setUp() { + mailList = new ListOf(); + someMail = new Mail("someHome@mail.com","someWork@mail.com"); + } + + @Test + void testSet_ListOfMails_addMailsToCurrentList(){ + Vector anotherList = new Vector(); + Mail[] mails = { new Mail(null,null), + new Mail("home1@mail.com",null), + new Mail(null, "work1@mail.co.jp"), + new Mail("home2@mail.fr","work2@mail.fr") + }; + + for(Mail each : mails){ + anotherList.add(each); + } + + mailList.set(anotherList); + + for(Mail each : mails){ + assertTrue(mailList.find(each)); + } + } + + @Test + void testSet_NullValue_ExceptionThrown(){ + assertThrows(Exception.class, ()->mailList.set(null)); + } + + @Test + void testAdd_NewMail_addMailToList(){ + mailList.add(someMail); + + assertTrue(mailList.find(someMail)); + } + + @Test + void testAdd_AlreadyExistingHomeMail_Fusion(){ + Mail oneMail = new Mail("someHome@mail.com",null); + Mail anotherMail = new Mail("someHome@mail.com","anotherWork@mail.com"); + + assertEquals(oneMail.getHome(),anotherMail.getHome()); + + mailList.add(oneMail); + mailList.add(anotherMail); + + assertTrue(mailList.find(oneMail)); + assertEquals("anotherWork@mail.com", oneMail.getWork()); + assertEquals("someHome@mail.com",oneMail.getHome()); + assertEquals(1,mailList.size()); + } + + @Test + void testAdd_AlreadyExistingWorkMail_NoFusion(){ + Mail oneMail = new Mail(null,"someWork@mail.com"); + Mail anotherMail = new Mail("anotherHome@mail.com","someWork@mail.com"); + + assertEquals(oneMail.getWork(),anotherMail.getWork()); + + mailList.add(oneMail); + mailList.add(anotherMail); + + assertTrue(mailList.find(oneMail)); + assertEquals("someWork@mail.com", oneMail.getWork()); + assertNotEquals("anotherHome@mail.com",oneMail.getHome()); + assertEquals(2,mailList.size()); + } + + @Test + void testAdd_Null_ExceptionThrown(){ + assertThrows(NullPointerException.class, () -> mailList.add(null)); + } + + @Test + void testDelete_ExistingMail_Succeed(){ + mailList.add(someMail); + + mailList.delete(someMail); + assertFalse(mailList.find(someMail)); + assertEquals(0,mailList.size()); + } + + @Test + void testDelete_NotContainedMail_NoEffect(){ + ListOf anotherList = new ListOf(); + Mail anotherMail = new Mail(null,null); + + mailList.add(someMail); + anotherList.add(anotherMail); + + mailList.delete(anotherMail); + + assertTrue(mailList.find(someMail)); + assertFalse(mailList.find(anotherMail)); + + assertTrue(anotherList.find(anotherMail)); + assertEquals(1,anotherList.size()); + } + + @Test + void testDelete_NullValue_ExceptionThrown(){ + assertThrows(NullPointerException.class, () -> mailList.delete(null)); + } + + @Test + void testFind_NoMailInCommon_ReturnFalse(){ + Mail anotherMail = new Mail("anotherHome@mail.com","anotherWork@mail.com"); + + mailList.add(someMail); + assertFalse(mailList.find(anotherMail)); + } + + @Test + void testFind_HomeMailInCommon_ReturnTrue(){ + Mail anotherMail = new Mail("someHome@mail.com","anotherWork@mail.com"); + + mailList.add(someMail); + assertTrue(mailList.find(anotherMail)); + } + + @Test + void testFind_WorkMailInCommon_ReturnFalse(){ + Mail anotherMail = new Mail("anotherHome@mail.com","someWork@mail.com"); + + mailList.add(someMail); + assertFalse(mailList.find(anotherMail)); + } + + @Test + public void testMerge_TwoDifferentLists_ReturnListWithBothValue(){ + mailList.add(someMail); + + Mail anotherMail = new Mail("anotherHome@mail.com", "anotherWork@mail.com"); + ListOf anotherList = new ListOf(); + anotherList.add(anotherMail); + + ListOf mergedLists = mailList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someMail)); + assertTrue(mergedLists.find(anotherMail)); + assertEquals(2, mergedLists.size()); + } + + @Test + public void testMerge_SameLists_NoChange(){ + mailList.add(someMail); + + ListOf mergedLists = mailList.merge(mailList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someMail)); + assertEquals(mailList.size(), mergedLists.size()); + } + + @Test + public void testMerge_ListsWithSharedValues_NoDuplicate(){ + Mail anotherMail = new Mail("anotherHome@mail.com", "anotherWork@mail.com"); + + + mailList.add(someMail); + mailList.add(anotherMail); + + ListOf anotherList = new ListOf(); + anotherList.add(anotherMail); + + ListOf mergedLists = mailList.merge(anotherList); + + assertNotNull(mergedLists); + assertEquals(2, mergedLists.size()); + + + } + @Test + public void testMerge_EmptyMailList_SameGroupList(){ + ListOf anotherList = new ListOf(); + + mailList.add(someMail); + + ListOf mergedLists = mailList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(someMail)); + assertEquals(1, mergedLists.size()); + } + + @Test + public void testMerge_NullGroupList_ExceptionThrown(){ + mailList.add(someMail); + + assertThrows(NullPointerException.class, ()->mailList.merge(null)); + } + + +} \ No newline at end of file diff --git a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfPhoneTest.java b/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfPhoneTest.java new file mode 100644 index 00000000..1aafe15b --- /dev/null +++ b/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfPhoneTest.java @@ -0,0 +1,183 @@ +package fr.unantes.software.construction.address.nonRegression; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import fr.unantes.software.construction.address.Phone; +import java.util.Vector; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class ListOfPhoneTest { + + ListOf phoneList = new ListOf<>(); + Phone somePhone; + + @BeforeEach + void setUp() { + somePhone = new Phone(0600000000,"some comment"); + } + + @Test + void testSet_ListOfPhones_addPhonesToCurrentList(){ + Vector anotherList = new Vector<>(); + Phone[] phones = { somePhone, + new Phone(0600000001,null), + new Phone(0600000010,"another comment") + }; + + for(Phone each : phones){ + anotherList.add(each); + } + + phoneList.set(anotherList); + + for(Phone each : phones){ + assertTrue(phoneList.find(each)); + } + } + + @Test + void testSet_NullValue_ExceptionThrown(){ + assertThrows(Exception.class, ()->phoneList.set(null)); + } + + @Test + void testAdd_NewPhone_addPhoneToList(){ + phoneList.add(somePhone); + + assertTrue(phoneList.find(somePhone)); + } + + @Test + void testAdd_AlreadyExistingPhone_Fusion(){ + Phone onePhone = new Phone(somePhone.getPhoneNumber(), null); + Phone anotherPhone = new Phone(somePhone.getPhoneNumber(), "a different comment"); + + phoneList.add(onePhone); + phoneList.add(anotherPhone); + + assertTrue(phoneList.find(onePhone)); + assertEquals(1,phoneList.get().size()); + } + + @Test + void testAdd_Null_ExceptionThrown(){ + assertThrows(NullPointerException.class, () -> phoneList.add(null)); + } + + @Test + void testDelete_ExistingMail_Succeed(){ + phoneList.add(somePhone); + + phoneList.delete(somePhone); + assertFalse(phoneList.find(somePhone)); + assertEquals(0,phoneList.get().size()); + } + + @Test + void testDelete_NotContainedMail_NoEffect(){ + ListOf anotherList = new ListOf(); + Phone anotherPhone = new Phone(0606060606,"another comment"); + + phoneList.add(somePhone); + anotherList.add(anotherPhone); + + phoneList.delete(anotherPhone); + + assertTrue(phoneList.find(somePhone)); + assertFalse(phoneList.find(anotherPhone)); + + assertTrue(anotherList.find(anotherPhone)); + assertEquals(1,anotherList.get().size()); + } + + @Test + void testDelete_NullValue_ExceptionThrown(){ + assertThrows(NullPointerException.class, () -> phoneList.delete(null)); + } + + @Test + void testFind_NoPhoneInCommon_ReturnFalse(){ + Phone anotherPhone = new Phone(0606060606,"another comment"); + + phoneList.add(somePhone); + assertFalse(phoneList.find(anotherPhone)); + } + + @Test + void testFind_PhoneNumberInCommon_ReturnTrue(){ + Phone anotherPhone = new Phone(somePhone.getPhoneNumber(),"another comment"); + + phoneList.add(somePhone); + assertTrue(phoneList.find(anotherPhone)); + } + + + @Test + public void testMerge_TwoDifferentLists_ReturnListWithBothValue(){ + phoneList.add(somePhone); + + ListOf anotherList = new ListOf(); + Phone anotherPhone = new Phone(0606060606,"another comment"); + anotherList.add(anotherPhone); + + ListOf mergedLists = phoneList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(somePhone)); + assertTrue(mergedLists.find(anotherPhone)); + assertEquals(2, mergedLists.get().size()); + } + + @Test + public void testMerge_SameLists_NoChange(){ + phoneList.add(somePhone); + + ListOf mergedLists = phoneList.merge(phoneList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(somePhone)); + assertEquals(phoneList.get().size(), mergedLists.get().size()); + } + + @Test + public void testMerge_ListsWithSharedValues_NoDuplicate(){ + ListOf anotherList = new ListOf(); + Phone anotherPhone = new Phone(0606060606,"another comment"); + + + phoneList.add(somePhone); + phoneList.add(anotherPhone); + + anotherList.add(anotherPhone); + + ListOf mergedLists = phoneList.merge(anotherList); + + assertNotNull(mergedLists); + assertEquals(2, mergedLists.get().size()); + + + } + @Test + public void testMerge_EmptyPhoneList_SameGroupList(){ + ListOf anotherList = new ListOf(); + + phoneList.add(somePhone); + + ListOf mergedLists = phoneList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.find(somePhone)); + assertEquals(1, mergedLists.get().size()); + } + + @Test + public void testMerge_NullGroupList_ExceptionThrown(){ + phoneList.add(somePhone); + assertThrows(NullPointerException.class, ()->phoneList.merge(null)); + } + +} \ No newline at end of file -- GitLab From 6eae62b15b786a1d0633c8ca5da430b63b095e5d Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Wed, 25 Mar 2020 13:18:58 +0100 Subject: [PATCH 077/120] Changed Card class and related to handle unique identifier --- .../software/construction/address/Card.java | 54 +++-- .../construction/address/CompanyCard.java | 49 +---- .../construction/address/PrivateCard.java | 82 +------ .../construction/address/CompanyCardTest.java | 184 +--------------- .../construction/address/PrivateCardTest.java | 203 +----------------- 5 files changed, 57 insertions(+), 515 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/address/Card.java b/src/main/java/fr/unantes/software/construction/address/Card.java index 31d51416..a0bec384 100755 --- a/src/main/java/fr/unantes/software/construction/address/Card.java +++ b/src/main/java/fr/unantes/software/construction/address/Card.java @@ -1,8 +1,11 @@ package fr.unantes.software.construction.address; import fr.unantes.software.construction.Client; +import fr.unantes.software.construction.references.SingleReference; import org.apache.commons.lang3.Validate; +import java.util.UUID; + /** * @author * @version 1.0 @@ -10,21 +13,22 @@ import org.apache.commons.lang3.Validate; */ public abstract class Card { - protected String identification; - protected GroupList groups = new GroupList(); - protected AddressList addresses = new AddressList(); - protected PhoneList phones = new PhoneList(); - protected MailList mails = new MailList(); - private Client client; + private final UUID identification = UUID.randomUUID(); + private GroupList groups = new GroupList(); + private AddressList addresses = new AddressList(); + private PhoneList phones = new PhoneList(); + private MailList mails = new MailList(); + protected SingleReference client = new SingleReference(this) { + @Override + public SingleReference oppositeFor(Client target) { + return target.getCard(); + } + }; - /** - * Constructeur sans parametres - */ - public Card(String id) { - identification = id; + public Card(Client client){ + this.client.set(client); } - /** * @return addresses */ @@ -52,7 +56,7 @@ public abstract class Card { public GroupList getGroups() { return groups; } - + /** * @param addresses @@ -87,16 +91,13 @@ public abstract class Card { } /** - * Renvoie une fusion de deux fiches. - * @param card - * @return + * @return groups */ - public abstract Card merge(Card card); - - public abstract CompanyCard mergeCompanyCard(CompanyCard card); - - public abstract PrivateCard mergePrivateCard(PrivateCard card); - + public SingleReference getOwner() { + return client; + } + + public abstract String getName(); public abstract String toXML(); @@ -107,19 +108,14 @@ public abstract class Card { /** * @return _nomF nom de la fiche */ - public String getIdentification() { + public UUID getIdentification() { return identification; } - - public void setIdentification(String str) { - Validate.notNull(str); - identification = str; - } public boolean equals(Object other) { if (other instanceof Card) { - return identification.equals(((Card) other).identification); + return client.get().getIdentification().equals(((Card) other).client.get().getIdentification()); } return false; } diff --git a/src/main/java/fr/unantes/software/construction/address/CompanyCard.java b/src/main/java/fr/unantes/software/construction/address/CompanyCard.java index 1ea77706..be6b199a 100755 --- a/src/main/java/fr/unantes/software/construction/address/CompanyCard.java +++ b/src/main/java/fr/unantes/software/construction/address/CompanyCard.java @@ -1,16 +1,15 @@ package fr.unantes.software.construction.address; +import fr.unantes.software.construction.CompanyClient; import org.apache.commons.lang3.Validate; public class CompanyCard extends Card { - protected String companyName; - - public CompanyCard(String companyName) { - super(companyName); - Validate.notNull(companyName); - this.companyName = companyName; + public CompanyCard(CompanyClient client) { + super(client); + Validate.notNull(client); + this.companyName = client.getName(); } @@ -23,41 +22,13 @@ public class CompanyCard extends Card { this.companyName = companyName; } - public CompanyCard mergeCompanyCard(CompanyCard card) { - CompanyCard newCard = new CompanyCard(identification); - - card.setIdentification(identification); - card.setCompanyName(companyName); - - newCard.setCompanyName(companyName); - newCard.setAddresses(addresses.merge(card.getAddresses())); - newCard.setPhones(phones.merge(card.getPhones())); - newCard.setMails(mails.merge(card.getMails())); - newCard.setGroups(groups.merge(card.getGroups())); - - return newCard; - } - - /** - * Fusione deux fiches en une troisieme. - * - * @see Card#merge(Card) - */ - - public Card merge(Card card) { - Card res = new CompanyCard(identification); - - if (identicalCard(card)) - res = card.mergeCompanyCard(this); - return res; - } - - public PrivateCard mergePrivateCard(PrivateCard card) { - return null; + @Override + public String getName() { + return companyName; } public String toXML() { - return ("" + identification + companyName + addresses.toXML() - + phones.toXML() + mails.toXML() + groups.toXML() + ""); + return ("" + getIdentification() + companyName + getAddresses().toXML() + + getPhones().toXML() + getMails().toXML() + getGroups().toXML() + ""); } } diff --git a/src/main/java/fr/unantes/software/construction/address/PrivateCard.java b/src/main/java/fr/unantes/software/construction/address/PrivateCard.java index 549c417b..1a27865d 100755 --- a/src/main/java/fr/unantes/software/construction/address/PrivateCard.java +++ b/src/main/java/fr/unantes/software/construction/address/PrivateCard.java @@ -1,5 +1,7 @@ package fr.unantes.software.construction.address; +import fr.unantes.software.construction.PrivateClient; + /** * @author * @version 1.0 @@ -7,88 +9,24 @@ package fr.unantes.software.construction.address; */ public class PrivateCard extends Card { + private PrivateClient client; /** attributs d'insatance */ - protected String firstName; - protected String lastName; - - - public PrivateCard(String lastName, String firstName) { - super(lastName + firstName); - this.lastName = lastName; - this.firstName = firstName; - } - - public PrivateCard(String id) { - super(id); - lastName = ""; - firstName = ""; - } - - /** - * @return lastName nom de la personne de la fiche - */ - public String getLastName() { - return lastName; + public PrivateCard(PrivateClient client) { + super(client); + this.client = client; } /** * @return firstName prenom de la personne de la fiche */ - public String getFirstName() { - return firstName; - } - - /** - * @return _nom lastName de la personne de la fiche - */ - public void setLastName(String lastName) { - this.lastName = lastName; + public String getName(){ + return client.getFirstName()+" "+client.getLastName(); } - /** - * @param firstName - * prenom de la personne de la fiche - */ - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - /** - * permet la fusion entre la fiche courante et une fiche passee en parametre - * dans une troisieme fiche - * - * @param card fiche a faire fusionner a vec la fiche courante - * @return fiche resultant de la fusion de la fiche courante et celle passee en parametre - */ - public Card merge(Card card) { - Card newCard = new PrivateCard(identification); - if (identicalCard(card)) - newCard = card.mergePrivateCard(this); - return newCard; - } - - public CompanyCard mergeCompanyCard(CompanyCard card) { - return null; - } - - public PrivateCard mergePrivateCard(PrivateCard card) { - PrivateCard newCard = new PrivateCard(identification); - newCard.setIdentification(identification); - newCard.setLastName(lastName); - if (firstName == null) - newCard.setFirstName(card.getFirstName()); - else - newCard.setFirstName(firstName); - newCard.setAddresses(addresses.merge(card.getAddresses())); - newCard.setPhones(phones.merge(card.getPhones())); - newCard.setMails(mails.merge(card.getMails())); - newCard.setGroups(groups.merge(card.getGroups())); - return newCard; - } public String toXML() { - return ("" + identification + lastName + firstName + addresses.toXML() - + phones.toXML() + mails.toXML() + groups.toXML() + ""); + return ("" + getIdentification() + client.getLastName() + client.getFirstName() + getAddresses().toXML() + + getPhones().toXML() + getMails().toXML() + getGroups().toXML() + ""); } } diff --git a/src/main/test/fr/unantes/software/construction/address/CompanyCardTest.java b/src/main/test/fr/unantes/software/construction/address/CompanyCardTest.java index 8e745aa0..7512e7e3 100644 --- a/src/main/test/fr/unantes/software/construction/address/CompanyCardTest.java +++ b/src/main/test/fr/unantes/software/construction/address/CompanyCardTest.java @@ -1,40 +1,18 @@ package fr.unantes.software.construction.address; +import fr.unantes.software.construction.CompanyClient; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.mockito.internal.matchers.Null; import static org.junit.jupiter.api.Assertions.*; class CompanyCardTest { - CompanyCard companyCard; - AddressList someAddresses; CompanyAddress anAddress; - PhoneList somePhones; Phone aPhone; - MailList someMails; Mail aMail; - GroupList someGroups; Group aGroup; - + private CompanyCard companyCard; @BeforeEach - void setUp() { - companyCard = new CompanyCard("companyName"); - - someAddresses = new AddressList(); - somePhones = new PhoneList(); - someMails = new MailList(); - someGroups = new GroupList(); - - anAddress = new CompanyAddress(1, "Some Company Street", new City("Groenland", "Qeqertarsuaq"), 0, null,null); - someAddresses.add(anAddress); - companyCard.setAddresses(someAddresses); - aPhone = new Phone(0202020202, ""); - somePhones.add(aPhone); - companyCard.setPhones(somePhones); - aMail = new Mail(null, "work@mail.io"); - someMails.add(aMail); - companyCard.setMails(someMails); - aGroup = new Group("someName", ""); - someGroups.add(aGroup); - companyCard.setGroups(someGroups); + void setUp(){ + CompanyClient someClient = new CompanyClient("companyName"); + companyCard = new CompanyCard(someClient); } /* @@ -96,36 +74,6 @@ class CompanyCardTest { assertNotEquals(null, companyCard.getGroups()); } - @Test - void testSetIdentification_AnyStringValue_Succeed(){ - companyCard.setIdentification("id002"); - - assertEquals("id002", companyCard.getIdentification()); - - } - - @Test - void testSetIdentification_NullValue_ExceptionThrown(){ - assertThrows(NullPointerException.class, ()-> companyCard.setIdentification(null)); - assertNotEquals(null, companyCard.getIdentification()); - } - - @Test - void testIdenticalCard_SameCardId_ReturnTrue(){ - CompanyCard anotherCard = new CompanyCard("companyName"); - - assertEquals(anotherCard.getIdentification(), companyCard.getIdentification()); - assertTrue(companyCard.identicalCard(anotherCard)); - } - - @Test - void testIdenticalCard_DifferentCardId_ReturnFalse(){ - CompanyCard anotherCard = new CompanyCard("001"); - - assertNotEquals(anotherCard.getIdentification(), companyCard.getIdentification()); - assertFalse(companyCard.identicalCard(anotherCard)); - } - /* * CompanyCard */ @@ -141,126 +89,4 @@ class CompanyCardTest { assertThrows(NullPointerException.class, ()->companyCard.setCompanyName(null)); assertEquals(oldName, companyCard.getCompanyName()); } - - @Test - void testMerge_CompanyCardWithSameId_ReturnPrivateCardWithBothValues(){ - CompanyCard anotherCard = new CompanyCard("companyName"); - - AddressList anotherAddresses = new AddressList(); - PhoneList anotherPhones = new PhoneList(); - MailList anotherMails = new MailList(); - GroupList anotherGroups = new GroupList(); - - CompanyAddress anotherAddress = new CompanyAddress(1, "Another Company Street", new City("France", "Angouleme"), 16000, null,null); - anotherAddresses.add(anotherAddress); - anotherCard.setAddresses(anotherAddresses); - Phone anotherPhone = new Phone(0642424242, ""); - anotherPhones.add(anotherPhone); - anotherCard.setPhones(anotherPhones); - Mail anotherMail = new Mail("anotherHome@mail.com", null); - anotherMails.add(anotherMail); - anotherCard.setMails(anotherMails); - Group anotherGroup = new Group("anotherName", ""); - anotherGroups.add(anotherGroup); - anotherCard.setGroups(anotherGroups); - - CompanyCard mergedCard = (CompanyCard) companyCard.merge(anotherCard); - - assertTrue(mergedCard.getAddresses().find(anAddress)); - assertTrue(mergedCard.getAddresses().find(anotherAddress)); - assertEquals(2,mergedCard.getAddresses().get().size()); - - assertTrue(mergedCard.getPhones().find(aPhone)); - assertTrue(mergedCard.getPhones().find(anotherPhone)); - assertEquals(2,mergedCard.getPhones().get().size()); - - assertTrue(mergedCard.getMails().find(aMail)); - assertTrue(mergedCard.getMails().find(anotherMail)); - assertEquals(2,mergedCard.getMails().get().size()); - - assertTrue(mergedCard.getGroups().find(aGroup)); - assertTrue(mergedCard.getGroups().find(anotherGroup)); - assertEquals(2,mergedCard.getGroups().get().size()); - - assertEquals(companyCard.getIdentification(),mergedCard.getIdentification()); - } - - @Test - void testMerge_SameCompanyCard_NoChange(){ - CompanyCard mergedCard = (CompanyCard) companyCard.merge(companyCard); - - assertTrue(mergedCard.getAddresses().find(anAddress)); - assertEquals(1,mergedCard.getAddresses().get().size()); - - assertTrue(mergedCard.getPhones().find(aPhone)); - assertEquals(1,mergedCard.getPhones().get().size()); - - assertTrue(mergedCard.getMails().find(aMail)); - assertEquals(1,mergedCard.getMails().get().size()); - - assertTrue(mergedCard.getGroups().find(aGroup)); - assertEquals(1,mergedCard.getGroups().get().size()); - } - - @Test - void testMerge_CompanyCardsWithSharedValues_NoDuplicate(){ - CompanyCard anotherCard = new CompanyCard("companyName"); - - AddressList anotherAddresses = new AddressList(); - PhoneList anotherPhones = new PhoneList(); - MailList anotherMails = new MailList(); - GroupList anotherGroups = new GroupList(); - CompanyAddress anotherAddress = new CompanyAddress(1, "Another Private Street", new City("France", "Angouleme"), 16000, null,null); - Phone anotherPhone = new Phone(0642424242, ""); - Mail anotherMail = new Mail("anotherHome@mail.com", null); - Group anotherGroup = new Group("anotherName", ""); - - anotherAddresses.add(anotherAddress); - anotherPhones.add(anotherPhone); - anotherMails.add(anotherMail); - anotherGroups.add(anotherGroup); - - anotherCard.setAddresses(someAddresses); - anotherCard.setPhones(somePhones); - anotherCard.setMails(someMails); - anotherCard.setGroups(someGroups); - anotherCard.setAddresses(anotherAddresses); - anotherCard.setPhones(anotherPhones); - anotherCard.setMails(anotherMails); - anotherCard.setGroups(anotherGroups); - - CompanyCard mergedCard = (CompanyCard) companyCard.merge(anotherCard); - - assertTrue(mergedCard.getAddresses().find(anAddress)); - assertTrue(mergedCard.getAddresses().find(anotherAddress)); - assertEquals(2,mergedCard.getAddresses().get().size()); - - assertTrue(mergedCard.getPhones().find(aPhone)); - assertTrue(mergedCard.getPhones().find(anotherPhone)); - assertEquals(2,mergedCard.getPhones().get().size()); - - assertTrue(mergedCard.getMails().find(aMail)); - assertTrue(mergedCard.getMails().find(anotherMail)); - assertEquals(2,mergedCard.getMails().get().size()); - - assertTrue(mergedCard.getGroups().find(aGroup)); - assertTrue(mergedCard.getGroups().find(anotherGroup)); - assertEquals(2,mergedCard.getGroups().get().size()); - } - - @Test - void testMergeCompanyCard_AnyCompanyCard_ReturnNull(){ - assertNull(companyCard.mergePrivateCard(new PrivateCard(null))); - } - - @Test - void testMergeCompanyCard_SomeCompanyCard_KeepCurrentAttributes(){ - CompanyCard anotherCard = new CompanyCard("companyName"); - companyCard.setCompanyName("JohnDoe Inc."); - anotherCard.setCompanyName("TomJoe Corp."); - - CompanyCard mergedCard = companyCard.mergeCompanyCard(anotherCard); - - assertEquals(companyCard.getCompanyName(),mergedCard.getCompanyName()); - } } \ No newline at end of file diff --git a/src/main/test/fr/unantes/software/construction/address/PrivateCardTest.java b/src/main/test/fr/unantes/software/construction/address/PrivateCardTest.java index 2233af30..11206a2c 100644 --- a/src/main/test/fr/unantes/software/construction/address/PrivateCardTest.java +++ b/src/main/test/fr/unantes/software/construction/address/PrivateCardTest.java @@ -1,5 +1,6 @@ package fr.unantes.software.construction.address; +import fr.unantes.software.construction.PrivateClient; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -7,34 +8,12 @@ import static org.junit.jupiter.api.Assertions.*; class PrivateCardTest { - PrivateCard someCard; - AddressList someAddresses; PrivateAddress anAddress; - PhoneList somePhones; Phone aPhone; - MailList someMails; Mail aMail; - GroupList someGroups; Group aGroup; - + private PrivateCard someCard; @BeforeEach - void setUp() { - someCard = new PrivateCard("000"); - - someAddresses = new AddressList(); - somePhones = new PhoneList(); - someMails = new MailList(); - someGroups = new GroupList(); - - anAddress = new PrivateAddress(1, "Some Private Street", new City("Groenland", "Qeqertarsuaq"), 0, null); - someAddresses.add(anAddress); - someCard.setAddresses(someAddresses); - aPhone = new Phone(0202020202, ""); - somePhones.add(aPhone); - someCard.setPhones(somePhones); - aMail = new Mail("someHome@mail.com", null); - someMails.add(aMail); - someCard.setMails(someMails); - aGroup = new Group("someName", ""); - someGroups.add(aGroup); - someCard.setGroups(someGroups); + void setUp(){ + PrivateClient someClient = new PrivateClient("John", "Doe"); + someCard = new PrivateCard(someClient); } /* @@ -96,181 +75,13 @@ class PrivateCardTest { assertNotEquals(null, someCard.getGroups()); } - @Test - void testSetIdentification_AnyStringValue_Succeed(){ - someCard.setIdentification("id002"); - - assertEquals("id002",someCard.getIdentification()); - - } - - @Test - void testSetIdentification_NullValue_ExceptionThrown(){ - assertThrows(NullPointerException.class, ()-> someCard.setIdentification(null)); - assertNotEquals(null, someCard.getIdentification()); - } - - @Test - void testIdenticalCard_SameCardId_ReturnTrue(){ - PrivateCard anotherCard = new PrivateCard("000"); - - assertEquals(anotherCard.getIdentification(),someCard.getIdentification()); - assertTrue(someCard.identicalCard(anotherCard)); - } - @Test void testIdenticalCard_DifferentCardId_ReturnFalse(){ - PrivateCard anotherCard = new PrivateCard("001"); + PrivateClient anotherClient = new PrivateClient("Mary","Sue"); + PrivateCard anotherCard = new PrivateCard(anotherClient); assertNotEquals(anotherCard.getIdentification(),someCard.getIdentification()); assertFalse(someCard.identicalCard(anotherCard)); } - /* - * PrivateCard - */ - @Test - void testSetLastName_AnyStringValue_Succeed(){ - someCard.setLastName("someone"); - assertEquals("someone",someCard.getLastName()); - - someCard.setLastName(null); - assertNull(someCard.getLastName()); - } - - - @Test - void testSetFirstName_AnyStringValue_Succeed(){ - someCard.setFirstName("someone"); - assertEquals("someone",someCard.getFirstName()); - - someCard.setFirstName(null); - assertNull(someCard.getFirstName()); - } - - @Test - void testMerge_PrivateCardWithSameId_ReturnPrivateCardWithBothValues(){ - PrivateCard anotherCard = new PrivateCard("000"); - - AddressList anotherAddresses = new AddressList(); - PhoneList anotherPhones = new PhoneList(); - MailList anotherMails = new MailList(); - GroupList anotherGroups = new GroupList(); - - PrivateAddress anotherAddress = new PrivateAddress(1, "Another Private Street", new City("France", "Angouleme"), 16000, null); - anotherAddresses.add(anotherAddress); - anotherCard.setAddresses(anotherAddresses); - Phone anotherPhone = new Phone(0642424242, ""); - anotherPhones.add(anotherPhone); - anotherCard.setPhones(anotherPhones); - Mail anotherMail = new Mail("anotherHome@mail.com", null); - anotherMails.add(anotherMail); - anotherCard.setMails(anotherMails); - Group anotherGroup = new Group("anotherName", ""); - anotherGroups.add(anotherGroup); - anotherCard.setGroups(anotherGroups); - - PrivateCard mergedCard = (PrivateCard) someCard.merge(anotherCard); - - assertTrue(mergedCard.getAddresses().find(anAddress)); - assertTrue(mergedCard.getAddresses().find(anotherAddress)); - assertEquals(2,mergedCard.getAddresses().get().size()); - - assertTrue(mergedCard.getPhones().find(aPhone)); - assertTrue(mergedCard.getPhones().find(anotherPhone)); - assertEquals(2,mergedCard.getPhones().get().size()); - - assertTrue(mergedCard.getMails().find(aMail)); - assertTrue(mergedCard.getMails().find(anotherMail)); - assertEquals(2,mergedCard.getMails().get().size()); - - assertTrue(mergedCard.getGroups().find(aGroup)); - assertTrue(mergedCard.getGroups().find(anotherGroup)); - assertEquals(2,mergedCard.getGroups().get().size()); - - assertEquals(someCard.getIdentification(),mergedCard.getIdentification()); - } - - @Test - void testMerge_SamePrivateCard_NoChange(){ - PrivateCard mergedCard = (PrivateCard) someCard.merge(someCard); - - assertTrue(mergedCard.getAddresses().find(anAddress)); - assertEquals(1,mergedCard.getAddresses().get().size()); - - assertTrue(mergedCard.getPhones().find(aPhone)); - assertEquals(1,mergedCard.getPhones().get().size()); - - assertTrue(mergedCard.getMails().find(aMail)); - assertEquals(1,mergedCard.getMails().get().size()); - - assertTrue(mergedCard.getGroups().find(aGroup)); - assertEquals(1,mergedCard.getGroups().get().size()); - } - - @Test - void testMerge_PrivateCardsWithSharedValues_NoDuplicate(){ - PrivateCard anotherCard = new PrivateCard("000"); - - AddressList anotherAddresses = new AddressList(); - PhoneList anotherPhones = new PhoneList(); - MailList anotherMails = new MailList(); - GroupList anotherGroups = new GroupList(); - PrivateAddress anotherAddress = new PrivateAddress(1, "Another Private Street", new City("France", "Angouleme"), 16000, null); - Phone anotherPhone = new Phone(0642424242, ""); - Mail anotherMail = new Mail("anotherHome@mail.com", null); - Group anotherGroup = new Group("anotherName", ""); - - anotherAddresses.add(anotherAddress); - anotherPhones.add(anotherPhone); - anotherMails.add(anotherMail); - anotherGroups.add(anotherGroup); - - anotherCard.setAddresses(someAddresses); - anotherCard.setPhones(somePhones); - anotherCard.setMails(someMails); - anotherCard.setGroups(someGroups); - anotherCard.setAddresses(anotherAddresses); - anotherCard.setPhones(anotherPhones); - anotherCard.setMails(anotherMails); - anotherCard.setGroups(anotherGroups); - - PrivateCard mergedCard = (PrivateCard) someCard.merge(anotherCard); - - assertTrue(mergedCard.getAddresses().find(anAddress)); - assertTrue(mergedCard.getAddresses().find(anotherAddress)); - assertEquals(2,mergedCard.getAddresses().get().size()); - - assertTrue(mergedCard.getPhones().find(aPhone)); - assertTrue(mergedCard.getPhones().find(anotherPhone)); - assertEquals(2,mergedCard.getPhones().get().size()); - - assertTrue(mergedCard.getMails().find(aMail)); - assertTrue(mergedCard.getMails().find(anotherMail)); - assertEquals(2,mergedCard.getMails().get().size()); - - assertTrue(mergedCard.getGroups().find(aGroup)); - assertTrue(mergedCard.getGroups().find(anotherGroup)); - assertEquals(2,mergedCard.getGroups().get().size()); - } - - @Test - void testMergeCompanyCard_AnyCompanyCard_ExceptionThrown(){ - assertThrows(NullPointerException.class, ()-> someCard.mergeCompanyCard(new CompanyCard(null))); - } - - @Test - void testMergePrivateCard_SomePrivateCard_KeepCurrentAttributes(){ - PrivateCard anotherCard = new PrivateCard("000"); - someCard.setFirstName("John"); - someCard.setLastName("Doe"); - - anotherCard.setFirstName("Tom"); - anotherCard.setLastName("Joe"); - - PrivateCard mergedCard = someCard.mergePrivateCard(anotherCard); - - assertEquals(someCard.getFirstName(),mergedCard.getFirstName()); - assertEquals(someCard.getLastName(),mergedCard.getLastName()); - } } \ No newline at end of file -- GitLab From cfb3bffcf8cb9e6985d7219588de4e47601464d3 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Wed, 25 Mar 2020 13:28:26 +0100 Subject: [PATCH 078/120] Modified classes impacted by Card new behavior --- .../construction/address/CardList.java | 3 ++- .../construction/address/CardListTest.java | 19 +++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/address/CardList.java b/src/main/java/fr/unantes/software/construction/address/CardList.java index ac0015bf..bbae6d9b 100755 --- a/src/main/java/fr/unantes/software/construction/address/CardList.java +++ b/src/main/java/fr/unantes/software/construction/address/CardList.java @@ -82,7 +82,7 @@ public class CardList { for (Enumeration e1 = cards.get().elements(); e1.hasMoreElements() ;) { nextCard1 = (Card)e1.nextElement(); if((nextCard).identicalCard(nextCard1)){ - res.add((nextCard).merge(nextCard1)); + res.add(nextCard); r = true; } else{ @@ -94,6 +94,7 @@ public class CardList { return res; } + public String toXML(){ String res = ""; Enumeration e = cards.elements(); diff --git a/src/main/test/fr/unantes/software/construction/address/CardListTest.java b/src/main/test/fr/unantes/software/construction/address/CardListTest.java index e2e0fbea..b147dc89 100644 --- a/src/main/test/fr/unantes/software/construction/address/CardListTest.java +++ b/src/main/test/fr/unantes/software/construction/address/CardListTest.java @@ -1,27 +1,30 @@ package fr.unantes.software.construction.address; +import fr.unantes.software.construction.CompanyClient; +import fr.unantes.software.construction.PrivateClient; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; - import java.util.Vector; import static org.junit.jupiter.api.Assertions.*; -class CardListTest { +class CardListTest {; + PrivateClient someClient; CardList cardList; Card someCard; @BeforeEach void setUp() { + someClient = new PrivateClient("John","Doe"); cardList = new CardList(); - someCard = new PrivateCard("John","Doe"); + someCard = new PrivateCard(someClient); } @Test void testSet_ListOfCards_addCardsToCurrentList(){ Vector anotherList = new Vector(); Card[] cards = { someCard, - new PrivateCard("Tom","Joe"), - new CompanyCard("JohnDoe Corp.") + new PrivateCard(new PrivateClient("Tom", "Jones")), + new CompanyCard(new CompanyClient("JohnDoe Corp.")) }; for(Card each : cards){ @@ -92,7 +95,7 @@ class CardListTest { @Test public void testFind_NotContainedValue_ReturnFalse(){ - cardList.add(new PrivateCard("Tom","Joe")); + cardList.add(new PrivateCard(new PrivateClient("Tom","Jones"))); assertFalse(cardList.find(someCard)); } @@ -100,7 +103,7 @@ class CardListTest { public void testMerge_TwoDifferentLists_ReturnListWithBothValue(){ cardList.add(someCard); - Card anotherCard = new PrivateCard("Tom", "Joe"); + Card anotherCard = new PrivateCard(new PrivateClient("Tom","Jones")); CardList anotherList = new CardList(); anotherList.add(anotherCard); @@ -125,7 +128,7 @@ class CardListTest { @Test public void testMerge_ListsWithSharedValues_NoDuplicate(){ - Card anotherCard = new PrivateCard("Tom", "Joe"); + Card anotherCard = new PrivateCard(new PrivateClient("Tom","Jones")); cardList.add(someCard); cardList.add(anotherCard); -- GitLab From ea40edfbfa2b1cd8161510573af1e178eae2a536 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Wed, 25 Mar 2020 13:29:36 +0100 Subject: [PATCH 079/120] Implemented subclasses to handle Client differents roles --- .../unantes/software/construction/Client.java | 89 ++++++------------- .../software/construction/CompanyClient.java | 21 +++++ .../software/construction/PrivateClient.java | 43 +++++++++ .../software/construction/ClientTest.java | 6 +- 4 files changed, 93 insertions(+), 66 deletions(-) create mode 100644 src/main/java/fr/unantes/software/construction/CompanyClient.java create mode 100644 src/main/java/fr/unantes/software/construction/PrivateClient.java diff --git a/src/main/java/fr/unantes/software/construction/Client.java b/src/main/java/fr/unantes/software/construction/Client.java index dbe52747..890849b1 100644 --- a/src/main/java/fr/unantes/software/construction/Client.java +++ b/src/main/java/fr/unantes/software/construction/Client.java @@ -4,52 +4,28 @@ import fr.unantes.software.construction.address.Address; import fr.unantes.software.construction.address.Card; import fr.unantes.software.construction.references.MultipleReference; import fr.unantes.software.construction.references.SingleReference; -import java.io.InvalidClassException; +import java.util.UUID; -public class Client { - - private String name; - private String role; +public abstract class Client { + private final UUID identification = UUID.randomUUID(); private final MultipleReference accounts = new MultipleReference(this) { @Override public MultipleReference oppositeFor(Account target) { return target.getOwner(); } }; - private short accountSize = 0; - private Card card; + private SingleReference card = new SingleReference(this) { + @Override + public SingleReference oppositeFor(Card target) { + return target.getOwner(); + } + }; private SingleReference refAddress = new SingleReference(this) { @Override public SingleReference oppositeFor(Address target) { return target.getRefClient(); } }; - /* - public OneToOneAssociation refAddress = new OneToOneAssociation<>(this); - - // Inner class to describe Bidirectional Monovalued Association between Address & Client - - public class OneToOneAssociation extends - SingleReference { - - public OneToOneAssociation(Client a) { - super(a); - } - - @Override - public SingleReference oppositeFor(Object target) { - return refAddress; - } - } - */ - - public Client(String name, String role) throws InvalidClassException { - if (!role.equals("private") && !role.equals("company")) { - throw new InvalidClassException("Invalid role supplied. A person can only be private or company"); - } - this.name = name; - this.role = role; - } public Address getAddress(){ return refAddress.get(); @@ -59,33 +35,18 @@ public class Client { return refAddress; } - public void setAddress(Address add){ - this.refAddress.set(add); - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; + public SingleReference getCard(){ + return card; } - public String getRole() { - return role; + public void setAddress(Address add){ + this.refAddress.set(add); } - public void setRole(String role) throws InvalidClassException { - if (!role.equals("private") && !role.equals("company")) { - throw new InvalidClassException("Invalid role supplied. A person can only be private or company"); - } - this.role = role; + public UUID getIdentification() { + return identification; } - /** - * - * @uml.property name="accounts" - */ public MultipleReference getAccounts() { return accounts; } @@ -119,7 +80,7 @@ public class Client { * @uml.property name="accounts" */ public boolean isAccountsEmpty() { - return accounts.size() == 0; + return accounts.get().isEmpty(); } /** @@ -127,7 +88,9 @@ public class Client { * @uml.property name="accounts" */ public void clearAccounts() { - accountSize = 0; + for(Account a : accounts.get()){ + accounts.remove(a); + } } /** @@ -138,27 +101,27 @@ public class Client { return accounts.contains(element); } - /** * * @uml.property name="accounts" */ public int accountsSize() { - return accounts.size(); + return accounts.get().size(); } + public abstract String getName(); + public abstract String getRole(); + public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Client person = (Client) o; - if (getRole().equals(person.getRole()) && role.equals("agent")) { - return getName().equals(person.getName()) && card == person.card; - } - return getName().equals(person.getName()) && getRole().equals(person.getRole()); + + return getIdentification().equals(person.getIdentification()) && card == person.card; } public int hashCode() { - return getName().hashCode() + getRole().hashCode() + card.hashCode(); + return getIdentification().hashCode() + getRole().hashCode() + card.hashCode(); } } diff --git a/src/main/java/fr/unantes/software/construction/CompanyClient.java b/src/main/java/fr/unantes/software/construction/CompanyClient.java new file mode 100644 index 00000000..4c0c95c4 --- /dev/null +++ b/src/main/java/fr/unantes/software/construction/CompanyClient.java @@ -0,0 +1,21 @@ +package fr.unantes.software.construction; + + +public class CompanyClient extends Client { + private String name; + + public CompanyClient(String name){ + super(); + this.name = name; + } + + @Override + public String getName() { + return name; + } + + @Override + public String getRole() { + return "company"; + } +} diff --git a/src/main/java/fr/unantes/software/construction/PrivateClient.java b/src/main/java/fr/unantes/software/construction/PrivateClient.java new file mode 100644 index 00000000..c5cbb1b5 --- /dev/null +++ b/src/main/java/fr/unantes/software/construction/PrivateClient.java @@ -0,0 +1,43 @@ +package fr.unantes.software.construction; + +import java.io.InvalidClassException; + +public class PrivateClient extends Client{ + private String firstName; + private String lastName; + + public PrivateClient(String lastName){ + super(); + this.lastName = lastName; + } + + public PrivateClient(String firstName, String lastName){ + super(); + this.lastName = lastName; + setFirstName(firstName); + } + + public String getFirstName(){ + return firstName; + } + public String getLastName(){ + return lastName; + } + + public void setFirstName(String value){ + this.firstName = value; + } + public void setLastName(String value){ + this.lastName = value; + } + + @Override + public String getName(){ + return lastName; + } + + @Override + public String getRole() { + return "private"; + } +} diff --git a/src/main/test/fr/unantes/software/construction/ClientTest.java b/src/main/test/fr/unantes/software/construction/ClientTest.java index 488a7502..8aedda9e 100644 --- a/src/main/test/fr/unantes/software/construction/ClientTest.java +++ b/src/main/test/fr/unantes/software/construction/ClientTest.java @@ -11,12 +11,12 @@ class ClientTest { Client client; @BeforeEach - void setUp() throws InvalidClassException { - client = new Client("Tom","private"); + void setUp(){ + client = new PrivateClient("John","Doe"); } @Test void testCompleteHandshakeWith_Account() throws InvalidClassException { - Client client2 = new Client("Jerry","private"); + Client client2 = new PrivateClient("Jerry","Lechat"); Account[] accounts = {new Account(client,50, 0,"private"), new Account(client,200, 0,"private"), -- GitLab From 35dd5987ddafed2a1b8868f2e4895ebb3876e293 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Wed, 25 Mar 2020 13:31:50 +0100 Subject: [PATCH 080/120] Fixed classes impacted by Client new behavior --- .../unantes/software/construction/Bank.java | 7 +++++-- .../software/construction/AccountTest.java | 20 +++++++++---------- .../software/construction/BankTest.java | 12 ++++------- .../construction/DepositOperationTest.java | 7 ++----- .../construction/WithdrawOperationTest.java | 5 ++--- .../construction/address/AddressBookTest.java | 13 +++++++++--- .../address/CompanyAddressTest.java | 10 ++++------ .../address/PrivateAddressTest.java | 10 ++++------ 8 files changed, 41 insertions(+), 43 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/Bank.java b/src/main/java/fr/unantes/software/construction/Bank.java index 8eaa390d..34405079 100755 --- a/src/main/java/fr/unantes/software/construction/Bank.java +++ b/src/main/java/fr/unantes/software/construction/Bank.java @@ -151,7 +151,10 @@ public class Bank { try { if (pending == null) { - pending = new Client(name, type); + if(type.equals("private")) + pending = new PrivateClient(name); + else + pending = new CompanyClient(name); this.addClients(pending); } Account acc = new Account(pending, amount, overdraft, type); @@ -207,7 +210,7 @@ public class Bank { public Account getAccount(int accountNumber) { Iterator it = this.accountsIterator(); while (it.hasNext()){ - Account a = (Account)it.next(); + Account a = it.next(); if(a.getId()==accountNumber) { return a; } diff --git a/src/main/test/fr/unantes/software/construction/AccountTest.java b/src/main/test/fr/unantes/software/construction/AccountTest.java index 04856152..ef0943b8 100644 --- a/src/main/test/fr/unantes/software/construction/AccountTest.java +++ b/src/main/test/fr/unantes/software/construction/AccountTest.java @@ -13,13 +13,13 @@ class AccountTest { @BeforeEach void setUp() throws InvalidClassException { - account = new Account(new Client("John","private"),100,0,"private"); - accOverdraft = new Account(new Client("Meg","private"),-100,-150,"private"); + account = new Account(new PrivateClient("John","Doe"),100,0,"private"); + accOverdraft = new Account(new PrivateClient("Maggie","Prime"),-100,-150,"private"); } @Test void testCompleteHandshakeWith_Operation() throws InvalidClassException { - Account acc2 = new Account(new Client("Marco","private"),100,0,"private"); + Account acc2 = new Account(new PrivateClient("Marco","Polo"),100,0,"private"); Operation[] deposits = {new DepositOperation(50, LocalDateTime.now()), new DepositOperation(25, LocalDateTime.now()), @@ -98,7 +98,7 @@ class AccountTest { } @Test - void testWithdraw_belowOverdraft_Refused() throws Exception { + void testWithdraw_belowOverdraft_Refused(){ float oldBalance = accOverdraft.getBalance(); assertThrows(Exception.class, () -> accOverdraft.withdraw(50.25f)); assertFalse(accOverdraft.getBalance() account.withdraw(-50.25f)); assertFalse(account.getBalance()>oldBalance); @@ -160,9 +160,9 @@ class AccountTest { } @Test - void setOwner() throws InvalidClassException { + void setOwner(){ Client oldClient = account.getOwner().get(0); - Client newClient = new Client("Timmy", "private"); + Client newClient = new PrivateClient("Phillippe", "Chappuis"); assertFalse(account.getOwner().contains(newClient)); assertTrue(account.getOwner().contains(oldClient)); @@ -174,9 +174,9 @@ class AccountTest { } @Test - void completeHandshakeWith_Client() throws InvalidClassException { - Client client1 = new Client("Boule","private"); - Client client2 = new Client("Bill","private"); + void completeHandshakeWith_Client(){ + Client client1 = new PrivateClient("Maurice","Rosy"); + Client client2 = new PrivateClient("Robert","Velter"); client1.addAccounts(account); client2.addAccounts(account); diff --git a/src/main/test/fr/unantes/software/construction/BankTest.java b/src/main/test/fr/unantes/software/construction/BankTest.java index f7bfdeb8..67f1a3ea 100644 --- a/src/main/test/fr/unantes/software/construction/BankTest.java +++ b/src/main/test/fr/unantes/software/construction/BankTest.java @@ -1,12 +1,8 @@ package fr.unantes.software.construction; -import java.util.Iterator; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.BeforeEach; - -import java.io.InvalidClassException; - import static org.junit.jupiter.api.Assertions.*; public class BankTest { @@ -15,9 +11,9 @@ public class BankTest { private Client client; @BeforeEach - void setup() throws InvalidClassException{ + void setup(){ bank = new Bank(); - client = new Client("ComLtd","private"); + client = new CompanyClient("ComLtd"); } @Test @@ -31,7 +27,7 @@ public class BankTest { } @Test - void test_addAccount_WhenDoesNotExist() throws InvalidClassException{ + void test_addAccount_WhenDoesNotExist(){ String name = "Martin"; int a = bank.addAccount(name, 15026.33f, 0.0f, "private" ); @@ -41,7 +37,7 @@ public class BankTest { } @Test - void test_addAccount_WhenAlreadyExist() throws InvalidClassException{ + void test_addAccount_WhenAlreadyExist(){ String name = "Martin"; int a = bank.addAccount(name, 15026.33f, 0.0f, "private" ); int b = bank.addAccount(name, 42.00f, 0.0f, "private" ); diff --git a/src/main/test/fr/unantes/software/construction/DepositOperationTest.java b/src/main/test/fr/unantes/software/construction/DepositOperationTest.java index 970a31e5..57ea56f8 100644 --- a/src/main/test/fr/unantes/software/construction/DepositOperationTest.java +++ b/src/main/test/fr/unantes/software/construction/DepositOperationTest.java @@ -2,11 +2,8 @@ package fr.unantes.software.construction; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; - import java.io.InvalidClassException; import java.time.LocalDateTime; - -import static java.time.LocalDateTime.now; import static org.junit.jupiter.api.Assertions.*; class DepositOperationTest { @@ -16,13 +13,13 @@ class DepositOperationTest { @BeforeEach void setUp() throws InvalidClassException { - account = new Account(new Client("John","private"),100,0,"private"); + account = new Account(new PrivateClient("John","Doe"),100,0,"private"); deposit_20 = new DepositOperation(20f, LocalDateTime.now()); } @Test void completeHandshake() throws InvalidClassException { - Account account2 = new Account(new Client("Tom","private"),0,0,"private"); + Account account2 = new Account(new PrivateClient("Marco","Polo"),0,0,"private"); account.addHistory(deposit_20); account2.addHistory(deposit_20); diff --git a/src/main/test/fr/unantes/software/construction/WithdrawOperationTest.java b/src/main/test/fr/unantes/software/construction/WithdrawOperationTest.java index bef25e0b..36dc76b1 100644 --- a/src/main/test/fr/unantes/software/construction/WithdrawOperationTest.java +++ b/src/main/test/fr/unantes/software/construction/WithdrawOperationTest.java @@ -2,7 +2,6 @@ package fr.unantes.software.construction; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; - import java.io.InvalidClassException; import java.time.LocalDateTime; @@ -15,13 +14,13 @@ class WithdrawOperationTest { @BeforeEach void setUp() throws InvalidClassException { - account = new Account(new Client("John","private"),100,0,"private"); + account = new Account(new PrivateClient("John","Doe"),100,0,"private"); withdraw_20 = new WithdrawOperation(20f, LocalDateTime.now()); } @Test void completeHandshake() throws InvalidClassException { - Account account2 = new Account(new Client("Tom","private"),0,0,"private"); + Account account2 = new Account(new PrivateClient("Tom","Joe"),0,0,"private"); account.addHistory(withdraw_20); account2.addHistory(withdraw_20); diff --git a/src/main/test/fr/unantes/software/construction/address/AddressBookTest.java b/src/main/test/fr/unantes/software/construction/address/AddressBookTest.java index 3f84064f..a5403afc 100644 --- a/src/main/test/fr/unantes/software/construction/address/AddressBookTest.java +++ b/src/main/test/fr/unantes/software/construction/address/AddressBookTest.java @@ -1,19 +1,24 @@ package fr.unantes.software.construction.address; +import fr.unantes.software.construction.PrivateClient; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; + import static org.junit.jupiter.api.Assertions.*; class AddressBookTest { + PrivateClient someClient; CardList someList; Card someCard; AddressBook addressBook; @BeforeEach void setUp(){ + someClient = new PrivateClient("Felix","Salten"); someList = new CardList(); - someCard = new PrivateCard("Chaussette","Louis"); + + someCard = new PrivateCard(someClient); someList.add(someCard); addressBook = new AddressBook(); } @@ -43,7 +48,8 @@ class AddressBookTest { AddressBook anotherBook = new AddressBook(); CardList anotherList = new CardList(); - Card anotherCard = new PrivateCard("Marco","Polo"); + PrivateClient anotherClient = new PrivateClient("Marco","Polo"); + Card anotherCard = new PrivateCard(anotherClient); anotherList.add(anotherCard); anotherBook.setCards(anotherList); @@ -72,7 +78,8 @@ class AddressBookTest { AddressBook anotherBook = new AddressBook(); CardList anotherList = new CardList(); - Card anotherCard = new PrivateCard("Marco","Polo"); + PrivateClient anotherClient = new PrivateClient("Marco","Polo"); + Card anotherCard = new PrivateCard(anotherClient); anotherList.add(someCard); anotherList.add(anotherCard); diff --git a/src/main/test/fr/unantes/software/construction/address/CompanyAddressTest.java b/src/main/test/fr/unantes/software/construction/address/CompanyAddressTest.java index 5963ae1e..7c9e2852 100644 --- a/src/main/test/fr/unantes/software/construction/address/CompanyAddressTest.java +++ b/src/main/test/fr/unantes/software/construction/address/CompanyAddressTest.java @@ -1,11 +1,9 @@ package fr.unantes.software.construction.address; -import fr.unantes.software.construction.Client; +import fr.unantes.software.construction.CompanyClient; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.io.InvalidClassException; - import static org.junit.jupiter.api.Assertions.*; class CompanyAddressTest { @@ -19,11 +17,11 @@ class CompanyAddressTest { * Related to superclass Address */ @Test - void test_CompleteHandshakeWith_Client() throws InvalidClassException { + void test_CompleteHandshakeWith_Client(){ CompanyAddress anotherCompanyAddress = new CompanyAddress(2,"boulevard de l'Industrie",new City("France", "Anger"),49000,null,null); - Client client1 = new Client("Blender Foundation", "company"); - Client client2 = new Client("Scania","company"); + CompanyClient client1 = new CompanyClient("Blender Foundation"); + CompanyClient client2 = new CompanyClient("Scania"); companyAddress.getRefClient().set(client1); diff --git a/src/main/test/fr/unantes/software/construction/address/PrivateAddressTest.java b/src/main/test/fr/unantes/software/construction/address/PrivateAddressTest.java index d3da61ab..d8a18f35 100644 --- a/src/main/test/fr/unantes/software/construction/address/PrivateAddressTest.java +++ b/src/main/test/fr/unantes/software/construction/address/PrivateAddressTest.java @@ -1,11 +1,9 @@ package fr.unantes.software.construction.address; -import fr.unantes.software.construction.Client; +import fr.unantes.software.construction.PrivateClient; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.io.InvalidClassException; - import static org.junit.jupiter.api.Assertions.*; class PrivateAddressTest { @@ -21,11 +19,11 @@ class PrivateAddressTest { */ @Test - void test_CompleteHandshakeWith_Client() throws InvalidClassException { + void test_CompleteHandshakeWith_Client(){ PrivateAddress anotherPersonalAddress = new PrivateAddress(742,"Evergreen Terrasse",new City("United-States", "Springfield"),0,null); - Client client1 = new Client("Tom", "private"); - Client client2 = new Client("Jerry","private"); + PrivateClient client1 = new PrivateClient(" Gerry", "Chiniquy"); + PrivateClient client2 = new PrivateClient("Robert","Clampett"); privateAddress.getRefClient().set(client1); -- GitLab From c1c15c629ebdc0d07c4f4212888cc2b9a06ef3ac Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Wed, 25 Mar 2020 15:54:02 +0100 Subject: [PATCH 081/120] Modified Account class according to Client new behavior --- .../fr/unantes/software/construction/Account.java | 11 +---------- .../fr/unantes/software/construction/AccountTest.java | 11 +++++------ 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/Account.java b/src/main/java/fr/unantes/software/construction/Account.java index e0e507bd..82f7712c 100755 --- a/src/main/java/fr/unantes/software/construction/Account.java +++ b/src/main/java/fr/unantes/software/construction/Account.java @@ -5,13 +5,11 @@ import fr.unantes.software.construction.references.MultipleReference; import fr.unantes.software.construction.references.OneToManyReference; import org.apache.commons.lang3.Validate; -import java.io.InvalidClassException; import java.time.LocalDateTime; import java.util.UUID; public class Account { private final Integer id = UUID.randomUUID().variant(); - public String type; private float balance; private float overdraft; public final MultipleReference owner = new MultipleReference(this) { @@ -31,14 +29,10 @@ public class Account { * Initializes the owner, amount, overdraft and the account id with parameters * The method also initializes the history with a new empty Vector */ - public Account(Client p, float amount, float overdraft, String type) throws InvalidClassException { + public Account(Client p, float amount, float overdraft){ owner.add(p); this.balance = amount; this.overdraft = overdraft; - this.type = type; - if (!type.equals("private") && !type.equals("company")) { - throw new InvalidClassException("Invalid type supplied. An account can only be private or company"); - } } /** @@ -141,8 +135,6 @@ public class Account { * */ public void setOwner(Client owner) { - if (owner.getRole().equals("private") && !this.type.equals("private")) return; - if (owner.getRole().equals("company") && !this.type.equals("company")) return; getOwner().add(owner); } @@ -158,7 +150,6 @@ public class Account { public Operation[] historyToArray() { return getHistory().get().toArray(new Operation[getHistory().get().size()]); - //return (Operation[]) history.getHistory().toArray(new Operation[history.getHistory().size()]); } } diff --git a/src/main/test/fr/unantes/software/construction/AccountTest.java b/src/main/test/fr/unantes/software/construction/AccountTest.java index ef0943b8..925397f0 100644 --- a/src/main/test/fr/unantes/software/construction/AccountTest.java +++ b/src/main/test/fr/unantes/software/construction/AccountTest.java @@ -2,7 +2,6 @@ package fr.unantes.software.construction; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.io.InvalidClassException; import java.time.LocalDateTime; import static org.junit.jupiter.api.Assertions.*; @@ -12,14 +11,14 @@ class AccountTest { private Account account, accOverdraft; @BeforeEach - void setUp() throws InvalidClassException { - account = new Account(new PrivateClient("John","Doe"),100,0,"private"); - accOverdraft = new Account(new PrivateClient("Maggie","Prime"),-100,-150,"private"); + void setUp(){ + account = new Account(new PrivateClient("John","Doe"),100,0); + accOverdraft = new Account(new PrivateClient("Maggie","Prime"),-100,-150); } @Test - void testCompleteHandshakeWith_Operation() throws InvalidClassException { - Account acc2 = new Account(new PrivateClient("Marco","Polo"),100,0,"private"); + void testCompleteHandshakeWith_Operation(){ + Account acc2 = new Account(new PrivateClient("Marco","Polo"),100,0); Operation[] deposits = {new DepositOperation(50, LocalDateTime.now()), new DepositOperation(25, LocalDateTime.now()), -- GitLab From 2cd2048fc59bc8a4a00b050feda92d94f9de7636 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Wed, 25 Mar 2020 15:54:36 +0100 Subject: [PATCH 082/120] Modified classes impacted by Account changes --- .../unantes/software/construction/Bank.java | 22 ++++++++----------- .../software/construction/ClientTest.java | 16 +++++++------- .../construction/DepositOperationTest.java | 9 ++++---- .../construction/WithdrawOperationTest.java | 9 ++++---- 4 files changed, 25 insertions(+), 31 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/Bank.java b/src/main/java/fr/unantes/software/construction/Bank.java index 34405079..e3323b20 100755 --- a/src/main/java/fr/unantes/software/construction/Bank.java +++ b/src/main/java/fr/unantes/software/construction/Bank.java @@ -149,20 +149,16 @@ public class Bank { Validate.notNull(type); Client pending = getClient(name); - try { - if (pending == null) { - if(type.equals("private")) - pending = new PrivateClient(name); - else - pending = new CompanyClient(name); - this.addClients(pending); - } - Account acc = new Account(pending, amount, overdraft, type); - this.addAccounts(acc); - pending.addAccounts(acc); - } catch (InvalidClassException e) { - e.printStackTrace(); + if (pending == null) { + if(type.equals("private")) + pending = new PrivateClient(name); + else + pending = new CompanyClient(name); + this.addClients(pending); } + Account acc = new Account(pending, amount, overdraft); + this.addAccounts(acc); + pending.addAccounts(acc); return accountNumbers; } diff --git a/src/main/test/fr/unantes/software/construction/ClientTest.java b/src/main/test/fr/unantes/software/construction/ClientTest.java index 8aedda9e..1579ce8d 100644 --- a/src/main/test/fr/unantes/software/construction/ClientTest.java +++ b/src/main/test/fr/unantes/software/construction/ClientTest.java @@ -15,12 +15,12 @@ class ClientTest { client = new PrivateClient("John","Doe"); } @Test - void testCompleteHandshakeWith_Account() throws InvalidClassException { + void testCompleteHandshakeWith_Account(){ Client client2 = new PrivateClient("Jerry","Lechat"); - Account[] accounts = {new Account(client,50, 0,"private"), - new Account(client,200, 0,"private"), - new Account(client,10, 0,"company") + Account[] accounts = {new Account(client,50, 0), + new Account(client,200, 0), + new Account(client,10, 0) }; for(Account each : accounts) { @@ -37,10 +37,10 @@ class ClientTest { } @Test - void testBidirectionalAddWith_Account() throws InvalidClassException { - Account[] accounts = {new Account(client,50, 0,"private"), - new Account(client,200, 0,"private"), - new Account(client,10, 0,"company") + void testBidirectionalAddWith_Account(){ + Account[] accounts = {new Account(client,50, 0), + new Account(client,200, 0), + new Account(client,10, 0) }; for(Account each : accounts) { diff --git a/src/main/test/fr/unantes/software/construction/DepositOperationTest.java b/src/main/test/fr/unantes/software/construction/DepositOperationTest.java index 57ea56f8..977bd362 100644 --- a/src/main/test/fr/unantes/software/construction/DepositOperationTest.java +++ b/src/main/test/fr/unantes/software/construction/DepositOperationTest.java @@ -2,7 +2,6 @@ package fr.unantes.software.construction; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.io.InvalidClassException; import java.time.LocalDateTime; import static org.junit.jupiter.api.Assertions.*; @@ -12,14 +11,14 @@ class DepositOperationTest { private Account account; @BeforeEach - void setUp() throws InvalidClassException { - account = new Account(new PrivateClient("John","Doe"),100,0,"private"); + void setUp(){ + account = new Account(new PrivateClient("John","Doe"),100,0); deposit_20 = new DepositOperation(20f, LocalDateTime.now()); } @Test - void completeHandshake() throws InvalidClassException { - Account account2 = new Account(new PrivateClient("Marco","Polo"),0,0,"private"); + void completeHandshake(){ + Account account2 = new Account(new PrivateClient("Marco","Polo"),0,0); account.addHistory(deposit_20); account2.addHistory(deposit_20); diff --git a/src/main/test/fr/unantes/software/construction/WithdrawOperationTest.java b/src/main/test/fr/unantes/software/construction/WithdrawOperationTest.java index 36dc76b1..38177908 100644 --- a/src/main/test/fr/unantes/software/construction/WithdrawOperationTest.java +++ b/src/main/test/fr/unantes/software/construction/WithdrawOperationTest.java @@ -2,7 +2,6 @@ package fr.unantes.software.construction; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.io.InvalidClassException; import java.time.LocalDateTime; import static org.junit.jupiter.api.Assertions.*; @@ -13,14 +12,14 @@ class WithdrawOperationTest { private Account account; @BeforeEach - void setUp() throws InvalidClassException { - account = new Account(new PrivateClient("John","Doe"),100,0,"private"); + void setUp(){ + account = new Account(new PrivateClient("John","Doe"),100,0); withdraw_20 = new WithdrawOperation(20f, LocalDateTime.now()); } @Test - void completeHandshake() throws InvalidClassException { - Account account2 = new Account(new PrivateClient("Tom","Joe"),0,0,"private"); + void completeHandshake(){ + Account account2 = new Account(new PrivateClient("Tom","Joe"),0,0); account.addHistory(withdraw_20); account2.addHistory(withdraw_20); -- GitLab From ba187b3265067ffd2076021e07c01c7dab85db9f Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Wed, 25 Mar 2020 17:55:40 +0100 Subject: [PATCH 083/120] Updated Client tests and added tests for its subclasses --- .../software/construction/ClientTest.java | 106 +++++++++++++++++- .../construction/CompanyClientTest.java | 56 +++++++++ .../construction/PrivateClientTest.java | 65 +++++++++++ 3 files changed, 221 insertions(+), 6 deletions(-) create mode 100644 src/main/test/fr/unantes/software/construction/CompanyClientTest.java create mode 100644 src/main/test/fr/unantes/software/construction/PrivateClientTest.java diff --git a/src/main/test/fr/unantes/software/construction/ClientTest.java b/src/main/test/fr/unantes/software/construction/ClientTest.java index 1579ce8d..5d9ef7e2 100644 --- a/src/main/test/fr/unantes/software/construction/ClientTest.java +++ b/src/main/test/fr/unantes/software/construction/ClientTest.java @@ -2,8 +2,7 @@ package fr.unantes.software.construction; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; - -import java.io.InvalidClassException; +import org.mockito.internal.matchers.Null; import static org.junit.jupiter.api.Assertions.*; @@ -12,11 +11,11 @@ class ClientTest { @BeforeEach void setUp(){ - client = new PrivateClient("John","Doe"); + client = new PrivateClient("Doe"); } @Test void testCompleteHandshakeWith_Account(){ - Client client2 = new PrivateClient("Jerry","Lechat"); + Client client2 = new PrivateClient("Lechat"); Account[] accounts = {new Account(client,50, 0), new Account(client,200, 0), @@ -28,7 +27,7 @@ class ClientTest { } for(Account each : accounts) { - client2.addAccounts(each); + client2.addAccount(each); } for(Account each : accounts) { @@ -44,7 +43,7 @@ class ClientTest { }; for(Account each : accounts) { - client.addAccounts(each); + client.addAccount(each); } for(Account each : accounts) { @@ -52,4 +51,99 @@ class ClientTest { assertTrue(each.getOwner().contains(client)); } } + + @Test + public void testSetAccounts_ListOfAccounts_addReferenceTo() { + Account[] accounts = { + new Account(null,50, 0), + new Account(null,200, 0), + new Account(null,10, 0) + }; + client.setAccounts(accounts); + + for(Account each : accounts) { + assertTrue(client.getAccounts().contains(each)); + assertTrue(each.getOwner().contains(client)); + } + } + + @Test + public void testAddAccount_AlreadyExistingAccount_NoDuplicate() { + Account account = new Account(null,50,0); + client.addAccount(account); + client.addAccount(account); + + assertTrue(client.getAccounts().contains(account)); + assertEquals(1,client.getAccounts().size()); + } + + @Test + void testAddAccount_NullAccount_ExceptionThrown(){ + assertThrows(NullPointerException.class, () -> client.addAccount(null)); + } + @Test + public void testRemoveAccount_ExistingAccount_BidirectionalRemove() { + Account account = new Account(client,50,0); + assertTrue(client.getAccounts().contains(account)); + + client.removeAccount(account); + assertFalse(client.getAccounts().contains(account)); + } + + @Test + public void testRemoveAccount_SomeoneElseAccount_NoEffect() { + PrivateClient client2 = new PrivateClient("Dupont"); + Account account = new Account(client2,50,0); + + client.removeAccount(account); + assertFalse(client.getAccounts().contains(account)); + assertTrue(client2.getAccounts().contains(account)); + } + + @Test + public void testRemoveAccount_NullAccount_ExceptionThrown() { + assertThrows(NullPointerException.class, () -> client.removeAccount(null)); + } + + @Test + public void testClearAccounts_SeveralReferences_EmptyAccountsIsTrue() { + Account[] accounts = { + new Account(client,50, 0), + new Account(client,200, 0), + new Account(client,10, 0) + }; + + client.clearAccounts(); + + for(Account each : accounts){ + assertFalse(client.containsAccount(each)); + } + + assertTrue(client.isAccountsEmpty()); + } + + @Test + public void testContainsAccount_ReferencedAccount_ReturnTrue() { + Account[] accounts = { + new Account(client,50, 0), + new Account(client,200, 0), + new Account(client,10, 0) + }; + + for(Account each : accounts){ + assertTrue(client.containsAccount(each)); + } + } + + @Test + public void testContainsAccount_SomeoneElseAccount_ReturnFalse() { + Account account = new Account(new PrivateClient("Dupond"),50,0); + + assertFalse(client.containsAccount(account)); + } + + @Test + public void testContainsAccounts_NullValue_ReturnFalse() { + assertFalse(client.containsAccount(null)); + } } \ No newline at end of file diff --git a/src/main/test/fr/unantes/software/construction/CompanyClientTest.java b/src/main/test/fr/unantes/software/construction/CompanyClientTest.java new file mode 100644 index 00000000..113aee98 --- /dev/null +++ b/src/main/test/fr/unantes/software/construction/CompanyClientTest.java @@ -0,0 +1,56 @@ +package fr.unantes.software.construction; + +import fr.unantes.software.construction.address.City; +import fr.unantes.software.construction.address.CompanyAddress; +import fr.unantes.software.construction.address.PrivateAddress; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.shadow.com.univocity.parsers.annotations.Validate; + +import static org.junit.jupiter.api.Assertions.*; + +class CompanyClientTest { + CompanyClient client; + + @BeforeEach + void setUp() { + client = new CompanyClient("Doe Corp."); + } + + @Test + public void testSetName_SomeName_Succeed() { + client.setName("Doe.io"); + assertEquals("Doe.io", client.getName()); + } + + @Test + public void testSetName_NullValue_ExceptionThrown() { + String oldName = client.getName(); + assertThrows(Exception.class, () -> client.setName(null)); + assertEquals(oldName,client.getName()); + } + + @Test + public void testSetAddress_CompanyAddress_addReferenceTo() { + CompanyAddress address = new CompanyAddress(2,"Dupuis Street", new City("a Country","a City"),49000,null,null); + assertFalse(address.getRefClient().isSet()); + assertFalse(client.getAddressRef().isSet()); + + client.setAddress(address); + + assertTrue(address.getRefClient().isSet()); + assertTrue(client.getAddressRef().isSet()); + assertEquals(address,client.getAddressRef().get()); + assertEquals(client,address.getRefClient().get()); + } + + @Test + public void testSetAddress_PrivateAddress_ExceptionThrown() { + assertThrows(Exception.class, () -> client.setAddress(new PrivateAddress(2,"Dupuis Street",new City("a Country","a City"),49000,null))); + } + + @Test + public void testSetAddress_NullAddress_ExceptionThrown() { + assertThrows(Exception.class, () -> client.setAddress(null)); + } +} \ No newline at end of file diff --git a/src/main/test/fr/unantes/software/construction/PrivateClientTest.java b/src/main/test/fr/unantes/software/construction/PrivateClientTest.java new file mode 100644 index 00000000..f9f27ce0 --- /dev/null +++ b/src/main/test/fr/unantes/software/construction/PrivateClientTest.java @@ -0,0 +1,65 @@ +package fr.unantes.software.construction; + +import fr.unantes.software.construction.address.City; +import fr.unantes.software.construction.address.CompanyAddress; +import fr.unantes.software.construction.address.PrivateAddress; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class PrivateClientTest { + PrivateClient client; + + @BeforeEach + void setUp() { + client = new PrivateClient("Doe"); + } + + @Test + public void testSetName_SomeName_Succeed() { + client.setName("Dupuis"); + assertEquals("Dupuis", client.getLastName()); + } + + @Test + public void testSetName_NullValue_ExceptionThrown() { + String oldName = client.getName(); + assertThrows(NullPointerException.class, () -> client.setName(null)); + + assertEquals(oldName,client.getName()); + } + + @Test + public void testSetFirstName_AnyStringValue_Succeed() { + client.setFirstName("Timmy"); + assertEquals("Timmy", client.getFirstName()); + + client.setFirstName(null); + assertNull(client.getFirstName()); + } + + @Test + public void testSetAddress_PrivateAddress_addReferenceTo() { + PrivateAddress address = new PrivateAddress(2,"Dupuis Street", new City("a Country","a City"),49000,null); + assertFalse(address.getRefClient().isSet()); + assertFalse(client.getAddressRef().isSet()); + + client.setAddress(address); + + assertTrue(address.getRefClient().isSet()); + assertTrue(client.getAddressRef().isSet()); + assertEquals(address,client.getAddressRef().get()); + assertEquals(client,address.getRefClient().get()); + } + + @Test + public void testSetAddress_CompanyAddress_ExceptionThrown() { + assertThrows(Exception.class, () -> client.setAddress(new CompanyAddress(2,"Dupuis Street",new City("a Country","a City"),49000,null,null))); + } + + @Test + public void testSetAddress_NullAddress_ExceptionThrown() { + assertThrows(Exception.class, () -> client.setAddress(null)); + } +} \ No newline at end of file -- GitLab From caa27120c5c50f58b8e3a89a5bdd935b3d9cbdb3 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Wed, 25 Mar 2020 17:56:44 +0100 Subject: [PATCH 084/120] Updated Client and it's subclasses to match tests --- .../unantes/software/construction/Client.java | 34 +++++++++++-------- .../software/construction/CompanyClient.java | 7 ++++ .../software/construction/PrivateClient.java | 5 +-- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/Client.java b/src/main/java/fr/unantes/software/construction/Client.java index 890849b1..e6131dfd 100644 --- a/src/main/java/fr/unantes/software/construction/Client.java +++ b/src/main/java/fr/unantes/software/construction/Client.java @@ -4,6 +4,9 @@ import fr.unantes.software.construction.address.Address; import fr.unantes.software.construction.address.Card; import fr.unantes.software.construction.references.MultipleReference; import fr.unantes.software.construction.references.SingleReference; +import org.apache.commons.lang3.Validate; + +import java.util.Iterator; import java.util.UUID; public abstract class Client { @@ -40,6 +43,8 @@ public abstract class Client { } public void setAddress(Address add){ + Validate.notNull(add); + Validate.isTrue(add.getRole().equals(this.getRole())); this.refAddress.set(add); } @@ -56,14 +61,17 @@ public abstract class Client { * @uml.property name="accounts" */ public void setAccounts(Account[] value) { - //accounts = value; + for(Account each : value){ + if(!containsAccount(each)) + accounts.add(each); + } } /** * * @uml.property name="accounts" */ - public void addAccounts(Account element) { + public void addAccount(Account element) { accounts.add(element); } @@ -71,7 +79,7 @@ public abstract class Client { * * @uml.property name="accounts" */ - public void removeAccounts(Account element) { + public void removeAccount(Account element) { accounts.remove(element); } @@ -87,27 +95,25 @@ public abstract class Client { * * @uml.property name="accounts" */ - public void clearAccounts() { - for(Account a : accounts.get()){ - accounts.remove(a); + public boolean clearAccounts() { + if(!isAccountsEmpty()) { + Iterator it = accounts.get().iterator(); + while(it.hasNext()) { + it.next(); + it.remove(); + } } + return isAccountsEmpty(); } /** * * @uml.property name="accounts" */ - public boolean containsAccounts(Account element) { + public boolean containsAccount(Account element) { return accounts.contains(element); } - /** - * - * @uml.property name="accounts" - */ - public int accountsSize() { - return accounts.get().size(); - } public abstract String getName(); public abstract String getRole(); diff --git a/src/main/java/fr/unantes/software/construction/CompanyClient.java b/src/main/java/fr/unantes/software/construction/CompanyClient.java index 4c0c95c4..7a39dbf1 100644 --- a/src/main/java/fr/unantes/software/construction/CompanyClient.java +++ b/src/main/java/fr/unantes/software/construction/CompanyClient.java @@ -1,6 +1,8 @@ package fr.unantes.software.construction; +import org.apache.commons.lang3.Validate; + public class CompanyClient extends Client { private String name; @@ -14,6 +16,11 @@ public class CompanyClient extends Client { return name; } + public void setName(String value) { + Validate.notNull(value); + name = value; + } + @Override public String getRole() { return "company"; diff --git a/src/main/java/fr/unantes/software/construction/PrivateClient.java b/src/main/java/fr/unantes/software/construction/PrivateClient.java index c5cbb1b5..bcbf6bbe 100644 --- a/src/main/java/fr/unantes/software/construction/PrivateClient.java +++ b/src/main/java/fr/unantes/software/construction/PrivateClient.java @@ -1,6 +1,6 @@ package fr.unantes.software.construction; -import java.io.InvalidClassException; +import org.apache.commons.lang3.Validate; public class PrivateClient extends Client{ private String firstName; @@ -27,7 +27,8 @@ public class PrivateClient extends Client{ public void setFirstName(String value){ this.firstName = value; } - public void setLastName(String value){ + public void setName(String value){ + Validate.notNull(value); this.lastName = value; } -- GitLab From 368e17f5f88e5ee84251d575b84bb0505fcc1a17 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Wed, 25 Mar 2020 17:58:09 +0100 Subject: [PATCH 085/120] Fixed classes impacted by client new behavior --- .../software/construction/Account.java | 3 ++- .../unantes/software/construction/Bank.java | 3 +-- .../construction/address/Address.java | 26 ++----------------- .../construction/address/CompanyAddress.java | 5 ++++ .../construction/address/PrivateAddress.java | 10 +++---- .../software/construction/AccountTest.java | 4 +-- 6 files changed, 17 insertions(+), 34 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/Account.java b/src/main/java/fr/unantes/software/construction/Account.java index 82f7712c..c7d42b3f 100755 --- a/src/main/java/fr/unantes/software/construction/Account.java +++ b/src/main/java/fr/unantes/software/construction/Account.java @@ -30,7 +30,8 @@ public class Account { * The method also initializes the history with a new empty Vector */ public Account(Client p, float amount, float overdraft){ - owner.add(p); + if(p != null) + owner.add(p); this.balance = amount; this.overdraft = overdraft; } diff --git a/src/main/java/fr/unantes/software/construction/Bank.java b/src/main/java/fr/unantes/software/construction/Bank.java index e3323b20..0a610c95 100755 --- a/src/main/java/fr/unantes/software/construction/Bank.java +++ b/src/main/java/fr/unantes/software/construction/Bank.java @@ -2,7 +2,6 @@ package fr.unantes.software.construction; import fr.unantes.software.construction.address.AddressBook; -import java.io.InvalidClassException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -158,7 +157,7 @@ public class Bank { } Account acc = new Account(pending, amount, overdraft); this.addAccounts(acc); - pending.addAccounts(acc); + pending.addAccount(acc); return accountNumbers; } diff --git a/src/main/java/fr/unantes/software/construction/address/Address.java b/src/main/java/fr/unantes/software/construction/address/Address.java index baf32138..98f14dad 100755 --- a/src/main/java/fr/unantes/software/construction/address/Address.java +++ b/src/main/java/fr/unantes/software/construction/address/Address.java @@ -24,28 +24,6 @@ public abstract class Address { return target.getAddressRef(); } }; - /* - protected OneToOneAssociation refClient = new OneToOneAssociation<>(this); - - // Inner class to describe Bidirectional Monovalued Association between Address & Client - - protected class OneToOneAssociation extends - SingleReference { - - public OneToOneAssociation(Address a) { - super(a); - } - - @Override - public SingleReference oppositeFor(Object target) { - return refClient; - } - } - */ - - - - public SingleReference getRefClient() { return refClient; @@ -170,7 +148,7 @@ public abstract class Address { return ("" + streetNumber + ", " + streetName + " " + city + " " + zipCode ); } - - + + public abstract String getRole(); public abstract String toXML(); } \ No newline at end of file diff --git a/src/main/java/fr/unantes/software/construction/address/CompanyAddress.java b/src/main/java/fr/unantes/software/construction/address/CompanyAddress.java index ac5ed5bd..78abf8b0 100755 --- a/src/main/java/fr/unantes/software/construction/address/CompanyAddress.java +++ b/src/main/java/fr/unantes/software/construction/address/CompanyAddress.java @@ -53,6 +53,11 @@ public class CompanyAddress extends Address { return zone; } + @Override + public String getRole() { + return "company"; + } + /** * @param zone le nom du lieu dit diff --git a/src/main/java/fr/unantes/software/construction/address/PrivateAddress.java b/src/main/java/fr/unantes/software/construction/address/PrivateAddress.java index 1afa4088..9a03dd94 100755 --- a/src/main/java/fr/unantes/software/construction/address/PrivateAddress.java +++ b/src/main/java/fr/unantes/software/construction/address/PrivateAddress.java @@ -8,11 +8,6 @@ package fr.unantes.software.construction.address; public class PrivateAddress extends Address { private String locality; -/* - public PrivateAddress() { - super(); - } -*/ /** * * @@ -46,6 +41,11 @@ public class PrivateAddress extends Address { return locality; } + @Override + public String getRole() { + return "private"; + } + /** Les modificateurs */ /** diff --git a/src/main/test/fr/unantes/software/construction/AccountTest.java b/src/main/test/fr/unantes/software/construction/AccountTest.java index 925397f0..b30c094a 100644 --- a/src/main/test/fr/unantes/software/construction/AccountTest.java +++ b/src/main/test/fr/unantes/software/construction/AccountTest.java @@ -177,8 +177,8 @@ class AccountTest { Client client1 = new PrivateClient("Maurice","Rosy"); Client client2 = new PrivateClient("Robert","Velter"); - client1.addAccounts(account); - client2.addAccounts(account); + client1.addAccount(account); + client2.addAccount(account); assertTrue(account.getOwner().contains(client1)); assertTrue(account.getOwner().contains(client2)); -- GitLab From 31f29ff7ac4250cdb45250e7e58ef5cc7cb5480c Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Thu, 26 Mar 2020 10:32:36 +0100 Subject: [PATCH 086/120] Added method to remove an owner in Account with related tests --- .../software/construction/Account.java | 14 +++++-- .../software/construction/AccountTest.java | 41 ++++++++++++++++++- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/Account.java b/src/main/java/fr/unantes/software/construction/Account.java index c7d42b3f..13fc26df 100755 --- a/src/main/java/fr/unantes/software/construction/Account.java +++ b/src/main/java/fr/unantes/software/construction/Account.java @@ -131,13 +131,21 @@ public class Account { } /** - * + * * @uml.property name="owner" - * + * */ - public void setOwner(Client owner) { + public void addOwner(Client owner) { getOwner().add(owner); } + /** + * + * @uml.property name="owner" + * + */ + public void removeOwner(Client owner) { + getOwner().remove(owner); + } public void addHistory(Operation o) { operations.add(o); diff --git a/src/main/test/fr/unantes/software/construction/AccountTest.java b/src/main/test/fr/unantes/software/construction/AccountTest.java index b30c094a..c4c45a2f 100644 --- a/src/main/test/fr/unantes/software/construction/AccountTest.java +++ b/src/main/test/fr/unantes/software/construction/AccountTest.java @@ -150,6 +150,7 @@ class AccountTest { assertEquals(account.getBalance(),50); assertTrue(accOverdraft.getBalance() > accOverdraft.getOverdraft()); } + @Test void setBalance_belowOverdraft_ExceptionThrown() { float oldBalance = accOverdraft.getBalance(); @@ -159,19 +160,55 @@ class AccountTest { } @Test - void setOwner(){ + void testAddOwner_ValidClient_AddReference(){ Client oldClient = account.getOwner().get(0); Client newClient = new PrivateClient("Phillippe", "Chappuis"); assertFalse(account.getOwner().contains(newClient)); assertTrue(account.getOwner().contains(oldClient)); - account.setOwner(newClient); + account.addOwner(newClient); assertTrue(account.getOwner().contains(newClient)); assertTrue(account.getOwner().contains(oldClient)); } + + @Test + void testRemoveOwner_AlreadyExistingOwner_NoDuplicate(){ + Account newAccount = new Account(null,50,0); + PrivateClient client = new PrivateClient("Dupuis"); + newAccount.addOwner(client); + assertTrue(newAccount.getOwner().contains(client)); + + newAccount.addOwner(client); + + assertEquals(1, newAccount.getOwner().size()); + } + + @Test + void testAddOwner_NullClient_ExceptionThrown(){ + assertThrows(NullPointerException.class, () ->account.addOwner(null)); + + } + + @Test + void testRemoveOwner_ExistingOwner_RemoveFromReferences(){ + PrivateClient client = new PrivateClient("Dupuis"); + account.addOwner(client); + assertTrue(account.getOwner().contains(client)); + + account.removeOwner(client); + + assertFalse(account.getOwner().contains(client)); + } + + @Test + void testRemoveOwner_NullOwner_ExceptionThrown(){ + assertThrows(NullPointerException.class, () ->account.removeOwner(null)); + + } + @Test void completeHandshakeWith_Client(){ Client client1 = new PrivateClient("Maurice","Rosy"); -- GitLab From 3ae77bcc5f4b93f2d5900bd20e4a5e22705fb641 Mon Sep 17 00:00:00 2001 From: Gries Robin Date: Thu, 26 Mar 2020 13:49:35 +0100 Subject: [PATCH 087/120] Provide a ListWrapper abstraction that more closely fit a List interface and pass tests for AddressList, CardList, and GroupList --- .../construction/address/Address.java | 10 ++- .../construction/address/AddressBook.java | 15 ++--- .../construction/address/AddressList.java | 25 +++----- .../software/construction/address/Card.java | 20 +++--- .../construction/address/CardList.java | 19 ++++-- .../construction/address/GroupList.java | 13 +++- .../construction/address/ListWrapper.java} | 51 ++++++++++----- .../software/construction/address/Mail.java | 13 +--- .../construction/address/MailList.java | 10 +-- .../software/construction/address/Phone.java | 11 +++- .../construction/address/PhoneList.java | 12 ++-- .../construction/address/AddressBookTest.java | 19 +++--- .../construction/address/AddressListTest.java | 27 ++++---- .../construction/address/CardListTest.java | 50 ++++++++------- .../construction/address/CompanyCardTest.java | 51 ++++++++------- .../construction/address/GroupListTest.java | 2 + .../construction/address/MailListTest.java | 30 ++++----- .../construction/address/PhoneListTest.java | 26 ++++---- .../construction/address/PrivateCardTest.java | 50 +++++++-------- .../ListWrapperAddressTest.java} | 47 +++++++------- .../ListWrapperCardTest.java} | 47 +++++++------- .../ListWrapperGroupTest.java} | 47 +++++++------- .../ListWrapperMailTest.java} | 55 ++++++++-------- .../ListWrapperPhoneTest.java} | 64 ++++++++++--------- 24 files changed, 380 insertions(+), 334 deletions(-) rename src/main/{test/fr/unantes/software/construction/address/nonRegression/ListOf.java => java/fr/unantes/software/construction/address/ListWrapper.java} (71%) rename src/main/test/fr/unantes/software/construction/address/{nonRegression/ListOfAddressTest.java => wrapper/ListWrapperAddressTest.java} (75%) rename src/main/test/fr/unantes/software/construction/address/{nonRegression/ListOfCardTest.java => wrapper/ListWrapperCardTest.java} (74%) rename src/main/test/fr/unantes/software/construction/address/{nonRegression/ListOfGroupTest.java => wrapper/ListWrapperGroupTest.java} (72%) rename src/main/test/fr/unantes/software/construction/address/{nonRegression/ListOfMailTest.java => wrapper/ListWrapperMailTest.java} (76%) rename src/main/test/fr/unantes/software/construction/address/{nonRegression/ListOfPhoneTest.java => wrapper/ListWrapperPhoneTest.java} (73%) diff --git a/src/main/java/fr/unantes/software/construction/address/Address.java b/src/main/java/fr/unantes/software/construction/address/Address.java index baf32138..60b8e750 100755 --- a/src/main/java/fr/unantes/software/construction/address/Address.java +++ b/src/main/java/fr/unantes/software/construction/address/Address.java @@ -11,7 +11,10 @@ import org.apache.commons.lang3.Validate; * @version 1.0 * @date 17/12/2004. */ -public abstract class Address { +public abstract class Address { + + private static final String XML_LIST_OPEN_TAG = ""; + private static final String XML_LIST_CLOSE_TAG = ""; protected Integer streetNumber; protected String streetName; @@ -173,4 +176,9 @@ public abstract class Address { public abstract String toXML(); + public String getXMLListOpenTag() { return XML_LIST_OPEN_TAG; } + + public String getXMLListClosingTag() { return XML_LIST_CLOSE_TAG;} + + } \ No newline at end of file diff --git a/src/main/java/fr/unantes/software/construction/address/AddressBook.java b/src/main/java/fr/unantes/software/construction/address/AddressBook.java index 4cd58dd8..5213cc02 100755 --- a/src/main/java/fr/unantes/software/construction/address/AddressBook.java +++ b/src/main/java/fr/unantes/software/construction/address/AddressBook.java @@ -12,15 +12,15 @@ public class AddressBook { private String name; - private CardList cards; + private ListWrapper cards; public AddressBook() { - cards = new CardList(); + cards = new ListWrapper<>(); } - public AddressBook(String name, CardList cards) { + public AddressBook(String name, ListWrapper cards) { this.name = name; - this.cards = new CardList(); + this.cards = new ListWrapper<>(); this.cards.set(cards.get()); } @@ -28,7 +28,7 @@ public class AddressBook { return name; } - public CardList getCards() { + public ListWrapper getCards() { return cards; } @@ -36,10 +36,9 @@ public class AddressBook { name = names; } - public void setCards(CardList cards) { + public void setCards(ListWrapper cards) { this.cards.set(cards.get()); } - /** * Fusione deux reprtoires. Rend un nouvel objet. @@ -49,7 +48,7 @@ public class AddressBook { * @return */ public AddressBook merge(AddressBook addressBook, String name) { - CardList newCard = this.cards.merge(addressBook.getCards()); + ListWrapper newCard = this.cards.merge(addressBook.getCards()); AddressBook newBook = new AddressBook(); newBook.setName(name); diff --git a/src/main/java/fr/unantes/software/construction/address/AddressList.java b/src/main/java/fr/unantes/software/construction/address/AddressList.java index 244268b9..053a7cb0 100755 --- a/src/main/java/fr/unantes/software/construction/address/AddressList.java +++ b/src/main/java/fr/unantes/software/construction/address/AddressList.java @@ -11,7 +11,12 @@ import org.apache.commons.lang3.Validate; import java.util.*; -public class AddressList { +/** + * @deprecated use ListWrapper of Address instead + * Kept for non regression testing + */ +@Deprecated +public class AddressList { /** Les attributs d'instance */ protected Vector addresses; @@ -57,7 +62,7 @@ public class AddressList { */ public void add(Address address) { Validate.notNull(address); - if (!find(address)) + if (!contains(address)) addresses.add(address); } @@ -65,7 +70,7 @@ public class AddressList { * @param address adresse a delete de la liste */ public void delete(Address address) { - if (find(address)) + if (contains(address)) addresses.remove(address); else System.out.println("l'adresse a existe pas"); @@ -74,7 +79,7 @@ public class AddressList { /** * @param address c'est l'adresse recherchee */ - public boolean find(Address address) { + public boolean contains(Address address) { return addresses.contains(address); } @@ -105,23 +110,13 @@ public class AddressList { for (Enumeration e1 = addresses.get().elements(); e1 .hasMoreElements();) { nextAddress = (Address) e1.nextElement(); - if (!(newAddressList.find(nextAddress))) { + if (!(newAddressList.contains(nextAddress))) { newAddressList.add(nextAddress); } } return newAddressList; } - public String toXML() { - String res = ""; - Enumeration e = addresses.elements(); - while (e.hasMoreElements()) { - res = res + ((Address) e.nextElement()).toXML(); - } - res = res + ""; - return res; - } - /** * @return res */ diff --git a/src/main/java/fr/unantes/software/construction/address/Card.java b/src/main/java/fr/unantes/software/construction/address/Card.java index 31d51416..28f71257 100755 --- a/src/main/java/fr/unantes/software/construction/address/Card.java +++ b/src/main/java/fr/unantes/software/construction/address/Card.java @@ -8,11 +8,10 @@ import org.apache.commons.lang3.Validate; * @version 1.0 * @date 17/12/2004. */ -public abstract class Card { - +public abstract class Card { protected String identification; - protected GroupList groups = new GroupList(); - protected AddressList addresses = new AddressList(); + protected ListWrapper groups = new ListWrapper<>(); + protected ListWrapper
addresses = new ListWrapper<>(); protected PhoneList phones = new PhoneList(); protected MailList mails = new MailList(); private Client client; @@ -28,7 +27,7 @@ public abstract class Card { /** * @return addresses */ - public AddressList getAddresses() { + public ListWrapper
getAddresses() { return addresses; } @@ -49,7 +48,7 @@ public abstract class Card { /** * @return groups */ - public GroupList getGroups() { + public ListWrapper getGroups() { return groups; } @@ -57,7 +56,7 @@ public abstract class Card { /** * @param addresses */ - public void setAddresses(AddressList addresses) { + public void setAddresses(ListWrapper
addresses) { Validate.notNull(addresses); this.addresses = addresses; } @@ -81,7 +80,7 @@ public abstract class Card { /** * @param groups */ - public void setGroups(GroupList groups) { + public void setGroups(ListWrapper groups) { Validate.notNull(groups); this.groups = groups; } @@ -96,9 +95,6 @@ public abstract class Card { public abstract CompanyCard mergeCompanyCard(CompanyCard card); public abstract PrivateCard mergePrivateCard(PrivateCard card); - - - public abstract String toXML(); public boolean identicalCard(Card card) { return (identification.equals(card.getIdentification())); @@ -123,4 +119,6 @@ public abstract class Card { } return false; } + + public abstract String toXML(); } diff --git a/src/main/java/fr/unantes/software/construction/address/CardList.java b/src/main/java/fr/unantes/software/construction/address/CardList.java index ac0015bf..1f397f3b 100755 --- a/src/main/java/fr/unantes/software/construction/address/CardList.java +++ b/src/main/java/fr/unantes/software/construction/address/CardList.java @@ -1,9 +1,14 @@ package fr.unantes.software.construction.address; +import java.util.Enumeration; +import java.util.Vector; import org.apache.commons.lang3.Validate; -import java.util.*; - +/** + * @deprecated use a ListWrapper of Card instead + * Kept for non-regression testing. + */ +@Deprecated public class CardList { /** Les attributs d'instance */ @@ -18,7 +23,7 @@ public class CardList { /** * @param cards un objet adresse que l'on veux copier */ - public CardList (CardList cards){ + public CardList(CardList cards){ this.cards = new Vector(); for (Enumeration e = cards.get().elements(); e.hasMoreElements() ;) { this.cards.add(e.nextElement()); @@ -49,19 +54,19 @@ public class CardList { */ public void add(Card card){ Validate.notNull(card); - if(!find(card)) cards.add(card); + if(!contains(card)) cards.add(card); } /** * @param card fiche à supprimer de la liste */ public void delete(Card card){ - if (find(card)) cards.remove(card); + if (contains(card)) cards.remove(card); } /** * @param card c'est la fiche find */ - public boolean find(Card card){ + public boolean contains(Card card){ return cards.contains(card); } @@ -94,6 +99,7 @@ public class CardList { return res; } + public String toXML(){ String res = ""; Enumeration e = cards.elements(); @@ -114,4 +120,5 @@ public class CardList { } return res; } + } diff --git a/src/main/java/fr/unantes/software/construction/address/GroupList.java b/src/main/java/fr/unantes/software/construction/address/GroupList.java index 0c223f90..8a1e8b3d 100755 --- a/src/main/java/fr/unantes/software/construction/address/GroupList.java +++ b/src/main/java/fr/unantes/software/construction/address/GroupList.java @@ -4,7 +4,14 @@ import org.apache.commons.lang3.Validate; import java.util.*; -public class GroupList { +/** + * @deprecated use ListWrapper of Group instead + * Kept for non regression testing + */ +@Deprecated +public class GroupList { + private static final String XML_LIST_OPEN_TAG = ""; + private static final String XML_LIST_CLOSE_TAG = ""; Vector groups; @@ -111,12 +118,12 @@ public class GroupList { } public String toXML() { - String res = ""; + String res = XML_LIST_OPEN_TAG; Enumeration e = groups.elements(); while (e.hasMoreElements()) { res = res + ((Group) e.nextElement()).toXML(); } - res = res + ""; + res = res + XML_LIST_CLOSE_TAG; return res; } diff --git a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOf.java b/src/main/java/fr/unantes/software/construction/address/ListWrapper.java similarity index 71% rename from src/main/test/fr/unantes/software/construction/address/nonRegression/ListOf.java rename to src/main/java/fr/unantes/software/construction/address/ListWrapper.java index 1e92e754..b11fd8fa 100644 --- a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOf.java +++ b/src/main/java/fr/unantes/software/construction/address/ListWrapper.java @@ -1,7 +1,9 @@ -package fr.unantes.software.construction.address.nonRegression; +package fr.unantes.software.construction.address; + import java.util.ArrayList; import java.util.List; + import org.apache.commons.lang3.Validate; /** @@ -16,27 +18,25 @@ import org.apache.commons.lang3.Validate; * so that Tests can then be run using a List<Foo> and validate that the behavior * stay the same. */ -public class ListOf { +public class ListWrapper { private List targetList; /** * Empty constructor */ - public ListOf(){ - targetList = new ArrayList(); + public ListWrapper(){ + targetList = new ArrayList<>(); } /** * Copy constructor * @param otherList List to copy */ - public ListOf(ListOf otherList){ + public ListWrapper(ListWrapper otherList){ targetList = otherList.targetList; } /** - * Note that the original FooList used a Vector, obviously we are replacing it with a List - * as it is better abstraction * @return a List of element */ public List get() { @@ -50,12 +50,13 @@ public class ListOf { targetList = newTargetList; } } - public void add(T elt) throws NullPointerException { + + public void add(T elt) { if (elt == null) { throw new NullPointerException(); } else { //add() methods in FooList all check that elt doesn't exist yet, - // so they are actually Set instead of List + // so they are actually List instead of List if (this.targetList.contains(elt)) { return; } @@ -66,9 +67,10 @@ public class ListOf { Validate.notNull(elt); targetList.remove(elt); } - public boolean find(T elt){ + public boolean contains(T elt){ return targetList.contains(elt); } + public boolean find(T elt) { return targetList.contains(elt);} public int size(){ return targetList.size(); @@ -79,14 +81,14 @@ public class ListOf { * @param otherList a list of elements to add to this ListOf * @return a new ListOf containing the elements of this ListOf element and the elements of otherList */ - public ListOf merge(ListOf otherList){ + public ListWrapper merge(ListWrapper otherList){ Validate.notNull(otherList); - ListOf newList = new ListOf(this); + ListWrapper newList = new ListWrapper<>(this); //It's slow , but speed isn't important for this test for(T t : otherList.get()) { - if( !newList.find(t) ) { + if( !newList.contains(t) ) { newList.add(t); } } @@ -99,17 +101,34 @@ public class ListOf { * @param otherList a list of elements to add to this ListOf * @return a new ListOf containing the elements of this ListOf element and the elements of otherList */ - public ListOf delegateMerge( ListOf otherList){ + public ListWrapper delegateMerge( ListWrapper otherList){ Validate.notNull(otherList); - ListOf newList = new ListOf(this); + ListWrapper newList = new ListWrapper<>(this); newList.get().addAll(otherList.get()); return newList; } + /** + * @return a String representing this ListWrapper + */ + public String toString() { + String res = ""; + for (T t : targetList){ + res = res.concat("/n" + t.toString()); + } + return res; + } + + public String toXML() { + //TODO + return null; + } + + //TODO verifier / tester si les FooList force effectivemment les merge() à rendre une liste // sans doublons - // si oui , peut etre utiliser un Set / HashSet + // si oui , peut etre utiliser un Set // } diff --git a/src/main/java/fr/unantes/software/construction/address/Mail.java b/src/main/java/fr/unantes/software/construction/address/Mail.java index 7f3640a8..2c304950 100755 --- a/src/main/java/fr/unantes/software/construction/address/Mail.java +++ b/src/main/java/fr/unantes/software/construction/address/Mail.java @@ -12,30 +12,19 @@ public class Mail { this.work = work; } - /** - * @return _maill - */ + public String getHome() { return home; } - /** - * @return _com_mail - */ public String getWork() { return work; } - /** - * @param home - */ public void setHome(String home) { this.home = home; } - /** - * @param work - */ public void setWork(String work) { this.work = work; } diff --git a/src/main/java/fr/unantes/software/construction/address/MailList.java b/src/main/java/fr/unantes/software/construction/address/MailList.java index f0803f6a..e416f570 100755 --- a/src/main/java/fr/unantes/software/construction/address/MailList.java +++ b/src/main/java/fr/unantes/software/construction/address/MailList.java @@ -11,7 +11,7 @@ import org.apache.commons.lang3.Validate; import java.util.*; -public class MailList { +public class MailList { private Vector mails; @@ -54,7 +54,7 @@ public class MailList { */ public void add(Mail mail) { Validate.notNull(mail); - if (!find(mail)) + if (!contains(mail)) mails.add(mail); else{ Mail nextMail; @@ -78,7 +78,7 @@ public class MailList { */ public void delete(Mail mail) { Validate.notNull(mail); - if (find(mail)) + if (contains(mail)) mails.remove(mail); else System.out.println("le mail n'existe pas"); @@ -88,7 +88,7 @@ public class MailList { * @param mail * c'est le mail recherche */ - public boolean find(Mail mail) { + public boolean contains(Mail mail) { boolean res = false; Mail nextMail; for (Enumeration e = mails.elements(); e.hasMoreElements();) { @@ -126,7 +126,7 @@ public class MailList { for (Enumeration e1 = mails.get().elements(); e1 .hasMoreElements();) { nextMail = (Mail) e1.nextElement(); - if (!(res.find(nextMail))) { + if (!(res.contains(nextMail))) { res.add(nextMail); } } diff --git a/src/main/java/fr/unantes/software/construction/address/Phone.java b/src/main/java/fr/unantes/software/construction/address/Phone.java index eef93155..677e1e5e 100755 --- a/src/main/java/fr/unantes/software/construction/address/Phone.java +++ b/src/main/java/fr/unantes/software/construction/address/Phone.java @@ -1,5 +1,6 @@ package fr.unantes.software.construction.address; +import java.util.Objects; import org.apache.commons.lang3.Validate; import javax.annotation.Nonnull; @@ -10,6 +11,7 @@ import javax.annotation.Nonnull; * @date 17/12/2004. */ public class Phone { + @Nonnull protected Integer phoneNumber; protected String comment; @@ -68,7 +70,11 @@ public class Phone { public String toXML() { return ("" + phoneNumber + comment + ""); } - + + public boolean sameNumberAs(Phone other){ + return this.phoneNumber.equals(other.phoneNumber); + } + public boolean equals(Object another){ if (this == another) return true; @@ -76,6 +82,7 @@ public class Phone { return false; Phone other = (Phone) another; - return (phoneNumber == other.phoneNumber) && comment.equals(other.comment); + return (phoneNumber.equals(other.phoneNumber)) && comment.equals(other.comment); } + } diff --git a/src/main/java/fr/unantes/software/construction/address/PhoneList.java b/src/main/java/fr/unantes/software/construction/address/PhoneList.java index 9c89b7c6..7bc8b51f 100755 --- a/src/main/java/fr/unantes/software/construction/address/PhoneList.java +++ b/src/main/java/fr/unantes/software/construction/address/PhoneList.java @@ -4,7 +4,7 @@ import org.apache.commons.lang3.Validate; import java.util.*; -public class PhoneList { +public class PhoneList { protected Vector phones; @@ -45,7 +45,7 @@ public class PhoneList { */ public void add(Phone phone) { Validate.notNull(phone); - if (!find(phone)) + if (!contains(phone)) phones.add(phone); // si existe deja faire la fusion des deux dans celle deja enregistrer // dans le vecteur. @@ -60,7 +60,7 @@ public class PhoneList { */ public void delete(Phone phone) { Validate.notNull(phone); - if (find(phone)) + if (contains(phone)) phones.remove(phone); else System.out.println("le telephone n'existe pas"); @@ -69,10 +69,10 @@ public class PhoneList { /** * @param phone c'est le telephone recherche */ - public boolean find(Phone phone) { + public boolean contains(Phone phone) { boolean res = false; for (Enumeration e = phones.elements(); e.hasMoreElements();) { - if (((Phone) e.nextElement()).getPhoneNumber() == phone.getPhoneNumber()) + if ( ((Phone) e.nextElement()).sameNumberAs(phone) ) res = true; } return res; @@ -103,7 +103,7 @@ public class PhoneList { for (Enumeration e1 = phones.get().elements(); e1 .hasMoreElements();) { nextPhone = (Phone) e1.nextElement(); - if (!(res.find(nextPhone))) { + if (!(res.contains(nextPhone))) { res.add(nextPhone); } } diff --git a/src/main/test/fr/unantes/software/construction/address/AddressBookTest.java b/src/main/test/fr/unantes/software/construction/address/AddressBookTest.java index 3f84064f..bb97a379 100644 --- a/src/main/test/fr/unantes/software/construction/address/AddressBookTest.java +++ b/src/main/test/fr/unantes/software/construction/address/AddressBookTest.java @@ -6,13 +6,13 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; class AddressBookTest { - CardList someList; + ListWrapper someList; Card someCard; AddressBook addressBook; @BeforeEach void setUp(){ - someList = new CardList(); + someList = new ListWrapper<>(); someCard = new PrivateCard("Chaussette","Louis"); someList.add(someCard); addressBook = new AddressBook(); @@ -22,7 +22,7 @@ class AddressBookTest { void testSetCards_ValidCardList_Succeed(){ assertDoesNotThrow(()->addressBook.setCards(someList)); - assertEquals(someList.find(someCard), addressBook.getCards().find(someCard)); + assertEquals(someList.contains(someCard), addressBook.getCards().contains(someCard)); } @Test @@ -34,7 +34,6 @@ class AddressBookTest { void testSetName_AnyStringValue_Suceed(){ assertDoesNotThrow(()->addressBook.setName("name")); assertEquals("name",addressBook.getName()); - } @Test @@ -42,7 +41,7 @@ class AddressBookTest { addressBook.setCards(someList); AddressBook anotherBook = new AddressBook(); - CardList anotherList = new CardList(); + ListWrapper anotherList = new ListWrapper<>(); Card anotherCard = new PrivateCard("Marco","Polo"); anotherList.add(anotherCard); @@ -51,8 +50,8 @@ class AddressBookTest { AddressBook mergedLists = addressBook.merge(anotherBook,"new name"); assertNotNull(mergedLists); - assertTrue(mergedLists.getCards().find(someCard)); - assertTrue(mergedLists.getCards().find(anotherCard)); + assertTrue(mergedLists.getCards().contains(someCard)); + assertTrue(mergedLists.getCards().contains(anotherCard)); assertEquals(2, mergedLists.getCards().get().size()); } @@ -62,7 +61,7 @@ class AddressBookTest { AddressBook mergedLists = addressBook.merge(addressBook,""); assertNotNull(mergedLists); - assertTrue(mergedLists.getCards().find(someCard)); + assertTrue(mergedLists.getCards().contains(someCard)); assertEquals(addressBook.getCards().get().size(), mergedLists.getCards().get().size()); } @@ -71,7 +70,7 @@ class AddressBookTest { addressBook.setCards(someList); AddressBook anotherBook = new AddressBook(); - CardList anotherList = new CardList(); + ListWrapper anotherList = new ListWrapper<>(); Card anotherCard = new PrivateCard("Marco","Polo"); anotherList.add(someCard); @@ -93,7 +92,7 @@ class AddressBookTest { AddressBook mergedLists = addressBook.merge(anotherBook,""); assertNotNull(mergedLists); - assertTrue(mergedLists.getCards().find(someCard)); + assertTrue(mergedLists.getCards().contains(someCard)); assertEquals(1, mergedLists.getCards().get().size()); } diff --git a/src/main/test/fr/unantes/software/construction/address/AddressListTest.java b/src/main/test/fr/unantes/software/construction/address/AddressListTest.java index 5d68e3fd..0a5d8fe6 100644 --- a/src/main/test/fr/unantes/software/construction/address/AddressListTest.java +++ b/src/main/test/fr/unantes/software/construction/address/AddressListTest.java @@ -1,5 +1,10 @@ package fr.unantes.software.construction.address; +import fr.unantes.software.construction.address.Address; +import fr.unantes.software.construction.address.AddressList; +import fr.unantes.software.construction.address.City; +import fr.unantes.software.construction.address.CompanyAddress; +import fr.unantes.software.construction.address.PrivateAddress; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -33,7 +38,7 @@ class AddressListTest { addressList.set(anotherList); for(Address each : addresses){ - assertTrue(addressList.find(each)); + assertTrue(addressList.contains(each)); } } @@ -46,7 +51,7 @@ class AddressListTest { @Test public void testAdd_newValue_Succeed(){ assertDoesNotThrow(() -> addressList.add(someAddress)); - assertTrue(addressList.find(someAddress)); + assertTrue(addressList.contains(someAddress)); } @Test @@ -70,7 +75,7 @@ class AddressListTest { addressList.add(someAddress); addressList.delete(someAddress); - assertFalse(addressList.find(someAddress)); + assertFalse(addressList.contains(someAddress)); } @Test @@ -79,23 +84,23 @@ class AddressListTest { anotherList.add(someAddress); int currentSize = addressList.get().size(); - assertFalse(addressList.find(someAddress)); + assertFalse(addressList.contains(someAddress)); addressList.delete(someAddress); - assertTrue(anotherList.find(someAddress)); + assertTrue(anotherList.contains(someAddress)); assertEquals(currentSize, addressList.get().size()); } @Test public void testFind_ContainedValue_ReturnTrue(){ addressList.add(someAddress); - assertTrue(addressList.find(someAddress)); + assertTrue(addressList.contains(someAddress)); } @Test public void testFind_NotContainedValue_ReturnFalse(){ addressList.add(new PrivateAddress(1,"Another Private Street", new City("Norvege","Honningsvag"),0,null)); - assertFalse(addressList.find(someAddress)); + assertFalse(addressList.contains(someAddress)); } @Test @@ -109,8 +114,8 @@ class AddressListTest { AddressList mergedLists = addressList.merge(anotherList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someAddress)); - assertTrue(mergedLists.find(anotherAddress)); + assertTrue(mergedLists.contains(someAddress)); + assertTrue(mergedLists.contains(anotherAddress)); assertEquals(2, mergedLists.get().size()); } @@ -121,7 +126,7 @@ class AddressListTest { AddressList mergedLists = addressList.merge(addressList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someAddress)); + assertTrue(mergedLists.contains(someAddress)); assertEquals(addressList.get().size(), mergedLists.get().size()); } @@ -151,7 +156,7 @@ class AddressListTest { AddressList mergedLists = addressList.merge(anotherList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someAddress)); + assertTrue(mergedLists.contains(someAddress)); assertEquals(1, mergedLists.get().size()); } diff --git a/src/main/test/fr/unantes/software/construction/address/CardListTest.java b/src/main/test/fr/unantes/software/construction/address/CardListTest.java index e2e0fbea..deadb2d7 100644 --- a/src/main/test/fr/unantes/software/construction/address/CardListTest.java +++ b/src/main/test/fr/unantes/software/construction/address/CardListTest.java @@ -1,5 +1,11 @@ package fr.unantes.software.construction.address; +import fr.unantes.software.construction.address.Card; +import fr.unantes.software.construction.address.CompanyCard; +import fr.unantes.software.construction.address.ListWrapper; +import fr.unantes.software.construction.address.PrivateCard; +import java.util.ArrayList; +import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -8,17 +14,17 @@ import java.util.Vector; import static org.junit.jupiter.api.Assertions.*; class CardListTest { - CardList cardList; + ListWrapper cardList; Card someCard; @BeforeEach void setUp() { - cardList = new CardList(); + cardList = new ListWrapper(); someCard = new PrivateCard("John","Doe"); } @Test void testSet_ListOfCards_addCardsToCurrentList(){ - Vector anotherList = new Vector(); + Vector anotherList = new Vector<>(); Card[] cards = { someCard, new PrivateCard("Tom","Joe"), new CompanyCard("JohnDoe Corp.") @@ -31,7 +37,7 @@ class CardListTest { cardList.set(anotherList); for(Card each : cards){ - assertTrue(cardList.find(each)); + assertTrue(cardList.contains(each)); } } @@ -44,7 +50,7 @@ class CardListTest { @Test public void testAdd_newValue_Succeed(){ assertDoesNotThrow(() -> cardList.add(someCard)); - assertTrue(cardList.find(someCard)); + assertTrue(cardList.contains(someCard)); } @Test @@ -68,32 +74,32 @@ class CardListTest { cardList.add(someCard); cardList.delete(someCard); - assertFalse(cardList.find(someCard)); + assertFalse(cardList.contains(someCard)); } @Test public void testDelete_ValueContainedByAnotherGroup_NoEffect(){ - CardList anotherList = new CardList(); + ListWrapper anotherList = new ListWrapper(); anotherList.add(someCard); int currentSize = cardList.get().size(); - assertFalse(cardList.find(someCard)); + assertFalse(cardList.contains(someCard)); cardList.delete(someCard); - assertTrue(anotherList.find(someCard)); + assertTrue(anotherList.contains(someCard)); assertEquals(currentSize, cardList.get().size()); } @Test public void testFind_ContainedValue_ReturnTrue(){ cardList.add(someCard); - assertTrue(cardList.find(someCard)); + assertTrue(cardList.contains(someCard)); } @Test public void testFind_NotContainedValue_ReturnFalse(){ cardList.add(new PrivateCard("Tom","Joe")); - assertFalse(cardList.find(someCard)); + assertFalse(cardList.contains(someCard)); } @Test @@ -101,14 +107,14 @@ class CardListTest { cardList.add(someCard); Card anotherCard = new PrivateCard("Tom", "Joe"); - CardList anotherList = new CardList(); + ListWrapper anotherList = new ListWrapper(); anotherList.add(anotherCard); - CardList mergedLists = cardList.merge(anotherList); + ListWrapper mergedLists = cardList.merge(anotherList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someCard)); - assertTrue(mergedLists.find(anotherCard)); + assertTrue(mergedLists.contains(someCard)); + assertTrue(mergedLists.contains(anotherCard)); assertEquals(2, mergedLists.get().size()); } @@ -116,10 +122,10 @@ class CardListTest { public void testMerge_SameLists_NoChange(){ cardList.add(someCard); - CardList mergedLists = cardList.merge(cardList); + ListWrapper mergedLists = cardList.merge(cardList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someCard)); + assertTrue(mergedLists.contains(someCard)); assertEquals(cardList.get().size(), mergedLists.get().size()); } @@ -130,10 +136,10 @@ class CardListTest { cardList.add(someCard); cardList.add(anotherCard); - CardList anotherList = new CardList(); + ListWrapper anotherList = new ListWrapper(); anotherList.add(anotherCard); - CardList mergedLists = cardList.merge(anotherList); + ListWrapper mergedLists = cardList.merge(anotherList); assertNotNull(mergedLists); assertEquals(2, mergedLists.get().size()); @@ -142,14 +148,14 @@ class CardListTest { } @Test public void testMerge_EmptyCardList_SameCardList(){ - CardList anotherList = new CardList(); + ListWrapper anotherList = new ListWrapper(); cardList.add(someCard); - CardList mergedLists = cardList.merge(anotherList); + ListWrapper mergedLists = cardList.merge(anotherList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someCard)); + assertTrue(mergedLists.contains(someCard)); assertEquals(1, mergedLists.get().size()); } diff --git a/src/main/test/fr/unantes/software/construction/address/CompanyCardTest.java b/src/main/test/fr/unantes/software/construction/address/CompanyCardTest.java index 8e745aa0..e84ffa4c 100644 --- a/src/main/test/fr/unantes/software/construction/address/CompanyCardTest.java +++ b/src/main/test/fr/unantes/software/construction/address/CompanyCardTest.java @@ -2,26 +2,25 @@ package fr.unantes.software.construction.address; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.mockito.internal.matchers.Null; import static org.junit.jupiter.api.Assertions.*; class CompanyCardTest { CompanyCard companyCard; - AddressList someAddresses; CompanyAddress anAddress; + ListWrapper
someAddresses; CompanyAddress anAddress; PhoneList somePhones; Phone aPhone; MailList someMails; Mail aMail; - GroupList someGroups; Group aGroup; + ListWrapper someGroups; Group aGroup; @BeforeEach void setUp() { companyCard = new CompanyCard("companyName"); - someAddresses = new AddressList(); + someAddresses = new ListWrapper
(); somePhones = new PhoneList(); someMails = new MailList(); - someGroups = new GroupList(); + someGroups = new ListWrapper(); anAddress = new CompanyAddress(1, "Some Company Street", new City("Groenland", "Qeqertarsuaq"), 0, null,null); someAddresses.add(anAddress); @@ -42,7 +41,7 @@ class CompanyCardTest { */ @Test void testSetAddresses_SomeAddressList_Succeed(){ - AddressList someList = new AddressList(); + ListWrapper
someList = new ListWrapper
(); companyCard.setAddresses(someList); assertEquals(someList, companyCard.getAddresses()); @@ -84,7 +83,7 @@ class CompanyCardTest { @Test void testSetGroups_SomeGroupList_Succeed(){ - GroupList someList = new GroupList(); + ListWrapper someList = new ListWrapper(); companyCard.setGroups(someList); assertEquals(someList, companyCard.getGroups()); @@ -146,10 +145,10 @@ class CompanyCardTest { void testMerge_CompanyCardWithSameId_ReturnPrivateCardWithBothValues(){ CompanyCard anotherCard = new CompanyCard("companyName"); - AddressList anotherAddresses = new AddressList(); + ListWrapper
anotherAddresses = new ListWrapper
(); PhoneList anotherPhones = new PhoneList(); MailList anotherMails = new MailList(); - GroupList anotherGroups = new GroupList(); + ListWrapper anotherGroups = new ListWrapper(); CompanyAddress anotherAddress = new CompanyAddress(1, "Another Company Street", new City("France", "Angouleme"), 16000, null,null); anotherAddresses.add(anotherAddress); @@ -166,16 +165,16 @@ class CompanyCardTest { CompanyCard mergedCard = (CompanyCard) companyCard.merge(anotherCard); - assertTrue(mergedCard.getAddresses().find(anAddress)); - assertTrue(mergedCard.getAddresses().find(anotherAddress)); + assertTrue(mergedCard.getAddresses().contains(anAddress)); + assertTrue(mergedCard.getAddresses().contains(anotherAddress)); assertEquals(2,mergedCard.getAddresses().get().size()); - assertTrue(mergedCard.getPhones().find(aPhone)); - assertTrue(mergedCard.getPhones().find(anotherPhone)); + assertTrue(mergedCard.getPhones().contains(aPhone)); + assertTrue(mergedCard.getPhones().contains(anotherPhone)); assertEquals(2,mergedCard.getPhones().get().size()); - assertTrue(mergedCard.getMails().find(aMail)); - assertTrue(mergedCard.getMails().find(anotherMail)); + assertTrue(mergedCard.getMails().contains(aMail)); + assertTrue(mergedCard.getMails().contains(anotherMail)); assertEquals(2,mergedCard.getMails().get().size()); assertTrue(mergedCard.getGroups().find(aGroup)); @@ -189,13 +188,13 @@ class CompanyCardTest { void testMerge_SameCompanyCard_NoChange(){ CompanyCard mergedCard = (CompanyCard) companyCard.merge(companyCard); - assertTrue(mergedCard.getAddresses().find(anAddress)); + assertTrue(mergedCard.getAddresses().contains(anAddress)); assertEquals(1,mergedCard.getAddresses().get().size()); - assertTrue(mergedCard.getPhones().find(aPhone)); + assertTrue(mergedCard.getPhones().contains(aPhone)); assertEquals(1,mergedCard.getPhones().get().size()); - assertTrue(mergedCard.getMails().find(aMail)); + assertTrue(mergedCard.getMails().contains(aMail)); assertEquals(1,mergedCard.getMails().get().size()); assertTrue(mergedCard.getGroups().find(aGroup)); @@ -206,10 +205,10 @@ class CompanyCardTest { void testMerge_CompanyCardsWithSharedValues_NoDuplicate(){ CompanyCard anotherCard = new CompanyCard("companyName"); - AddressList anotherAddresses = new AddressList(); + ListWrapper
anotherAddresses = new ListWrapper
(); PhoneList anotherPhones = new PhoneList(); MailList anotherMails = new MailList(); - GroupList anotherGroups = new GroupList(); + ListWrapper anotherGroups = new ListWrapper(); CompanyAddress anotherAddress = new CompanyAddress(1, "Another Private Street", new City("France", "Angouleme"), 16000, null,null); Phone anotherPhone = new Phone(0642424242, ""); Mail anotherMail = new Mail("anotherHome@mail.com", null); @@ -231,16 +230,16 @@ class CompanyCardTest { CompanyCard mergedCard = (CompanyCard) companyCard.merge(anotherCard); - assertTrue(mergedCard.getAddresses().find(anAddress)); - assertTrue(mergedCard.getAddresses().find(anotherAddress)); + assertTrue(mergedCard.getAddresses().contains(anAddress)); + assertTrue(mergedCard.getAddresses().contains(anotherAddress)); assertEquals(2,mergedCard.getAddresses().get().size()); - assertTrue(mergedCard.getPhones().find(aPhone)); - assertTrue(mergedCard.getPhones().find(anotherPhone)); + assertTrue(mergedCard.getPhones().contains(aPhone)); + assertTrue(mergedCard.getPhones().contains(anotherPhone)); assertEquals(2,mergedCard.getPhones().get().size()); - assertTrue(mergedCard.getMails().find(aMail)); - assertTrue(mergedCard.getMails().find(anotherMail)); + assertTrue(mergedCard.getMails().contains(aMail)); + assertTrue(mergedCard.getMails().contains(anotherMail)); assertEquals(2,mergedCard.getMails().get().size()); assertTrue(mergedCard.getGroups().find(aGroup)); diff --git a/src/main/test/fr/unantes/software/construction/address/GroupListTest.java b/src/main/test/fr/unantes/software/construction/address/GroupListTest.java index e631a9b7..a89fd993 100644 --- a/src/main/test/fr/unantes/software/construction/address/GroupListTest.java +++ b/src/main/test/fr/unantes/software/construction/address/GroupListTest.java @@ -1,5 +1,7 @@ package fr.unantes.software.construction.address; +import fr.unantes.software.construction.address.Group; +import fr.unantes.software.construction.address.GroupList; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.internal.matchers.Null; diff --git a/src/main/test/fr/unantes/software/construction/address/MailListTest.java b/src/main/test/fr/unantes/software/construction/address/MailListTest.java index c4b7f471..08936a42 100644 --- a/src/main/test/fr/unantes/software/construction/address/MailListTest.java +++ b/src/main/test/fr/unantes/software/construction/address/MailListTest.java @@ -34,7 +34,7 @@ class MailListTest { mailList.set(anotherList); for(Mail each : mails){ - assertTrue(mailList.find(each)); + assertTrue(mailList.contains(each)); } } @@ -47,7 +47,7 @@ class MailListTest { void testAdd_NewMail_addMailToList(){ mailList.add(someMail); - assertTrue(mailList.find(someMail)); + assertTrue(mailList.contains(someMail)); } @Test @@ -60,7 +60,7 @@ class MailListTest { mailList.add(oneMail); mailList.add(anotherMail); - assertTrue(mailList.find(oneMail)); + assertTrue(mailList.contains(oneMail)); assertEquals("anotherWork@mail.com", oneMail.getWork()); assertEquals("someHome@mail.com",oneMail.getHome()); assertEquals(1,mailList.size()); @@ -76,7 +76,7 @@ class MailListTest { mailList.add(oneMail); mailList.add(anotherMail); - assertTrue(mailList.find(oneMail)); + assertTrue(mailList.contains(oneMail)); assertEquals("someWork@mail.com", oneMail.getWork()); assertNotEquals("anotherHome@mail.com",oneMail.getHome()); assertEquals(2,mailList.size()); @@ -92,7 +92,7 @@ class MailListTest { mailList.add(someMail); mailList.delete(someMail); - assertFalse(mailList.find(someMail)); + assertFalse(mailList.contains(someMail)); assertEquals(0,mailList.size()); } @@ -106,10 +106,10 @@ class MailListTest { mailList.delete(anotherMail); - assertTrue(mailList.find(someMail)); - assertFalse(mailList.find(anotherMail)); + assertTrue(mailList.contains(someMail)); + assertFalse(mailList.contains(anotherMail)); - assertTrue(anotherList.find(anotherMail)); + assertTrue(anotherList.contains(anotherMail)); assertEquals(1,anotherList.size()); } @@ -123,7 +123,7 @@ class MailListTest { Mail anotherMail = new Mail("anotherHome@mail.com","anotherWork@mail.com"); mailList.add(someMail); - assertFalse(mailList.find(anotherMail)); + assertFalse(mailList.contains(anotherMail)); } @Test @@ -131,7 +131,7 @@ class MailListTest { Mail anotherMail = new Mail("someHome@mail.com","anotherWork@mail.com"); mailList.add(someMail); - assertTrue(mailList.find(anotherMail)); + assertTrue(mailList.contains(anotherMail)); } @Test @@ -139,7 +139,7 @@ class MailListTest { Mail anotherMail = new Mail("anotherHome@mail.com","someWork@mail.com"); mailList.add(someMail); - assertFalse(mailList.find(anotherMail)); + assertFalse(mailList.contains(anotherMail)); } @Test @@ -153,8 +153,8 @@ class MailListTest { MailList mergedLists = mailList.merge(anotherList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someMail)); - assertTrue(mergedLists.find(anotherMail)); + assertTrue(mergedLists.contains(someMail)); + assertTrue(mergedLists.contains(anotherMail)); assertEquals(2, mergedLists.size()); } @@ -165,7 +165,7 @@ class MailListTest { MailList mergedLists = mailList.merge(mailList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someMail)); + assertTrue(mergedLists.contains(someMail)); assertEquals(mailList.size(), mergedLists.size()); } @@ -196,7 +196,7 @@ class MailListTest { MailList mergedLists = mailList.merge(anotherList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someMail)); + assertTrue(mergedLists.contains(someMail)); assertEquals(1, mergedLists.size()); } diff --git a/src/main/test/fr/unantes/software/construction/address/PhoneListTest.java b/src/main/test/fr/unantes/software/construction/address/PhoneListTest.java index 536d375e..95909529 100644 --- a/src/main/test/fr/unantes/software/construction/address/PhoneListTest.java +++ b/src/main/test/fr/unantes/software/construction/address/PhoneListTest.java @@ -32,7 +32,7 @@ class PhoneListTest { phoneList.set(anotherList); for(Phone each : phones){ - assertTrue(phoneList.find(each)); + assertTrue(phoneList.contains(each)); } } @@ -45,7 +45,7 @@ class PhoneListTest { void testAdd_NewPhone_addPhoneToList(){ phoneList.add(somePhone); - assertTrue(phoneList.find(somePhone)); + assertTrue(phoneList.contains(somePhone)); } @Test @@ -56,7 +56,7 @@ class PhoneListTest { phoneList.add(onePhone); phoneList.add(anotherPhone); - assertTrue(phoneList.find(onePhone)); + assertTrue(phoneList.contains(onePhone)); assertEquals(1,phoneList.get().size()); } @@ -70,7 +70,7 @@ class PhoneListTest { phoneList.add(somePhone); phoneList.delete(somePhone); - assertFalse(phoneList.find(somePhone)); + assertFalse(phoneList.contains(somePhone)); assertEquals(0,phoneList.get().size()); } @@ -84,10 +84,10 @@ class PhoneListTest { phoneList.delete(anotherPhone); - assertTrue(phoneList.find(somePhone)); - assertFalse(phoneList.find(anotherPhone)); + assertTrue(phoneList.contains(somePhone)); + assertFalse(phoneList.contains(anotherPhone)); - assertTrue(anotherList.find(anotherPhone)); + assertTrue(anotherList.contains(anotherPhone)); assertEquals(1,anotherList.get().size()); } @@ -101,7 +101,7 @@ class PhoneListTest { Phone anotherPhone = new Phone(0606060606,"another comment"); phoneList.add(somePhone); - assertFalse(phoneList.find(anotherPhone)); + assertFalse(phoneList.contains(anotherPhone)); } @Test @@ -109,7 +109,7 @@ class PhoneListTest { Phone anotherPhone = new Phone(somePhone.getPhoneNumber(),"another comment"); phoneList.add(somePhone); - assertTrue(phoneList.find(anotherPhone)); + assertTrue(phoneList.contains(anotherPhone)); } @@ -124,8 +124,8 @@ class PhoneListTest { PhoneList mergedLists = phoneList.merge(anotherList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(somePhone)); - assertTrue(mergedLists.find(anotherPhone)); + assertTrue(mergedLists.contains(somePhone)); + assertTrue(mergedLists.contains(anotherPhone)); assertEquals(2, mergedLists.get().size()); } @@ -136,7 +136,7 @@ class PhoneListTest { PhoneList mergedLists = phoneList.merge(phoneList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(somePhone)); + assertTrue(mergedLists.contains(somePhone)); assertEquals(phoneList.get().size(), mergedLists.get().size()); } @@ -167,7 +167,7 @@ class PhoneListTest { PhoneList mergedLists = phoneList.merge(anotherList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(somePhone)); + assertTrue(mergedLists.contains(somePhone)); assertEquals(1, mergedLists.get().size()); } diff --git a/src/main/test/fr/unantes/software/construction/address/PrivateCardTest.java b/src/main/test/fr/unantes/software/construction/address/PrivateCardTest.java index 2233af30..532a7396 100644 --- a/src/main/test/fr/unantes/software/construction/address/PrivateCardTest.java +++ b/src/main/test/fr/unantes/software/construction/address/PrivateCardTest.java @@ -8,20 +8,20 @@ import static org.junit.jupiter.api.Assertions.*; class PrivateCardTest { PrivateCard someCard; - AddressList someAddresses; PrivateAddress anAddress; + ListWrapper
someAddresses; PrivateAddress anAddress; PhoneList somePhones; Phone aPhone; MailList someMails; Mail aMail; - GroupList someGroups; Group aGroup; + ListWrapper someGroups; Group aGroup; @BeforeEach void setUp() { someCard = new PrivateCard("000"); - someAddresses = new AddressList(); + someAddresses = new ListWrapper
(); somePhones = new PhoneList(); someMails = new MailList(); - someGroups = new GroupList(); + someGroups = new ListWrapper(); anAddress = new PrivateAddress(1, "Some Private Street", new City("Groenland", "Qeqertarsuaq"), 0, null); someAddresses.add(anAddress); @@ -42,7 +42,7 @@ class PrivateCardTest { */ @Test void testSetAddresses_SomeAddressList_Succeed(){ - AddressList someList = new AddressList(); + ListWrapper
someList = new ListWrapper
(); someCard.setAddresses(someList); assertEquals(someList,someCard.getAddresses()); @@ -84,7 +84,7 @@ class PrivateCardTest { @Test void testSetGroups_SomeGroupList_Succeed(){ - GroupList someList = new GroupList(); + ListWrapper someList = new ListWrapper(); someCard.setGroups(someList); assertEquals(someList,someCard.getGroups()); @@ -152,10 +152,10 @@ class PrivateCardTest { void testMerge_PrivateCardWithSameId_ReturnPrivateCardWithBothValues(){ PrivateCard anotherCard = new PrivateCard("000"); - AddressList anotherAddresses = new AddressList(); + ListWrapper
anotherAddresses = new ListWrapper
(); PhoneList anotherPhones = new PhoneList(); MailList anotherMails = new MailList(); - GroupList anotherGroups = new GroupList(); + ListWrapper anotherGroups = new ListWrapper(); PrivateAddress anotherAddress = new PrivateAddress(1, "Another Private Street", new City("France", "Angouleme"), 16000, null); anotherAddresses.add(anotherAddress); @@ -172,16 +172,16 @@ class PrivateCardTest { PrivateCard mergedCard = (PrivateCard) someCard.merge(anotherCard); - assertTrue(mergedCard.getAddresses().find(anAddress)); - assertTrue(mergedCard.getAddresses().find(anotherAddress)); + assertTrue(mergedCard.getAddresses().contains(anAddress)); + assertTrue(mergedCard.getAddresses().contains(anotherAddress)); assertEquals(2,mergedCard.getAddresses().get().size()); - assertTrue(mergedCard.getPhones().find(aPhone)); - assertTrue(mergedCard.getPhones().find(anotherPhone)); + assertTrue(mergedCard.getPhones().contains(aPhone)); + assertTrue(mergedCard.getPhones().contains(anotherPhone)); assertEquals(2,mergedCard.getPhones().get().size()); - assertTrue(mergedCard.getMails().find(aMail)); - assertTrue(mergedCard.getMails().find(anotherMail)); + assertTrue(mergedCard.getMails().contains(aMail)); + assertTrue(mergedCard.getMails().contains(anotherMail)); assertEquals(2,mergedCard.getMails().get().size()); assertTrue(mergedCard.getGroups().find(aGroup)); @@ -195,13 +195,13 @@ class PrivateCardTest { void testMerge_SamePrivateCard_NoChange(){ PrivateCard mergedCard = (PrivateCard) someCard.merge(someCard); - assertTrue(mergedCard.getAddresses().find(anAddress)); + assertTrue(mergedCard.getAddresses().contains(anAddress)); assertEquals(1,mergedCard.getAddresses().get().size()); - assertTrue(mergedCard.getPhones().find(aPhone)); + assertTrue(mergedCard.getPhones().contains(aPhone)); assertEquals(1,mergedCard.getPhones().get().size()); - assertTrue(mergedCard.getMails().find(aMail)); + assertTrue(mergedCard.getMails().contains(aMail)); assertEquals(1,mergedCard.getMails().get().size()); assertTrue(mergedCard.getGroups().find(aGroup)); @@ -212,10 +212,10 @@ class PrivateCardTest { void testMerge_PrivateCardsWithSharedValues_NoDuplicate(){ PrivateCard anotherCard = new PrivateCard("000"); - AddressList anotherAddresses = new AddressList(); + ListWrapper
anotherAddresses = new ListWrapper
(); PhoneList anotherPhones = new PhoneList(); MailList anotherMails = new MailList(); - GroupList anotherGroups = new GroupList(); + ListWrapper anotherGroups = new ListWrapper(); PrivateAddress anotherAddress = new PrivateAddress(1, "Another Private Street", new City("France", "Angouleme"), 16000, null); Phone anotherPhone = new Phone(0642424242, ""); Mail anotherMail = new Mail("anotherHome@mail.com", null); @@ -237,16 +237,16 @@ class PrivateCardTest { PrivateCard mergedCard = (PrivateCard) someCard.merge(anotherCard); - assertTrue(mergedCard.getAddresses().find(anAddress)); - assertTrue(mergedCard.getAddresses().find(anotherAddress)); + assertTrue(mergedCard.getAddresses().contains(anAddress)); + assertTrue(mergedCard.getAddresses().contains(anotherAddress)); assertEquals(2,mergedCard.getAddresses().get().size()); - assertTrue(mergedCard.getPhones().find(aPhone)); - assertTrue(mergedCard.getPhones().find(anotherPhone)); + assertTrue(mergedCard.getPhones().contains(aPhone)); + assertTrue(mergedCard.getPhones().contains(anotherPhone)); assertEquals(2,mergedCard.getPhones().get().size()); - assertTrue(mergedCard.getMails().find(aMail)); - assertTrue(mergedCard.getMails().find(anotherMail)); + assertTrue(mergedCard.getMails().contains(aMail)); + assertTrue(mergedCard.getMails().contains(anotherMail)); assertEquals(2,mergedCard.getMails().get().size()); assertTrue(mergedCard.getGroups().find(aGroup)); diff --git a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfAddressTest.java b/src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperAddressTest.java similarity index 75% rename from src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfAddressTest.java rename to src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperAddressTest.java index 9353da88..91947881 100644 --- a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfAddressTest.java +++ b/src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperAddressTest.java @@ -1,4 +1,4 @@ -package fr.unantes.software.construction.address.nonRegression; +package fr.unantes.software.construction.address.wrapper; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -10,20 +10,21 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import fr.unantes.software.construction.address.Address; import fr.unantes.software.construction.address.City; import fr.unantes.software.construction.address.CompanyAddress; +import fr.unantes.software.construction.address.ListWrapper; import fr.unantes.software.construction.address.PrivateAddress; import java.util.ArrayList; import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -class ListOfAddressTest { +class ListWrapperAddressTest { - ListOf
addressList; + ListWrapper
addressList; Address someAddress; @BeforeEach void setUp() { - addressList = new ListOf<>(); + addressList = new ListWrapper<>(); someAddress = new PrivateAddress(1,"Some Private Street", new City("Groenland","Qeqertarsuaq"),0,null); } @@ -42,7 +43,7 @@ class ListOfAddressTest { addressList.set(anotherList); for(Address each : addresses){ - assertTrue(addressList.find(each)); + assertTrue(addressList.contains(each)); } } @@ -55,7 +56,7 @@ class ListOfAddressTest { @Test public void testAdd_newValue_Succeed(){ assertDoesNotThrow(() -> addressList.add(someAddress)); - assertTrue(addressList.find(someAddress)); + assertTrue(addressList.contains(someAddress)); } @Test @@ -79,32 +80,32 @@ class ListOfAddressTest { addressList.add(someAddress); addressList.delete(someAddress); - assertFalse(addressList.find(someAddress)); + assertFalse(addressList.contains(someAddress)); } @Test public void testDelete_ValueContainedByAnotherGroup_NoEffect(){ - ListOf
anotherList = new ListOf<>(); + ListWrapper
anotherList = new ListWrapper<>(); anotherList.add(someAddress); int currentSize = addressList.get().size(); - assertFalse(addressList.find(someAddress)); + assertFalse(addressList.contains(someAddress)); addressList.delete(someAddress); - assertTrue(anotherList.find(someAddress)); + assertTrue(anotherList.contains(someAddress)); assertEquals(currentSize, addressList.get().size()); } @Test public void testFind_ContainedValue_ReturnTrue(){ addressList.add(someAddress); - assertTrue(addressList.find(someAddress)); + assertTrue(addressList.contains(someAddress)); } @Test public void testFind_NotContainedValue_ReturnFalse(){ addressList.add(new PrivateAddress(1,"Another Private Street", new City("Norvege","Honningsvag"),0,null)); - assertFalse(addressList.find(someAddress)); + assertFalse(addressList.contains(someAddress)); } @Test @@ -112,14 +113,14 @@ class ListOfAddressTest { addressList.add(someAddress); Address anotherAddress = new PrivateAddress(1,"Another Private Street", new City("Norvege","Honningsvag"),0,null); - ListOf
anotherList = new ListOf<>(); + ListWrapper
anotherList = new ListWrapper<>(); anotherList.add(anotherAddress); - ListOf
mergedLists = addressList.merge(anotherList); + ListWrapper
mergedLists = addressList.merge(anotherList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someAddress)); - assertTrue(mergedLists.find(anotherAddress)); + assertTrue(mergedLists.contains(someAddress)); + assertTrue(mergedLists.contains(anotherAddress)); assertEquals(2, mergedLists.get().size()); } @@ -127,10 +128,10 @@ class ListOfAddressTest { public void testMerge_SameLists_NoChange(){ addressList.add(someAddress); - ListOf
mergedLists = addressList.merge(addressList); + ListWrapper
mergedLists = addressList.merge(addressList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someAddress)); + assertTrue(mergedLists.contains(someAddress)); assertEquals(addressList.get().size(), mergedLists.get().size()); } @@ -141,10 +142,10 @@ class ListOfAddressTest { addressList.add(someAddress); addressList.add(anotherAddress); - ListOf
anotherList = new ListOf<>(); + ListWrapper
anotherList = new ListWrapper<>(); anotherList.add(anotherAddress); - ListOf
mergedLists = addressList.merge(anotherList); + ListWrapper
mergedLists = addressList.merge(anotherList); assertNotNull(mergedLists); assertEquals(2, mergedLists.get().size()); @@ -153,14 +154,14 @@ class ListOfAddressTest { } @Test public void testMerge_EmptyGroupList_SameGroupList(){ - ListOf
anotherList = new ListOf<>(); + ListWrapper
anotherList = new ListWrapper<>(); addressList.add(someAddress); - ListOf
mergedLists = addressList.merge(anotherList); + ListWrapper
mergedLists = addressList.merge(anotherList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someAddress)); + assertTrue(mergedLists.contains(someAddress)); assertEquals(1, mergedLists.get().size()); } diff --git a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfCardTest.java b/src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperCardTest.java similarity index 74% rename from src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfCardTest.java rename to src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperCardTest.java index f0a234c7..c0fac659 100644 --- a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfCardTest.java +++ b/src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperCardTest.java @@ -1,4 +1,4 @@ -package fr.unantes.software.construction.address.nonRegression; +package fr.unantes.software.construction.address.wrapper; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -9,18 +9,19 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import fr.unantes.software.construction.address.Card; import fr.unantes.software.construction.address.CompanyCard; +import fr.unantes.software.construction.address.ListWrapper; import fr.unantes.software.construction.address.PrivateCard; import java.util.ArrayList; import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -class ListOfCardTest { - ListOf cardList; +class ListWrapperCardTest { + ListWrapper cardList; Card someCard; @BeforeEach void setUp() { - cardList = new ListOf<>(); + cardList = new ListWrapper<>(); someCard = new PrivateCard("John","Doe"); } @@ -39,7 +40,7 @@ class ListOfCardTest { cardList.set(anotherList); for(Card each : cards){ - assertTrue(cardList.find(each)); + assertTrue(cardList.contains(each)); } } @@ -52,7 +53,7 @@ class ListOfCardTest { @Test public void testAdd_newValue_Succeed(){ assertDoesNotThrow(() -> cardList.add(someCard)); - assertTrue(cardList.find(someCard)); + assertTrue(cardList.contains(someCard)); } @Test @@ -76,32 +77,32 @@ class ListOfCardTest { cardList.add(someCard); cardList.delete(someCard); - assertFalse(cardList.find(someCard)); + assertFalse(cardList.contains(someCard)); } @Test public void testDelete_ValueContainedByAnotherGroup_NoEffect(){ - ListOf anotherList = new ListOf<>(); + ListWrapper anotherList = new ListWrapper<>(); anotherList.add(someCard); int currentSize = cardList.get().size(); - assertFalse(cardList.find(someCard)); + assertFalse(cardList.contains(someCard)); cardList.delete(someCard); - assertTrue(anotherList.find(someCard)); + assertTrue(anotherList.contains(someCard)); assertEquals(currentSize, cardList.get().size()); } @Test public void testFind_ContainedValue_ReturnTrue(){ cardList.add(someCard); - assertTrue(cardList.find(someCard)); + assertTrue(cardList.contains(someCard)); } @Test public void testFind_NotContainedValue_ReturnFalse(){ cardList.add(new PrivateCard("Tom","Joe")); - assertFalse(cardList.find(someCard)); + assertFalse(cardList.contains(someCard)); } @Test @@ -109,14 +110,14 @@ class ListOfCardTest { cardList.add(someCard); Card anotherCard = new PrivateCard("Tom", "Joe"); - ListOf anotherList = new ListOf<>(); + ListWrapper anotherList = new ListWrapper<>(); anotherList.add(anotherCard); - ListOf mergedLists = cardList.merge(anotherList); + ListWrapper mergedLists = cardList.merge(anotherList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someCard)); - assertTrue(mergedLists.find(anotherCard)); + assertTrue(mergedLists.contains(someCard)); + assertTrue(mergedLists.contains(anotherCard)); assertEquals(2, mergedLists.get().size()); } @@ -124,10 +125,10 @@ class ListOfCardTest { public void testMerge_SameLists_NoChange(){ cardList.add(someCard); - ListOf mergedLists = cardList.merge(cardList); + ListWrapper mergedLists = cardList.merge(cardList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someCard)); + assertTrue(mergedLists.contains(someCard)); assertEquals(cardList.get().size(), mergedLists.get().size()); } @@ -138,10 +139,10 @@ class ListOfCardTest { cardList.add(someCard); cardList.add(anotherCard); - ListOf anotherList = new ListOf<>(); + ListWrapper anotherList = new ListWrapper<>(); anotherList.add(anotherCard); - ListOf mergedLists = cardList.merge(anotherList); + ListWrapper mergedLists = cardList.merge(anotherList); assertNotNull(mergedLists); assertEquals(2, mergedLists.get().size()); @@ -150,14 +151,14 @@ class ListOfCardTest { } @Test public void testMerge_EmptyCardList_SameCardList(){ - ListOf anotherList = new ListOf<>(); + ListWrapper anotherList = new ListWrapper<>(); cardList.add(someCard); - ListOf mergedLists = cardList.merge(anotherList); + ListWrapper mergedLists = cardList.merge(anotherList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someCard)); + assertTrue(mergedLists.contains(someCard)); assertEquals(1, mergedLists.get().size()); } diff --git a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfGroupTest.java b/src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperGroupTest.java similarity index 72% rename from src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfGroupTest.java rename to src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperGroupTest.java index 022ff480..cd9e6c65 100644 --- a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfGroupTest.java +++ b/src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperGroupTest.java @@ -1,4 +1,4 @@ -package fr.unantes.software.construction.address.nonRegression; +package fr.unantes.software.construction.address.wrapper; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -8,18 +8,19 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import fr.unantes.software.construction.address.Group; +import fr.unantes.software.construction.address.ListWrapper; import java.util.Vector; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -class ListOfGroupTest { +class ListWrapperGroupTest { - ListOf groupList; + ListWrapper groupList; Group someGroup; @BeforeEach void setUp() { - groupList = new ListOf(); + groupList = new ListWrapper(); someGroup = new Group("a Group",""); } @@ -38,7 +39,7 @@ class ListOfGroupTest { groupList.set(anotherList); for(Group each : groups){ - assertTrue(groupList.find(each)); + assertTrue(groupList.contains(each)); } } @@ -51,7 +52,7 @@ class ListOfGroupTest { @Test public void testAdd_newValue_Succeed(){ assertDoesNotThrow(() -> groupList.add(someGroup)); - assertTrue(groupList.find(someGroup)); + assertTrue(groupList.contains(someGroup)); } @Test @@ -75,32 +76,32 @@ class ListOfGroupTest { groupList.add(someGroup); groupList.delete(someGroup); - assertFalse(groupList.find(someGroup)); + assertFalse(groupList.contains(someGroup)); } @Test public void testDelete_ValueContainedByAnotherGroup_NoEffect(){ - ListOf anotherList = new ListOf(); + ListWrapper anotherList = new ListWrapper(); anotherList.add(someGroup); int currentSize = groupList.size(); - assertFalse(groupList.find(someGroup)); + assertFalse(groupList.contains(someGroup)); groupList.delete(someGroup); - assertTrue(anotherList.find(someGroup)); + assertTrue(anotherList.contains(someGroup)); assertEquals(currentSize, groupList.size()); } @Test public void testFind_ContainedValue_ReturnTrue(){ groupList.add(someGroup); - assertTrue(groupList.find(someGroup)); + assertTrue(groupList.contains(someGroup)); } @Test public void testFind_NotContainedValue_ReturnFalse(){ groupList.add(new Group("anotherGroup", "")); - assertFalse(groupList.find(someGroup)); + assertFalse(groupList.contains(someGroup)); } @Test @@ -108,14 +109,14 @@ class ListOfGroupTest { groupList.add(someGroup); Group anotherGroup = new Group("secondGroup", ""); - ListOf anotherList = new ListOf(); + ListWrapper anotherList = new ListWrapper(); anotherList.add(anotherGroup); - ListOf mergedLists = groupList.merge(anotherList); + ListWrapper mergedLists = groupList.merge(anotherList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someGroup)); - assertTrue(mergedLists.find(anotherGroup)); + assertTrue(mergedLists.contains(someGroup)); + assertTrue(mergedLists.contains(anotherGroup)); assertEquals(2, mergedLists.size()); } @@ -123,10 +124,10 @@ class ListOfGroupTest { public void testMerge_SameLists_NoChange(){ groupList.add(someGroup); - ListOf mergedLists = groupList.merge(groupList); + ListWrapper mergedLists = groupList.merge(groupList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someGroup)); + assertTrue(mergedLists.contains(someGroup)); assertEquals(groupList.size(), mergedLists.size()); } @@ -137,10 +138,10 @@ class ListOfGroupTest { groupList.add(someGroup); groupList.add(anotherGroup); - ListOf anotherList = new ListOf(); + ListWrapper anotherList = new ListWrapper(); anotherList.add(anotherGroup); - ListOf mergedLists = groupList.merge(anotherList); + ListWrapper mergedLists = groupList.merge(anotherList); assertNotNull(mergedLists); assertEquals(2, mergedLists.size()); @@ -149,14 +150,14 @@ class ListOfGroupTest { } @Test public void testMerge_EmptyGroupList_SameGroupList(){ - ListOf anotherList = new ListOf(); + ListWrapper anotherList = new ListWrapper(); groupList.add(someGroup); - ListOf mergedLists = groupList.merge(anotherList); + ListWrapper mergedLists = groupList.merge(anotherList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someGroup)); + assertTrue(mergedLists.contains(someGroup)); assertEquals(1, mergedLists.size()); } diff --git a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfMailTest.java b/src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperMailTest.java similarity index 76% rename from src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfMailTest.java rename to src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperMailTest.java index 97568cfc..ed4cb452 100644 --- a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfMailTest.java +++ b/src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperMailTest.java @@ -1,4 +1,4 @@ -package fr.unantes.software.construction.address.nonRegression; +package fr.unantes.software.construction.address.wrapper; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -7,19 +7,20 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +import fr.unantes.software.construction.address.ListWrapper; import fr.unantes.software.construction.address.Mail; import java.util.Vector; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -class ListOfMailTest { +class ListWrapperMailTest { - ListOf mailList; + ListWrapper mailList; Mail someMail; @BeforeEach void setUp() { - mailList = new ListOf(); + mailList = new ListWrapper(); someMail = new Mail("someHome@mail.com","someWork@mail.com"); } @@ -39,7 +40,7 @@ class ListOfMailTest { mailList.set(anotherList); for(Mail each : mails){ - assertTrue(mailList.find(each)); + assertTrue(mailList.contains(each)); } } @@ -52,7 +53,7 @@ class ListOfMailTest { void testAdd_NewMail_addMailToList(){ mailList.add(someMail); - assertTrue(mailList.find(someMail)); + assertTrue(mailList.contains(someMail)); } @Test @@ -65,7 +66,7 @@ class ListOfMailTest { mailList.add(oneMail); mailList.add(anotherMail); - assertTrue(mailList.find(oneMail)); + assertTrue(mailList.contains(oneMail)); assertEquals("anotherWork@mail.com", oneMail.getWork()); assertEquals("someHome@mail.com",oneMail.getHome()); assertEquals(1,mailList.size()); @@ -81,7 +82,7 @@ class ListOfMailTest { mailList.add(oneMail); mailList.add(anotherMail); - assertTrue(mailList.find(oneMail)); + assertTrue(mailList.contains(oneMail)); assertEquals("someWork@mail.com", oneMail.getWork()); assertNotEquals("anotherHome@mail.com",oneMail.getHome()); assertEquals(2,mailList.size()); @@ -97,13 +98,13 @@ class ListOfMailTest { mailList.add(someMail); mailList.delete(someMail); - assertFalse(mailList.find(someMail)); + assertFalse(mailList.contains(someMail)); assertEquals(0,mailList.size()); } @Test void testDelete_NotContainedMail_NoEffect(){ - ListOf anotherList = new ListOf(); + ListWrapper anotherList = new ListWrapper<>(); Mail anotherMail = new Mail(null,null); mailList.add(someMail); @@ -111,10 +112,10 @@ class ListOfMailTest { mailList.delete(anotherMail); - assertTrue(mailList.find(someMail)); - assertFalse(mailList.find(anotherMail)); + assertTrue(mailList.contains(someMail)); + assertFalse(mailList.contains(anotherMail)); - assertTrue(anotherList.find(anotherMail)); + assertTrue(anotherList.contains(anotherMail)); assertEquals(1,anotherList.size()); } @@ -128,7 +129,7 @@ class ListOfMailTest { Mail anotherMail = new Mail("anotherHome@mail.com","anotherWork@mail.com"); mailList.add(someMail); - assertFalse(mailList.find(anotherMail)); + assertFalse(mailList.contains(anotherMail)); } @Test @@ -136,7 +137,7 @@ class ListOfMailTest { Mail anotherMail = new Mail("someHome@mail.com","anotherWork@mail.com"); mailList.add(someMail); - assertTrue(mailList.find(anotherMail)); + assertTrue(mailList.contains(anotherMail)); } @Test @@ -144,7 +145,7 @@ class ListOfMailTest { Mail anotherMail = new Mail("anotherHome@mail.com","someWork@mail.com"); mailList.add(someMail); - assertFalse(mailList.find(anotherMail)); + assertFalse(mailList.contains(anotherMail)); } @Test @@ -152,14 +153,14 @@ class ListOfMailTest { mailList.add(someMail); Mail anotherMail = new Mail("anotherHome@mail.com", "anotherWork@mail.com"); - ListOf anotherList = new ListOf(); + ListWrapper anotherList = new ListWrapper(); anotherList.add(anotherMail); - ListOf mergedLists = mailList.merge(anotherList); + ListWrapper mergedLists = mailList.merge(anotherList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someMail)); - assertTrue(mergedLists.find(anotherMail)); + assertTrue(mergedLists.contains(someMail)); + assertTrue(mergedLists.contains(anotherMail)); assertEquals(2, mergedLists.size()); } @@ -167,10 +168,10 @@ class ListOfMailTest { public void testMerge_SameLists_NoChange(){ mailList.add(someMail); - ListOf mergedLists = mailList.merge(mailList); + ListWrapper mergedLists = mailList.merge(mailList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someMail)); + assertTrue(mergedLists.contains(someMail)); assertEquals(mailList.size(), mergedLists.size()); } @@ -182,10 +183,10 @@ class ListOfMailTest { mailList.add(someMail); mailList.add(anotherMail); - ListOf anotherList = new ListOf(); + ListWrapper anotherList = new ListWrapper(); anotherList.add(anotherMail); - ListOf mergedLists = mailList.merge(anotherList); + ListWrapper mergedLists = mailList.merge(anotherList); assertNotNull(mergedLists); assertEquals(2, mergedLists.size()); @@ -194,14 +195,14 @@ class ListOfMailTest { } @Test public void testMerge_EmptyMailList_SameGroupList(){ - ListOf anotherList = new ListOf(); + ListWrapper anotherList = new ListWrapper(); mailList.add(someMail); - ListOf mergedLists = mailList.merge(anotherList); + ListWrapper mergedLists = mailList.merge(anotherList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someMail)); + assertTrue(mergedLists.contains(someMail)); assertEquals(1, mergedLists.size()); } diff --git a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfPhoneTest.java b/src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperPhoneTest.java similarity index 73% rename from src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfPhoneTest.java rename to src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperPhoneTest.java index 1aafe15b..3a8b996d 100644 --- a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfPhoneTest.java +++ b/src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperPhoneTest.java @@ -1,18 +1,20 @@ -package fr.unantes.software.construction.address.nonRegression; +package fr.unantes.software.construction.address.wrapper; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; + +import fr.unantes.software.construction.address.ListWrapper; import fr.unantes.software.construction.address.Phone; import java.util.Vector; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -class ListOfPhoneTest { +class ListWrapperPhoneTest { - ListOf phoneList = new ListOf<>(); + ListWrapper phoneList = new ListWrapper<>(); Phone somePhone; @BeforeEach @@ -35,7 +37,7 @@ class ListOfPhoneTest { phoneList.set(anotherList); for(Phone each : phones){ - assertTrue(phoneList.find(each)); + assertTrue(phoneList.contains(each)); } } @@ -48,7 +50,7 @@ class ListOfPhoneTest { void testAdd_NewPhone_addPhoneToList(){ phoneList.add(somePhone); - assertTrue(phoneList.find(somePhone)); + assertTrue(phoneList.contains(somePhone)); } @Test @@ -59,10 +61,18 @@ class ListOfPhoneTest { phoneList.add(onePhone); phoneList.add(anotherPhone); - assertTrue(phoneList.find(onePhone)); + assertTrue(phoneList.contains(onePhone)); assertEquals(1,phoneList.get().size()); } + @Test + void testFind_PhoneNumberInCommon_ReturnTrue(){ + Phone anotherPhone = new Phone(somePhone.getPhoneNumber(),"another comment"); + + phoneList.add(somePhone); + assertTrue(phoneList.contains(anotherPhone)); + } + @Test void testAdd_Null_ExceptionThrown(){ assertThrows(NullPointerException.class, () -> phoneList.add(null)); @@ -73,13 +83,13 @@ class ListOfPhoneTest { phoneList.add(somePhone); phoneList.delete(somePhone); - assertFalse(phoneList.find(somePhone)); + assertFalse(phoneList.contains(somePhone)); assertEquals(0,phoneList.get().size()); } @Test void testDelete_NotContainedMail_NoEffect(){ - ListOf anotherList = new ListOf(); + ListWrapper anotherList = new ListWrapper(); Phone anotherPhone = new Phone(0606060606,"another comment"); phoneList.add(somePhone); @@ -87,10 +97,10 @@ class ListOfPhoneTest { phoneList.delete(anotherPhone); - assertTrue(phoneList.find(somePhone)); - assertFalse(phoneList.find(anotherPhone)); + assertTrue(phoneList.contains(somePhone)); + assertFalse(phoneList.contains(anotherPhone)); - assertTrue(anotherList.find(anotherPhone)); + assertTrue(anotherList.contains(anotherPhone)); assertEquals(1,anotherList.get().size()); } @@ -104,15 +114,7 @@ class ListOfPhoneTest { Phone anotherPhone = new Phone(0606060606,"another comment"); phoneList.add(somePhone); - assertFalse(phoneList.find(anotherPhone)); - } - - @Test - void testFind_PhoneNumberInCommon_ReturnTrue(){ - Phone anotherPhone = new Phone(somePhone.getPhoneNumber(),"another comment"); - - phoneList.add(somePhone); - assertTrue(phoneList.find(anotherPhone)); + assertFalse(phoneList.contains(anotherPhone)); } @@ -120,15 +122,15 @@ class ListOfPhoneTest { public void testMerge_TwoDifferentLists_ReturnListWithBothValue(){ phoneList.add(somePhone); - ListOf anotherList = new ListOf(); + ListWrapper anotherList = new ListWrapper(); Phone anotherPhone = new Phone(0606060606,"another comment"); anotherList.add(anotherPhone); - ListOf mergedLists = phoneList.merge(anotherList); + ListWrapper mergedLists = phoneList.merge(anotherList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(somePhone)); - assertTrue(mergedLists.find(anotherPhone)); + assertTrue(mergedLists.contains(somePhone)); + assertTrue(mergedLists.contains(anotherPhone)); assertEquals(2, mergedLists.get().size()); } @@ -136,16 +138,16 @@ class ListOfPhoneTest { public void testMerge_SameLists_NoChange(){ phoneList.add(somePhone); - ListOf mergedLists = phoneList.merge(phoneList); + ListWrapper mergedLists = phoneList.merge(phoneList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(somePhone)); + assertTrue(mergedLists.contains(somePhone)); assertEquals(phoneList.get().size(), mergedLists.get().size()); } @Test public void testMerge_ListsWithSharedValues_NoDuplicate(){ - ListOf anotherList = new ListOf(); + ListWrapper anotherList = new ListWrapper(); Phone anotherPhone = new Phone(0606060606,"another comment"); @@ -154,7 +156,7 @@ class ListOfPhoneTest { anotherList.add(anotherPhone); - ListOf mergedLists = phoneList.merge(anotherList); + ListWrapper mergedLists = phoneList.merge(anotherList); assertNotNull(mergedLists); assertEquals(2, mergedLists.get().size()); @@ -163,14 +165,14 @@ class ListOfPhoneTest { } @Test public void testMerge_EmptyPhoneList_SameGroupList(){ - ListOf anotherList = new ListOf(); + ListWrapper anotherList = new ListWrapper(); phoneList.add(somePhone); - ListOf mergedLists = phoneList.merge(anotherList); + ListWrapper mergedLists = phoneList.merge(anotherList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(somePhone)); + assertTrue(mergedLists.contains(somePhone)); assertEquals(1, mergedLists.get().size()); } -- GitLab From 80e0e00edeef94747aa11be5a1f5903c523523c0 Mon Sep 17 00:00:00 2001 From: Gries Robin Date: Thu, 26 Mar 2020 13:49:35 +0100 Subject: [PATCH 088/120] Provide a ListWrapper abstraction that more closely fit a List interface and pass tests for AddressList, CardList, and GroupList AddressList, CardList and GroupList are now Deprecated --- .../construction/address/Address.java | 10 ++- .../construction/address/AddressBook.java | 15 ++--- .../construction/address/AddressList.java | 25 +++----- .../software/construction/address/Card.java | 20 +++--- .../construction/address/CardList.java | 19 ++++-- .../construction/address/GroupList.java | 13 +++- .../construction/address/ListWrapper.java} | 51 ++++++++++----- .../software/construction/address/Mail.java | 13 +--- .../construction/address/MailList.java | 10 +-- .../software/construction/address/Phone.java | 11 +++- .../construction/address/PhoneList.java | 12 ++-- .../construction/address/AddressBookTest.java | 19 +++--- .../construction/address/AddressListTest.java | 27 ++++---- .../construction/address/CardListTest.java | 50 ++++++++------- .../construction/address/CompanyCardTest.java | 51 ++++++++------- .../construction/address/GroupListTest.java | 2 + .../construction/address/MailListTest.java | 30 ++++----- .../construction/address/PhoneListTest.java | 26 ++++---- .../construction/address/PrivateCardTest.java | 50 +++++++-------- .../ListWrapperAddressTest.java} | 47 +++++++------- .../ListWrapperCardTest.java} | 47 +++++++------- .../ListWrapperGroupTest.java} | 47 +++++++------- .../ListWrapperMailTest.java} | 55 ++++++++-------- .../ListWrapperPhoneTest.java} | 64 ++++++++++--------- 24 files changed, 380 insertions(+), 334 deletions(-) rename src/main/{test/fr/unantes/software/construction/address/nonRegression/ListOf.java => java/fr/unantes/software/construction/address/ListWrapper.java} (71%) rename src/main/test/fr/unantes/software/construction/address/{nonRegression/ListOfAddressTest.java => wrapper/ListWrapperAddressTest.java} (75%) rename src/main/test/fr/unantes/software/construction/address/{nonRegression/ListOfCardTest.java => wrapper/ListWrapperCardTest.java} (74%) rename src/main/test/fr/unantes/software/construction/address/{nonRegression/ListOfGroupTest.java => wrapper/ListWrapperGroupTest.java} (72%) rename src/main/test/fr/unantes/software/construction/address/{nonRegression/ListOfMailTest.java => wrapper/ListWrapperMailTest.java} (76%) rename src/main/test/fr/unantes/software/construction/address/{nonRegression/ListOfPhoneTest.java => wrapper/ListWrapperPhoneTest.java} (73%) diff --git a/src/main/java/fr/unantes/software/construction/address/Address.java b/src/main/java/fr/unantes/software/construction/address/Address.java index baf32138..60b8e750 100755 --- a/src/main/java/fr/unantes/software/construction/address/Address.java +++ b/src/main/java/fr/unantes/software/construction/address/Address.java @@ -11,7 +11,10 @@ import org.apache.commons.lang3.Validate; * @version 1.0 * @date 17/12/2004. */ -public abstract class Address { +public abstract class Address { + + private static final String XML_LIST_OPEN_TAG = ""; + private static final String XML_LIST_CLOSE_TAG = ""; protected Integer streetNumber; protected String streetName; @@ -173,4 +176,9 @@ public abstract class Address { public abstract String toXML(); + public String getXMLListOpenTag() { return XML_LIST_OPEN_TAG; } + + public String getXMLListClosingTag() { return XML_LIST_CLOSE_TAG;} + + } \ No newline at end of file diff --git a/src/main/java/fr/unantes/software/construction/address/AddressBook.java b/src/main/java/fr/unantes/software/construction/address/AddressBook.java index 4cd58dd8..5213cc02 100755 --- a/src/main/java/fr/unantes/software/construction/address/AddressBook.java +++ b/src/main/java/fr/unantes/software/construction/address/AddressBook.java @@ -12,15 +12,15 @@ public class AddressBook { private String name; - private CardList cards; + private ListWrapper cards; public AddressBook() { - cards = new CardList(); + cards = new ListWrapper<>(); } - public AddressBook(String name, CardList cards) { + public AddressBook(String name, ListWrapper cards) { this.name = name; - this.cards = new CardList(); + this.cards = new ListWrapper<>(); this.cards.set(cards.get()); } @@ -28,7 +28,7 @@ public class AddressBook { return name; } - public CardList getCards() { + public ListWrapper getCards() { return cards; } @@ -36,10 +36,9 @@ public class AddressBook { name = names; } - public void setCards(CardList cards) { + public void setCards(ListWrapper cards) { this.cards.set(cards.get()); } - /** * Fusione deux reprtoires. Rend un nouvel objet. @@ -49,7 +48,7 @@ public class AddressBook { * @return */ public AddressBook merge(AddressBook addressBook, String name) { - CardList newCard = this.cards.merge(addressBook.getCards()); + ListWrapper newCard = this.cards.merge(addressBook.getCards()); AddressBook newBook = new AddressBook(); newBook.setName(name); diff --git a/src/main/java/fr/unantes/software/construction/address/AddressList.java b/src/main/java/fr/unantes/software/construction/address/AddressList.java index 244268b9..053a7cb0 100755 --- a/src/main/java/fr/unantes/software/construction/address/AddressList.java +++ b/src/main/java/fr/unantes/software/construction/address/AddressList.java @@ -11,7 +11,12 @@ import org.apache.commons.lang3.Validate; import java.util.*; -public class AddressList { +/** + * @deprecated use ListWrapper of Address instead + * Kept for non regression testing + */ +@Deprecated +public class AddressList { /** Les attributs d'instance */ protected Vector addresses; @@ -57,7 +62,7 @@ public class AddressList { */ public void add(Address address) { Validate.notNull(address); - if (!find(address)) + if (!contains(address)) addresses.add(address); } @@ -65,7 +70,7 @@ public class AddressList { * @param address adresse a delete de la liste */ public void delete(Address address) { - if (find(address)) + if (contains(address)) addresses.remove(address); else System.out.println("l'adresse a existe pas"); @@ -74,7 +79,7 @@ public class AddressList { /** * @param address c'est l'adresse recherchee */ - public boolean find(Address address) { + public boolean contains(Address address) { return addresses.contains(address); } @@ -105,23 +110,13 @@ public class AddressList { for (Enumeration e1 = addresses.get().elements(); e1 .hasMoreElements();) { nextAddress = (Address) e1.nextElement(); - if (!(newAddressList.find(nextAddress))) { + if (!(newAddressList.contains(nextAddress))) { newAddressList.add(nextAddress); } } return newAddressList; } - public String toXML() { - String res = ""; - Enumeration e = addresses.elements(); - while (e.hasMoreElements()) { - res = res + ((Address) e.nextElement()).toXML(); - } - res = res + ""; - return res; - } - /** * @return res */ diff --git a/src/main/java/fr/unantes/software/construction/address/Card.java b/src/main/java/fr/unantes/software/construction/address/Card.java index 31d51416..28f71257 100755 --- a/src/main/java/fr/unantes/software/construction/address/Card.java +++ b/src/main/java/fr/unantes/software/construction/address/Card.java @@ -8,11 +8,10 @@ import org.apache.commons.lang3.Validate; * @version 1.0 * @date 17/12/2004. */ -public abstract class Card { - +public abstract class Card { protected String identification; - protected GroupList groups = new GroupList(); - protected AddressList addresses = new AddressList(); + protected ListWrapper groups = new ListWrapper<>(); + protected ListWrapper
addresses = new ListWrapper<>(); protected PhoneList phones = new PhoneList(); protected MailList mails = new MailList(); private Client client; @@ -28,7 +27,7 @@ public abstract class Card { /** * @return addresses */ - public AddressList getAddresses() { + public ListWrapper
getAddresses() { return addresses; } @@ -49,7 +48,7 @@ public abstract class Card { /** * @return groups */ - public GroupList getGroups() { + public ListWrapper getGroups() { return groups; } @@ -57,7 +56,7 @@ public abstract class Card { /** * @param addresses */ - public void setAddresses(AddressList addresses) { + public void setAddresses(ListWrapper
addresses) { Validate.notNull(addresses); this.addresses = addresses; } @@ -81,7 +80,7 @@ public abstract class Card { /** * @param groups */ - public void setGroups(GroupList groups) { + public void setGroups(ListWrapper groups) { Validate.notNull(groups); this.groups = groups; } @@ -96,9 +95,6 @@ public abstract class Card { public abstract CompanyCard mergeCompanyCard(CompanyCard card); public abstract PrivateCard mergePrivateCard(PrivateCard card); - - - public abstract String toXML(); public boolean identicalCard(Card card) { return (identification.equals(card.getIdentification())); @@ -123,4 +119,6 @@ public abstract class Card { } return false; } + + public abstract String toXML(); } diff --git a/src/main/java/fr/unantes/software/construction/address/CardList.java b/src/main/java/fr/unantes/software/construction/address/CardList.java index ac0015bf..1f397f3b 100755 --- a/src/main/java/fr/unantes/software/construction/address/CardList.java +++ b/src/main/java/fr/unantes/software/construction/address/CardList.java @@ -1,9 +1,14 @@ package fr.unantes.software.construction.address; +import java.util.Enumeration; +import java.util.Vector; import org.apache.commons.lang3.Validate; -import java.util.*; - +/** + * @deprecated use a ListWrapper of Card instead + * Kept for non-regression testing. + */ +@Deprecated public class CardList { /** Les attributs d'instance */ @@ -18,7 +23,7 @@ public class CardList { /** * @param cards un objet adresse que l'on veux copier */ - public CardList (CardList cards){ + public CardList(CardList cards){ this.cards = new Vector(); for (Enumeration e = cards.get().elements(); e.hasMoreElements() ;) { this.cards.add(e.nextElement()); @@ -49,19 +54,19 @@ public class CardList { */ public void add(Card card){ Validate.notNull(card); - if(!find(card)) cards.add(card); + if(!contains(card)) cards.add(card); } /** * @param card fiche à supprimer de la liste */ public void delete(Card card){ - if (find(card)) cards.remove(card); + if (contains(card)) cards.remove(card); } /** * @param card c'est la fiche find */ - public boolean find(Card card){ + public boolean contains(Card card){ return cards.contains(card); } @@ -94,6 +99,7 @@ public class CardList { return res; } + public String toXML(){ String res = ""; Enumeration e = cards.elements(); @@ -114,4 +120,5 @@ public class CardList { } return res; } + } diff --git a/src/main/java/fr/unantes/software/construction/address/GroupList.java b/src/main/java/fr/unantes/software/construction/address/GroupList.java index 0c223f90..8a1e8b3d 100755 --- a/src/main/java/fr/unantes/software/construction/address/GroupList.java +++ b/src/main/java/fr/unantes/software/construction/address/GroupList.java @@ -4,7 +4,14 @@ import org.apache.commons.lang3.Validate; import java.util.*; -public class GroupList { +/** + * @deprecated use ListWrapper of Group instead + * Kept for non regression testing + */ +@Deprecated +public class GroupList { + private static final String XML_LIST_OPEN_TAG = ""; + private static final String XML_LIST_CLOSE_TAG = ""; Vector groups; @@ -111,12 +118,12 @@ public class GroupList { } public String toXML() { - String res = ""; + String res = XML_LIST_OPEN_TAG; Enumeration e = groups.elements(); while (e.hasMoreElements()) { res = res + ((Group) e.nextElement()).toXML(); } - res = res + ""; + res = res + XML_LIST_CLOSE_TAG; return res; } diff --git a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOf.java b/src/main/java/fr/unantes/software/construction/address/ListWrapper.java similarity index 71% rename from src/main/test/fr/unantes/software/construction/address/nonRegression/ListOf.java rename to src/main/java/fr/unantes/software/construction/address/ListWrapper.java index 1e92e754..b11fd8fa 100644 --- a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOf.java +++ b/src/main/java/fr/unantes/software/construction/address/ListWrapper.java @@ -1,7 +1,9 @@ -package fr.unantes.software.construction.address.nonRegression; +package fr.unantes.software.construction.address; + import java.util.ArrayList; import java.util.List; + import org.apache.commons.lang3.Validate; /** @@ -16,27 +18,25 @@ import org.apache.commons.lang3.Validate; * so that Tests can then be run using a List<Foo> and validate that the behavior * stay the same. */ -public class ListOf { +public class ListWrapper { private List targetList; /** * Empty constructor */ - public ListOf(){ - targetList = new ArrayList(); + public ListWrapper(){ + targetList = new ArrayList<>(); } /** * Copy constructor * @param otherList List to copy */ - public ListOf(ListOf otherList){ + public ListWrapper(ListWrapper otherList){ targetList = otherList.targetList; } /** - * Note that the original FooList used a Vector, obviously we are replacing it with a List - * as it is better abstraction * @return a List of element */ public List get() { @@ -50,12 +50,13 @@ public class ListOf { targetList = newTargetList; } } - public void add(T elt) throws NullPointerException { + + public void add(T elt) { if (elt == null) { throw new NullPointerException(); } else { //add() methods in FooList all check that elt doesn't exist yet, - // so they are actually Set instead of List + // so they are actually List instead of List if (this.targetList.contains(elt)) { return; } @@ -66,9 +67,10 @@ public class ListOf { Validate.notNull(elt); targetList.remove(elt); } - public boolean find(T elt){ + public boolean contains(T elt){ return targetList.contains(elt); } + public boolean find(T elt) { return targetList.contains(elt);} public int size(){ return targetList.size(); @@ -79,14 +81,14 @@ public class ListOf { * @param otherList a list of elements to add to this ListOf * @return a new ListOf containing the elements of this ListOf element and the elements of otherList */ - public ListOf merge(ListOf otherList){ + public ListWrapper merge(ListWrapper otherList){ Validate.notNull(otherList); - ListOf newList = new ListOf(this); + ListWrapper newList = new ListWrapper<>(this); //It's slow , but speed isn't important for this test for(T t : otherList.get()) { - if( !newList.find(t) ) { + if( !newList.contains(t) ) { newList.add(t); } } @@ -99,17 +101,34 @@ public class ListOf { * @param otherList a list of elements to add to this ListOf * @return a new ListOf containing the elements of this ListOf element and the elements of otherList */ - public ListOf delegateMerge( ListOf otherList){ + public ListWrapper delegateMerge( ListWrapper otherList){ Validate.notNull(otherList); - ListOf newList = new ListOf(this); + ListWrapper newList = new ListWrapper<>(this); newList.get().addAll(otherList.get()); return newList; } + /** + * @return a String representing this ListWrapper + */ + public String toString() { + String res = ""; + for (T t : targetList){ + res = res.concat("/n" + t.toString()); + } + return res; + } + + public String toXML() { + //TODO + return null; + } + + //TODO verifier / tester si les FooList force effectivemment les merge() à rendre une liste // sans doublons - // si oui , peut etre utiliser un Set / HashSet + // si oui , peut etre utiliser un Set // } diff --git a/src/main/java/fr/unantes/software/construction/address/Mail.java b/src/main/java/fr/unantes/software/construction/address/Mail.java index 7f3640a8..2c304950 100755 --- a/src/main/java/fr/unantes/software/construction/address/Mail.java +++ b/src/main/java/fr/unantes/software/construction/address/Mail.java @@ -12,30 +12,19 @@ public class Mail { this.work = work; } - /** - * @return _maill - */ + public String getHome() { return home; } - /** - * @return _com_mail - */ public String getWork() { return work; } - /** - * @param home - */ public void setHome(String home) { this.home = home; } - /** - * @param work - */ public void setWork(String work) { this.work = work; } diff --git a/src/main/java/fr/unantes/software/construction/address/MailList.java b/src/main/java/fr/unantes/software/construction/address/MailList.java index f0803f6a..e416f570 100755 --- a/src/main/java/fr/unantes/software/construction/address/MailList.java +++ b/src/main/java/fr/unantes/software/construction/address/MailList.java @@ -11,7 +11,7 @@ import org.apache.commons.lang3.Validate; import java.util.*; -public class MailList { +public class MailList { private Vector mails; @@ -54,7 +54,7 @@ public class MailList { */ public void add(Mail mail) { Validate.notNull(mail); - if (!find(mail)) + if (!contains(mail)) mails.add(mail); else{ Mail nextMail; @@ -78,7 +78,7 @@ public class MailList { */ public void delete(Mail mail) { Validate.notNull(mail); - if (find(mail)) + if (contains(mail)) mails.remove(mail); else System.out.println("le mail n'existe pas"); @@ -88,7 +88,7 @@ public class MailList { * @param mail * c'est le mail recherche */ - public boolean find(Mail mail) { + public boolean contains(Mail mail) { boolean res = false; Mail nextMail; for (Enumeration e = mails.elements(); e.hasMoreElements();) { @@ -126,7 +126,7 @@ public class MailList { for (Enumeration e1 = mails.get().elements(); e1 .hasMoreElements();) { nextMail = (Mail) e1.nextElement(); - if (!(res.find(nextMail))) { + if (!(res.contains(nextMail))) { res.add(nextMail); } } diff --git a/src/main/java/fr/unantes/software/construction/address/Phone.java b/src/main/java/fr/unantes/software/construction/address/Phone.java index eef93155..677e1e5e 100755 --- a/src/main/java/fr/unantes/software/construction/address/Phone.java +++ b/src/main/java/fr/unantes/software/construction/address/Phone.java @@ -1,5 +1,6 @@ package fr.unantes.software.construction.address; +import java.util.Objects; import org.apache.commons.lang3.Validate; import javax.annotation.Nonnull; @@ -10,6 +11,7 @@ import javax.annotation.Nonnull; * @date 17/12/2004. */ public class Phone { + @Nonnull protected Integer phoneNumber; protected String comment; @@ -68,7 +70,11 @@ public class Phone { public String toXML() { return ("" + phoneNumber + comment + ""); } - + + public boolean sameNumberAs(Phone other){ + return this.phoneNumber.equals(other.phoneNumber); + } + public boolean equals(Object another){ if (this == another) return true; @@ -76,6 +82,7 @@ public class Phone { return false; Phone other = (Phone) another; - return (phoneNumber == other.phoneNumber) && comment.equals(other.comment); + return (phoneNumber.equals(other.phoneNumber)) && comment.equals(other.comment); } + } diff --git a/src/main/java/fr/unantes/software/construction/address/PhoneList.java b/src/main/java/fr/unantes/software/construction/address/PhoneList.java index 9c89b7c6..7bc8b51f 100755 --- a/src/main/java/fr/unantes/software/construction/address/PhoneList.java +++ b/src/main/java/fr/unantes/software/construction/address/PhoneList.java @@ -4,7 +4,7 @@ import org.apache.commons.lang3.Validate; import java.util.*; -public class PhoneList { +public class PhoneList { protected Vector phones; @@ -45,7 +45,7 @@ public class PhoneList { */ public void add(Phone phone) { Validate.notNull(phone); - if (!find(phone)) + if (!contains(phone)) phones.add(phone); // si existe deja faire la fusion des deux dans celle deja enregistrer // dans le vecteur. @@ -60,7 +60,7 @@ public class PhoneList { */ public void delete(Phone phone) { Validate.notNull(phone); - if (find(phone)) + if (contains(phone)) phones.remove(phone); else System.out.println("le telephone n'existe pas"); @@ -69,10 +69,10 @@ public class PhoneList { /** * @param phone c'est le telephone recherche */ - public boolean find(Phone phone) { + public boolean contains(Phone phone) { boolean res = false; for (Enumeration e = phones.elements(); e.hasMoreElements();) { - if (((Phone) e.nextElement()).getPhoneNumber() == phone.getPhoneNumber()) + if ( ((Phone) e.nextElement()).sameNumberAs(phone) ) res = true; } return res; @@ -103,7 +103,7 @@ public class PhoneList { for (Enumeration e1 = phones.get().elements(); e1 .hasMoreElements();) { nextPhone = (Phone) e1.nextElement(); - if (!(res.find(nextPhone))) { + if (!(res.contains(nextPhone))) { res.add(nextPhone); } } diff --git a/src/main/test/fr/unantes/software/construction/address/AddressBookTest.java b/src/main/test/fr/unantes/software/construction/address/AddressBookTest.java index 3f84064f..bb97a379 100644 --- a/src/main/test/fr/unantes/software/construction/address/AddressBookTest.java +++ b/src/main/test/fr/unantes/software/construction/address/AddressBookTest.java @@ -6,13 +6,13 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; class AddressBookTest { - CardList someList; + ListWrapper someList; Card someCard; AddressBook addressBook; @BeforeEach void setUp(){ - someList = new CardList(); + someList = new ListWrapper<>(); someCard = new PrivateCard("Chaussette","Louis"); someList.add(someCard); addressBook = new AddressBook(); @@ -22,7 +22,7 @@ class AddressBookTest { void testSetCards_ValidCardList_Succeed(){ assertDoesNotThrow(()->addressBook.setCards(someList)); - assertEquals(someList.find(someCard), addressBook.getCards().find(someCard)); + assertEquals(someList.contains(someCard), addressBook.getCards().contains(someCard)); } @Test @@ -34,7 +34,6 @@ class AddressBookTest { void testSetName_AnyStringValue_Suceed(){ assertDoesNotThrow(()->addressBook.setName("name")); assertEquals("name",addressBook.getName()); - } @Test @@ -42,7 +41,7 @@ class AddressBookTest { addressBook.setCards(someList); AddressBook anotherBook = new AddressBook(); - CardList anotherList = new CardList(); + ListWrapper anotherList = new ListWrapper<>(); Card anotherCard = new PrivateCard("Marco","Polo"); anotherList.add(anotherCard); @@ -51,8 +50,8 @@ class AddressBookTest { AddressBook mergedLists = addressBook.merge(anotherBook,"new name"); assertNotNull(mergedLists); - assertTrue(mergedLists.getCards().find(someCard)); - assertTrue(mergedLists.getCards().find(anotherCard)); + assertTrue(mergedLists.getCards().contains(someCard)); + assertTrue(mergedLists.getCards().contains(anotherCard)); assertEquals(2, mergedLists.getCards().get().size()); } @@ -62,7 +61,7 @@ class AddressBookTest { AddressBook mergedLists = addressBook.merge(addressBook,""); assertNotNull(mergedLists); - assertTrue(mergedLists.getCards().find(someCard)); + assertTrue(mergedLists.getCards().contains(someCard)); assertEquals(addressBook.getCards().get().size(), mergedLists.getCards().get().size()); } @@ -71,7 +70,7 @@ class AddressBookTest { addressBook.setCards(someList); AddressBook anotherBook = new AddressBook(); - CardList anotherList = new CardList(); + ListWrapper anotherList = new ListWrapper<>(); Card anotherCard = new PrivateCard("Marco","Polo"); anotherList.add(someCard); @@ -93,7 +92,7 @@ class AddressBookTest { AddressBook mergedLists = addressBook.merge(anotherBook,""); assertNotNull(mergedLists); - assertTrue(mergedLists.getCards().find(someCard)); + assertTrue(mergedLists.getCards().contains(someCard)); assertEquals(1, mergedLists.getCards().get().size()); } diff --git a/src/main/test/fr/unantes/software/construction/address/AddressListTest.java b/src/main/test/fr/unantes/software/construction/address/AddressListTest.java index 5d68e3fd..0a5d8fe6 100644 --- a/src/main/test/fr/unantes/software/construction/address/AddressListTest.java +++ b/src/main/test/fr/unantes/software/construction/address/AddressListTest.java @@ -1,5 +1,10 @@ package fr.unantes.software.construction.address; +import fr.unantes.software.construction.address.Address; +import fr.unantes.software.construction.address.AddressList; +import fr.unantes.software.construction.address.City; +import fr.unantes.software.construction.address.CompanyAddress; +import fr.unantes.software.construction.address.PrivateAddress; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -33,7 +38,7 @@ class AddressListTest { addressList.set(anotherList); for(Address each : addresses){ - assertTrue(addressList.find(each)); + assertTrue(addressList.contains(each)); } } @@ -46,7 +51,7 @@ class AddressListTest { @Test public void testAdd_newValue_Succeed(){ assertDoesNotThrow(() -> addressList.add(someAddress)); - assertTrue(addressList.find(someAddress)); + assertTrue(addressList.contains(someAddress)); } @Test @@ -70,7 +75,7 @@ class AddressListTest { addressList.add(someAddress); addressList.delete(someAddress); - assertFalse(addressList.find(someAddress)); + assertFalse(addressList.contains(someAddress)); } @Test @@ -79,23 +84,23 @@ class AddressListTest { anotherList.add(someAddress); int currentSize = addressList.get().size(); - assertFalse(addressList.find(someAddress)); + assertFalse(addressList.contains(someAddress)); addressList.delete(someAddress); - assertTrue(anotherList.find(someAddress)); + assertTrue(anotherList.contains(someAddress)); assertEquals(currentSize, addressList.get().size()); } @Test public void testFind_ContainedValue_ReturnTrue(){ addressList.add(someAddress); - assertTrue(addressList.find(someAddress)); + assertTrue(addressList.contains(someAddress)); } @Test public void testFind_NotContainedValue_ReturnFalse(){ addressList.add(new PrivateAddress(1,"Another Private Street", new City("Norvege","Honningsvag"),0,null)); - assertFalse(addressList.find(someAddress)); + assertFalse(addressList.contains(someAddress)); } @Test @@ -109,8 +114,8 @@ class AddressListTest { AddressList mergedLists = addressList.merge(anotherList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someAddress)); - assertTrue(mergedLists.find(anotherAddress)); + assertTrue(mergedLists.contains(someAddress)); + assertTrue(mergedLists.contains(anotherAddress)); assertEquals(2, mergedLists.get().size()); } @@ -121,7 +126,7 @@ class AddressListTest { AddressList mergedLists = addressList.merge(addressList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someAddress)); + assertTrue(mergedLists.contains(someAddress)); assertEquals(addressList.get().size(), mergedLists.get().size()); } @@ -151,7 +156,7 @@ class AddressListTest { AddressList mergedLists = addressList.merge(anotherList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someAddress)); + assertTrue(mergedLists.contains(someAddress)); assertEquals(1, mergedLists.get().size()); } diff --git a/src/main/test/fr/unantes/software/construction/address/CardListTest.java b/src/main/test/fr/unantes/software/construction/address/CardListTest.java index e2e0fbea..deadb2d7 100644 --- a/src/main/test/fr/unantes/software/construction/address/CardListTest.java +++ b/src/main/test/fr/unantes/software/construction/address/CardListTest.java @@ -1,5 +1,11 @@ package fr.unantes.software.construction.address; +import fr.unantes.software.construction.address.Card; +import fr.unantes.software.construction.address.CompanyCard; +import fr.unantes.software.construction.address.ListWrapper; +import fr.unantes.software.construction.address.PrivateCard; +import java.util.ArrayList; +import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -8,17 +14,17 @@ import java.util.Vector; import static org.junit.jupiter.api.Assertions.*; class CardListTest { - CardList cardList; + ListWrapper cardList; Card someCard; @BeforeEach void setUp() { - cardList = new CardList(); + cardList = new ListWrapper(); someCard = new PrivateCard("John","Doe"); } @Test void testSet_ListOfCards_addCardsToCurrentList(){ - Vector anotherList = new Vector(); + Vector anotherList = new Vector<>(); Card[] cards = { someCard, new PrivateCard("Tom","Joe"), new CompanyCard("JohnDoe Corp.") @@ -31,7 +37,7 @@ class CardListTest { cardList.set(anotherList); for(Card each : cards){ - assertTrue(cardList.find(each)); + assertTrue(cardList.contains(each)); } } @@ -44,7 +50,7 @@ class CardListTest { @Test public void testAdd_newValue_Succeed(){ assertDoesNotThrow(() -> cardList.add(someCard)); - assertTrue(cardList.find(someCard)); + assertTrue(cardList.contains(someCard)); } @Test @@ -68,32 +74,32 @@ class CardListTest { cardList.add(someCard); cardList.delete(someCard); - assertFalse(cardList.find(someCard)); + assertFalse(cardList.contains(someCard)); } @Test public void testDelete_ValueContainedByAnotherGroup_NoEffect(){ - CardList anotherList = new CardList(); + ListWrapper anotherList = new ListWrapper(); anotherList.add(someCard); int currentSize = cardList.get().size(); - assertFalse(cardList.find(someCard)); + assertFalse(cardList.contains(someCard)); cardList.delete(someCard); - assertTrue(anotherList.find(someCard)); + assertTrue(anotherList.contains(someCard)); assertEquals(currentSize, cardList.get().size()); } @Test public void testFind_ContainedValue_ReturnTrue(){ cardList.add(someCard); - assertTrue(cardList.find(someCard)); + assertTrue(cardList.contains(someCard)); } @Test public void testFind_NotContainedValue_ReturnFalse(){ cardList.add(new PrivateCard("Tom","Joe")); - assertFalse(cardList.find(someCard)); + assertFalse(cardList.contains(someCard)); } @Test @@ -101,14 +107,14 @@ class CardListTest { cardList.add(someCard); Card anotherCard = new PrivateCard("Tom", "Joe"); - CardList anotherList = new CardList(); + ListWrapper anotherList = new ListWrapper(); anotherList.add(anotherCard); - CardList mergedLists = cardList.merge(anotherList); + ListWrapper mergedLists = cardList.merge(anotherList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someCard)); - assertTrue(mergedLists.find(anotherCard)); + assertTrue(mergedLists.contains(someCard)); + assertTrue(mergedLists.contains(anotherCard)); assertEquals(2, mergedLists.get().size()); } @@ -116,10 +122,10 @@ class CardListTest { public void testMerge_SameLists_NoChange(){ cardList.add(someCard); - CardList mergedLists = cardList.merge(cardList); + ListWrapper mergedLists = cardList.merge(cardList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someCard)); + assertTrue(mergedLists.contains(someCard)); assertEquals(cardList.get().size(), mergedLists.get().size()); } @@ -130,10 +136,10 @@ class CardListTest { cardList.add(someCard); cardList.add(anotherCard); - CardList anotherList = new CardList(); + ListWrapper anotherList = new ListWrapper(); anotherList.add(anotherCard); - CardList mergedLists = cardList.merge(anotherList); + ListWrapper mergedLists = cardList.merge(anotherList); assertNotNull(mergedLists); assertEquals(2, mergedLists.get().size()); @@ -142,14 +148,14 @@ class CardListTest { } @Test public void testMerge_EmptyCardList_SameCardList(){ - CardList anotherList = new CardList(); + ListWrapper anotherList = new ListWrapper(); cardList.add(someCard); - CardList mergedLists = cardList.merge(anotherList); + ListWrapper mergedLists = cardList.merge(anotherList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someCard)); + assertTrue(mergedLists.contains(someCard)); assertEquals(1, mergedLists.get().size()); } diff --git a/src/main/test/fr/unantes/software/construction/address/CompanyCardTest.java b/src/main/test/fr/unantes/software/construction/address/CompanyCardTest.java index 8e745aa0..e84ffa4c 100644 --- a/src/main/test/fr/unantes/software/construction/address/CompanyCardTest.java +++ b/src/main/test/fr/unantes/software/construction/address/CompanyCardTest.java @@ -2,26 +2,25 @@ package fr.unantes.software.construction.address; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.mockito.internal.matchers.Null; import static org.junit.jupiter.api.Assertions.*; class CompanyCardTest { CompanyCard companyCard; - AddressList someAddresses; CompanyAddress anAddress; + ListWrapper
someAddresses; CompanyAddress anAddress; PhoneList somePhones; Phone aPhone; MailList someMails; Mail aMail; - GroupList someGroups; Group aGroup; + ListWrapper someGroups; Group aGroup; @BeforeEach void setUp() { companyCard = new CompanyCard("companyName"); - someAddresses = new AddressList(); + someAddresses = new ListWrapper
(); somePhones = new PhoneList(); someMails = new MailList(); - someGroups = new GroupList(); + someGroups = new ListWrapper(); anAddress = new CompanyAddress(1, "Some Company Street", new City("Groenland", "Qeqertarsuaq"), 0, null,null); someAddresses.add(anAddress); @@ -42,7 +41,7 @@ class CompanyCardTest { */ @Test void testSetAddresses_SomeAddressList_Succeed(){ - AddressList someList = new AddressList(); + ListWrapper
someList = new ListWrapper
(); companyCard.setAddresses(someList); assertEquals(someList, companyCard.getAddresses()); @@ -84,7 +83,7 @@ class CompanyCardTest { @Test void testSetGroups_SomeGroupList_Succeed(){ - GroupList someList = new GroupList(); + ListWrapper someList = new ListWrapper(); companyCard.setGroups(someList); assertEquals(someList, companyCard.getGroups()); @@ -146,10 +145,10 @@ class CompanyCardTest { void testMerge_CompanyCardWithSameId_ReturnPrivateCardWithBothValues(){ CompanyCard anotherCard = new CompanyCard("companyName"); - AddressList anotherAddresses = new AddressList(); + ListWrapper
anotherAddresses = new ListWrapper
(); PhoneList anotherPhones = new PhoneList(); MailList anotherMails = new MailList(); - GroupList anotherGroups = new GroupList(); + ListWrapper anotherGroups = new ListWrapper(); CompanyAddress anotherAddress = new CompanyAddress(1, "Another Company Street", new City("France", "Angouleme"), 16000, null,null); anotherAddresses.add(anotherAddress); @@ -166,16 +165,16 @@ class CompanyCardTest { CompanyCard mergedCard = (CompanyCard) companyCard.merge(anotherCard); - assertTrue(mergedCard.getAddresses().find(anAddress)); - assertTrue(mergedCard.getAddresses().find(anotherAddress)); + assertTrue(mergedCard.getAddresses().contains(anAddress)); + assertTrue(mergedCard.getAddresses().contains(anotherAddress)); assertEquals(2,mergedCard.getAddresses().get().size()); - assertTrue(mergedCard.getPhones().find(aPhone)); - assertTrue(mergedCard.getPhones().find(anotherPhone)); + assertTrue(mergedCard.getPhones().contains(aPhone)); + assertTrue(mergedCard.getPhones().contains(anotherPhone)); assertEquals(2,mergedCard.getPhones().get().size()); - assertTrue(mergedCard.getMails().find(aMail)); - assertTrue(mergedCard.getMails().find(anotherMail)); + assertTrue(mergedCard.getMails().contains(aMail)); + assertTrue(mergedCard.getMails().contains(anotherMail)); assertEquals(2,mergedCard.getMails().get().size()); assertTrue(mergedCard.getGroups().find(aGroup)); @@ -189,13 +188,13 @@ class CompanyCardTest { void testMerge_SameCompanyCard_NoChange(){ CompanyCard mergedCard = (CompanyCard) companyCard.merge(companyCard); - assertTrue(mergedCard.getAddresses().find(anAddress)); + assertTrue(mergedCard.getAddresses().contains(anAddress)); assertEquals(1,mergedCard.getAddresses().get().size()); - assertTrue(mergedCard.getPhones().find(aPhone)); + assertTrue(mergedCard.getPhones().contains(aPhone)); assertEquals(1,mergedCard.getPhones().get().size()); - assertTrue(mergedCard.getMails().find(aMail)); + assertTrue(mergedCard.getMails().contains(aMail)); assertEquals(1,mergedCard.getMails().get().size()); assertTrue(mergedCard.getGroups().find(aGroup)); @@ -206,10 +205,10 @@ class CompanyCardTest { void testMerge_CompanyCardsWithSharedValues_NoDuplicate(){ CompanyCard anotherCard = new CompanyCard("companyName"); - AddressList anotherAddresses = new AddressList(); + ListWrapper
anotherAddresses = new ListWrapper
(); PhoneList anotherPhones = new PhoneList(); MailList anotherMails = new MailList(); - GroupList anotherGroups = new GroupList(); + ListWrapper anotherGroups = new ListWrapper(); CompanyAddress anotherAddress = new CompanyAddress(1, "Another Private Street", new City("France", "Angouleme"), 16000, null,null); Phone anotherPhone = new Phone(0642424242, ""); Mail anotherMail = new Mail("anotherHome@mail.com", null); @@ -231,16 +230,16 @@ class CompanyCardTest { CompanyCard mergedCard = (CompanyCard) companyCard.merge(anotherCard); - assertTrue(mergedCard.getAddresses().find(anAddress)); - assertTrue(mergedCard.getAddresses().find(anotherAddress)); + assertTrue(mergedCard.getAddresses().contains(anAddress)); + assertTrue(mergedCard.getAddresses().contains(anotherAddress)); assertEquals(2,mergedCard.getAddresses().get().size()); - assertTrue(mergedCard.getPhones().find(aPhone)); - assertTrue(mergedCard.getPhones().find(anotherPhone)); + assertTrue(mergedCard.getPhones().contains(aPhone)); + assertTrue(mergedCard.getPhones().contains(anotherPhone)); assertEquals(2,mergedCard.getPhones().get().size()); - assertTrue(mergedCard.getMails().find(aMail)); - assertTrue(mergedCard.getMails().find(anotherMail)); + assertTrue(mergedCard.getMails().contains(aMail)); + assertTrue(mergedCard.getMails().contains(anotherMail)); assertEquals(2,mergedCard.getMails().get().size()); assertTrue(mergedCard.getGroups().find(aGroup)); diff --git a/src/main/test/fr/unantes/software/construction/address/GroupListTest.java b/src/main/test/fr/unantes/software/construction/address/GroupListTest.java index e631a9b7..a89fd993 100644 --- a/src/main/test/fr/unantes/software/construction/address/GroupListTest.java +++ b/src/main/test/fr/unantes/software/construction/address/GroupListTest.java @@ -1,5 +1,7 @@ package fr.unantes.software.construction.address; +import fr.unantes.software.construction.address.Group; +import fr.unantes.software.construction.address.GroupList; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.internal.matchers.Null; diff --git a/src/main/test/fr/unantes/software/construction/address/MailListTest.java b/src/main/test/fr/unantes/software/construction/address/MailListTest.java index c4b7f471..08936a42 100644 --- a/src/main/test/fr/unantes/software/construction/address/MailListTest.java +++ b/src/main/test/fr/unantes/software/construction/address/MailListTest.java @@ -34,7 +34,7 @@ class MailListTest { mailList.set(anotherList); for(Mail each : mails){ - assertTrue(mailList.find(each)); + assertTrue(mailList.contains(each)); } } @@ -47,7 +47,7 @@ class MailListTest { void testAdd_NewMail_addMailToList(){ mailList.add(someMail); - assertTrue(mailList.find(someMail)); + assertTrue(mailList.contains(someMail)); } @Test @@ -60,7 +60,7 @@ class MailListTest { mailList.add(oneMail); mailList.add(anotherMail); - assertTrue(mailList.find(oneMail)); + assertTrue(mailList.contains(oneMail)); assertEquals("anotherWork@mail.com", oneMail.getWork()); assertEquals("someHome@mail.com",oneMail.getHome()); assertEquals(1,mailList.size()); @@ -76,7 +76,7 @@ class MailListTest { mailList.add(oneMail); mailList.add(anotherMail); - assertTrue(mailList.find(oneMail)); + assertTrue(mailList.contains(oneMail)); assertEquals("someWork@mail.com", oneMail.getWork()); assertNotEquals("anotherHome@mail.com",oneMail.getHome()); assertEquals(2,mailList.size()); @@ -92,7 +92,7 @@ class MailListTest { mailList.add(someMail); mailList.delete(someMail); - assertFalse(mailList.find(someMail)); + assertFalse(mailList.contains(someMail)); assertEquals(0,mailList.size()); } @@ -106,10 +106,10 @@ class MailListTest { mailList.delete(anotherMail); - assertTrue(mailList.find(someMail)); - assertFalse(mailList.find(anotherMail)); + assertTrue(mailList.contains(someMail)); + assertFalse(mailList.contains(anotherMail)); - assertTrue(anotherList.find(anotherMail)); + assertTrue(anotherList.contains(anotherMail)); assertEquals(1,anotherList.size()); } @@ -123,7 +123,7 @@ class MailListTest { Mail anotherMail = new Mail("anotherHome@mail.com","anotherWork@mail.com"); mailList.add(someMail); - assertFalse(mailList.find(anotherMail)); + assertFalse(mailList.contains(anotherMail)); } @Test @@ -131,7 +131,7 @@ class MailListTest { Mail anotherMail = new Mail("someHome@mail.com","anotherWork@mail.com"); mailList.add(someMail); - assertTrue(mailList.find(anotherMail)); + assertTrue(mailList.contains(anotherMail)); } @Test @@ -139,7 +139,7 @@ class MailListTest { Mail anotherMail = new Mail("anotherHome@mail.com","someWork@mail.com"); mailList.add(someMail); - assertFalse(mailList.find(anotherMail)); + assertFalse(mailList.contains(anotherMail)); } @Test @@ -153,8 +153,8 @@ class MailListTest { MailList mergedLists = mailList.merge(anotherList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someMail)); - assertTrue(mergedLists.find(anotherMail)); + assertTrue(mergedLists.contains(someMail)); + assertTrue(mergedLists.contains(anotherMail)); assertEquals(2, mergedLists.size()); } @@ -165,7 +165,7 @@ class MailListTest { MailList mergedLists = mailList.merge(mailList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someMail)); + assertTrue(mergedLists.contains(someMail)); assertEquals(mailList.size(), mergedLists.size()); } @@ -196,7 +196,7 @@ class MailListTest { MailList mergedLists = mailList.merge(anotherList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someMail)); + assertTrue(mergedLists.contains(someMail)); assertEquals(1, mergedLists.size()); } diff --git a/src/main/test/fr/unantes/software/construction/address/PhoneListTest.java b/src/main/test/fr/unantes/software/construction/address/PhoneListTest.java index 536d375e..95909529 100644 --- a/src/main/test/fr/unantes/software/construction/address/PhoneListTest.java +++ b/src/main/test/fr/unantes/software/construction/address/PhoneListTest.java @@ -32,7 +32,7 @@ class PhoneListTest { phoneList.set(anotherList); for(Phone each : phones){ - assertTrue(phoneList.find(each)); + assertTrue(phoneList.contains(each)); } } @@ -45,7 +45,7 @@ class PhoneListTest { void testAdd_NewPhone_addPhoneToList(){ phoneList.add(somePhone); - assertTrue(phoneList.find(somePhone)); + assertTrue(phoneList.contains(somePhone)); } @Test @@ -56,7 +56,7 @@ class PhoneListTest { phoneList.add(onePhone); phoneList.add(anotherPhone); - assertTrue(phoneList.find(onePhone)); + assertTrue(phoneList.contains(onePhone)); assertEquals(1,phoneList.get().size()); } @@ -70,7 +70,7 @@ class PhoneListTest { phoneList.add(somePhone); phoneList.delete(somePhone); - assertFalse(phoneList.find(somePhone)); + assertFalse(phoneList.contains(somePhone)); assertEquals(0,phoneList.get().size()); } @@ -84,10 +84,10 @@ class PhoneListTest { phoneList.delete(anotherPhone); - assertTrue(phoneList.find(somePhone)); - assertFalse(phoneList.find(anotherPhone)); + assertTrue(phoneList.contains(somePhone)); + assertFalse(phoneList.contains(anotherPhone)); - assertTrue(anotherList.find(anotherPhone)); + assertTrue(anotherList.contains(anotherPhone)); assertEquals(1,anotherList.get().size()); } @@ -101,7 +101,7 @@ class PhoneListTest { Phone anotherPhone = new Phone(0606060606,"another comment"); phoneList.add(somePhone); - assertFalse(phoneList.find(anotherPhone)); + assertFalse(phoneList.contains(anotherPhone)); } @Test @@ -109,7 +109,7 @@ class PhoneListTest { Phone anotherPhone = new Phone(somePhone.getPhoneNumber(),"another comment"); phoneList.add(somePhone); - assertTrue(phoneList.find(anotherPhone)); + assertTrue(phoneList.contains(anotherPhone)); } @@ -124,8 +124,8 @@ class PhoneListTest { PhoneList mergedLists = phoneList.merge(anotherList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(somePhone)); - assertTrue(mergedLists.find(anotherPhone)); + assertTrue(mergedLists.contains(somePhone)); + assertTrue(mergedLists.contains(anotherPhone)); assertEquals(2, mergedLists.get().size()); } @@ -136,7 +136,7 @@ class PhoneListTest { PhoneList mergedLists = phoneList.merge(phoneList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(somePhone)); + assertTrue(mergedLists.contains(somePhone)); assertEquals(phoneList.get().size(), mergedLists.get().size()); } @@ -167,7 +167,7 @@ class PhoneListTest { PhoneList mergedLists = phoneList.merge(anotherList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(somePhone)); + assertTrue(mergedLists.contains(somePhone)); assertEquals(1, mergedLists.get().size()); } diff --git a/src/main/test/fr/unantes/software/construction/address/PrivateCardTest.java b/src/main/test/fr/unantes/software/construction/address/PrivateCardTest.java index 2233af30..532a7396 100644 --- a/src/main/test/fr/unantes/software/construction/address/PrivateCardTest.java +++ b/src/main/test/fr/unantes/software/construction/address/PrivateCardTest.java @@ -8,20 +8,20 @@ import static org.junit.jupiter.api.Assertions.*; class PrivateCardTest { PrivateCard someCard; - AddressList someAddresses; PrivateAddress anAddress; + ListWrapper
someAddresses; PrivateAddress anAddress; PhoneList somePhones; Phone aPhone; MailList someMails; Mail aMail; - GroupList someGroups; Group aGroup; + ListWrapper someGroups; Group aGroup; @BeforeEach void setUp() { someCard = new PrivateCard("000"); - someAddresses = new AddressList(); + someAddresses = new ListWrapper
(); somePhones = new PhoneList(); someMails = new MailList(); - someGroups = new GroupList(); + someGroups = new ListWrapper(); anAddress = new PrivateAddress(1, "Some Private Street", new City("Groenland", "Qeqertarsuaq"), 0, null); someAddresses.add(anAddress); @@ -42,7 +42,7 @@ class PrivateCardTest { */ @Test void testSetAddresses_SomeAddressList_Succeed(){ - AddressList someList = new AddressList(); + ListWrapper
someList = new ListWrapper
(); someCard.setAddresses(someList); assertEquals(someList,someCard.getAddresses()); @@ -84,7 +84,7 @@ class PrivateCardTest { @Test void testSetGroups_SomeGroupList_Succeed(){ - GroupList someList = new GroupList(); + ListWrapper someList = new ListWrapper(); someCard.setGroups(someList); assertEquals(someList,someCard.getGroups()); @@ -152,10 +152,10 @@ class PrivateCardTest { void testMerge_PrivateCardWithSameId_ReturnPrivateCardWithBothValues(){ PrivateCard anotherCard = new PrivateCard("000"); - AddressList anotherAddresses = new AddressList(); + ListWrapper
anotherAddresses = new ListWrapper
(); PhoneList anotherPhones = new PhoneList(); MailList anotherMails = new MailList(); - GroupList anotherGroups = new GroupList(); + ListWrapper anotherGroups = new ListWrapper(); PrivateAddress anotherAddress = new PrivateAddress(1, "Another Private Street", new City("France", "Angouleme"), 16000, null); anotherAddresses.add(anotherAddress); @@ -172,16 +172,16 @@ class PrivateCardTest { PrivateCard mergedCard = (PrivateCard) someCard.merge(anotherCard); - assertTrue(mergedCard.getAddresses().find(anAddress)); - assertTrue(mergedCard.getAddresses().find(anotherAddress)); + assertTrue(mergedCard.getAddresses().contains(anAddress)); + assertTrue(mergedCard.getAddresses().contains(anotherAddress)); assertEquals(2,mergedCard.getAddresses().get().size()); - assertTrue(mergedCard.getPhones().find(aPhone)); - assertTrue(mergedCard.getPhones().find(anotherPhone)); + assertTrue(mergedCard.getPhones().contains(aPhone)); + assertTrue(mergedCard.getPhones().contains(anotherPhone)); assertEquals(2,mergedCard.getPhones().get().size()); - assertTrue(mergedCard.getMails().find(aMail)); - assertTrue(mergedCard.getMails().find(anotherMail)); + assertTrue(mergedCard.getMails().contains(aMail)); + assertTrue(mergedCard.getMails().contains(anotherMail)); assertEquals(2,mergedCard.getMails().get().size()); assertTrue(mergedCard.getGroups().find(aGroup)); @@ -195,13 +195,13 @@ class PrivateCardTest { void testMerge_SamePrivateCard_NoChange(){ PrivateCard mergedCard = (PrivateCard) someCard.merge(someCard); - assertTrue(mergedCard.getAddresses().find(anAddress)); + assertTrue(mergedCard.getAddresses().contains(anAddress)); assertEquals(1,mergedCard.getAddresses().get().size()); - assertTrue(mergedCard.getPhones().find(aPhone)); + assertTrue(mergedCard.getPhones().contains(aPhone)); assertEquals(1,mergedCard.getPhones().get().size()); - assertTrue(mergedCard.getMails().find(aMail)); + assertTrue(mergedCard.getMails().contains(aMail)); assertEquals(1,mergedCard.getMails().get().size()); assertTrue(mergedCard.getGroups().find(aGroup)); @@ -212,10 +212,10 @@ class PrivateCardTest { void testMerge_PrivateCardsWithSharedValues_NoDuplicate(){ PrivateCard anotherCard = new PrivateCard("000"); - AddressList anotherAddresses = new AddressList(); + ListWrapper
anotherAddresses = new ListWrapper
(); PhoneList anotherPhones = new PhoneList(); MailList anotherMails = new MailList(); - GroupList anotherGroups = new GroupList(); + ListWrapper anotherGroups = new ListWrapper(); PrivateAddress anotherAddress = new PrivateAddress(1, "Another Private Street", new City("France", "Angouleme"), 16000, null); Phone anotherPhone = new Phone(0642424242, ""); Mail anotherMail = new Mail("anotherHome@mail.com", null); @@ -237,16 +237,16 @@ class PrivateCardTest { PrivateCard mergedCard = (PrivateCard) someCard.merge(anotherCard); - assertTrue(mergedCard.getAddresses().find(anAddress)); - assertTrue(mergedCard.getAddresses().find(anotherAddress)); + assertTrue(mergedCard.getAddresses().contains(anAddress)); + assertTrue(mergedCard.getAddresses().contains(anotherAddress)); assertEquals(2,mergedCard.getAddresses().get().size()); - assertTrue(mergedCard.getPhones().find(aPhone)); - assertTrue(mergedCard.getPhones().find(anotherPhone)); + assertTrue(mergedCard.getPhones().contains(aPhone)); + assertTrue(mergedCard.getPhones().contains(anotherPhone)); assertEquals(2,mergedCard.getPhones().get().size()); - assertTrue(mergedCard.getMails().find(aMail)); - assertTrue(mergedCard.getMails().find(anotherMail)); + assertTrue(mergedCard.getMails().contains(aMail)); + assertTrue(mergedCard.getMails().contains(anotherMail)); assertEquals(2,mergedCard.getMails().get().size()); assertTrue(mergedCard.getGroups().find(aGroup)); diff --git a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfAddressTest.java b/src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperAddressTest.java similarity index 75% rename from src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfAddressTest.java rename to src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperAddressTest.java index 9353da88..91947881 100644 --- a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfAddressTest.java +++ b/src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperAddressTest.java @@ -1,4 +1,4 @@ -package fr.unantes.software.construction.address.nonRegression; +package fr.unantes.software.construction.address.wrapper; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -10,20 +10,21 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import fr.unantes.software.construction.address.Address; import fr.unantes.software.construction.address.City; import fr.unantes.software.construction.address.CompanyAddress; +import fr.unantes.software.construction.address.ListWrapper; import fr.unantes.software.construction.address.PrivateAddress; import java.util.ArrayList; import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -class ListOfAddressTest { +class ListWrapperAddressTest { - ListOf
addressList; + ListWrapper
addressList; Address someAddress; @BeforeEach void setUp() { - addressList = new ListOf<>(); + addressList = new ListWrapper<>(); someAddress = new PrivateAddress(1,"Some Private Street", new City("Groenland","Qeqertarsuaq"),0,null); } @@ -42,7 +43,7 @@ class ListOfAddressTest { addressList.set(anotherList); for(Address each : addresses){ - assertTrue(addressList.find(each)); + assertTrue(addressList.contains(each)); } } @@ -55,7 +56,7 @@ class ListOfAddressTest { @Test public void testAdd_newValue_Succeed(){ assertDoesNotThrow(() -> addressList.add(someAddress)); - assertTrue(addressList.find(someAddress)); + assertTrue(addressList.contains(someAddress)); } @Test @@ -79,32 +80,32 @@ class ListOfAddressTest { addressList.add(someAddress); addressList.delete(someAddress); - assertFalse(addressList.find(someAddress)); + assertFalse(addressList.contains(someAddress)); } @Test public void testDelete_ValueContainedByAnotherGroup_NoEffect(){ - ListOf
anotherList = new ListOf<>(); + ListWrapper
anotherList = new ListWrapper<>(); anotherList.add(someAddress); int currentSize = addressList.get().size(); - assertFalse(addressList.find(someAddress)); + assertFalse(addressList.contains(someAddress)); addressList.delete(someAddress); - assertTrue(anotherList.find(someAddress)); + assertTrue(anotherList.contains(someAddress)); assertEquals(currentSize, addressList.get().size()); } @Test public void testFind_ContainedValue_ReturnTrue(){ addressList.add(someAddress); - assertTrue(addressList.find(someAddress)); + assertTrue(addressList.contains(someAddress)); } @Test public void testFind_NotContainedValue_ReturnFalse(){ addressList.add(new PrivateAddress(1,"Another Private Street", new City("Norvege","Honningsvag"),0,null)); - assertFalse(addressList.find(someAddress)); + assertFalse(addressList.contains(someAddress)); } @Test @@ -112,14 +113,14 @@ class ListOfAddressTest { addressList.add(someAddress); Address anotherAddress = new PrivateAddress(1,"Another Private Street", new City("Norvege","Honningsvag"),0,null); - ListOf
anotherList = new ListOf<>(); + ListWrapper
anotherList = new ListWrapper<>(); anotherList.add(anotherAddress); - ListOf
mergedLists = addressList.merge(anotherList); + ListWrapper
mergedLists = addressList.merge(anotherList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someAddress)); - assertTrue(mergedLists.find(anotherAddress)); + assertTrue(mergedLists.contains(someAddress)); + assertTrue(mergedLists.contains(anotherAddress)); assertEquals(2, mergedLists.get().size()); } @@ -127,10 +128,10 @@ class ListOfAddressTest { public void testMerge_SameLists_NoChange(){ addressList.add(someAddress); - ListOf
mergedLists = addressList.merge(addressList); + ListWrapper
mergedLists = addressList.merge(addressList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someAddress)); + assertTrue(mergedLists.contains(someAddress)); assertEquals(addressList.get().size(), mergedLists.get().size()); } @@ -141,10 +142,10 @@ class ListOfAddressTest { addressList.add(someAddress); addressList.add(anotherAddress); - ListOf
anotherList = new ListOf<>(); + ListWrapper
anotherList = new ListWrapper<>(); anotherList.add(anotherAddress); - ListOf
mergedLists = addressList.merge(anotherList); + ListWrapper
mergedLists = addressList.merge(anotherList); assertNotNull(mergedLists); assertEquals(2, mergedLists.get().size()); @@ -153,14 +154,14 @@ class ListOfAddressTest { } @Test public void testMerge_EmptyGroupList_SameGroupList(){ - ListOf
anotherList = new ListOf<>(); + ListWrapper
anotherList = new ListWrapper<>(); addressList.add(someAddress); - ListOf
mergedLists = addressList.merge(anotherList); + ListWrapper
mergedLists = addressList.merge(anotherList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someAddress)); + assertTrue(mergedLists.contains(someAddress)); assertEquals(1, mergedLists.get().size()); } diff --git a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfCardTest.java b/src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperCardTest.java similarity index 74% rename from src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfCardTest.java rename to src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperCardTest.java index f0a234c7..c0fac659 100644 --- a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfCardTest.java +++ b/src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperCardTest.java @@ -1,4 +1,4 @@ -package fr.unantes.software.construction.address.nonRegression; +package fr.unantes.software.construction.address.wrapper; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -9,18 +9,19 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import fr.unantes.software.construction.address.Card; import fr.unantes.software.construction.address.CompanyCard; +import fr.unantes.software.construction.address.ListWrapper; import fr.unantes.software.construction.address.PrivateCard; import java.util.ArrayList; import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -class ListOfCardTest { - ListOf cardList; +class ListWrapperCardTest { + ListWrapper cardList; Card someCard; @BeforeEach void setUp() { - cardList = new ListOf<>(); + cardList = new ListWrapper<>(); someCard = new PrivateCard("John","Doe"); } @@ -39,7 +40,7 @@ class ListOfCardTest { cardList.set(anotherList); for(Card each : cards){ - assertTrue(cardList.find(each)); + assertTrue(cardList.contains(each)); } } @@ -52,7 +53,7 @@ class ListOfCardTest { @Test public void testAdd_newValue_Succeed(){ assertDoesNotThrow(() -> cardList.add(someCard)); - assertTrue(cardList.find(someCard)); + assertTrue(cardList.contains(someCard)); } @Test @@ -76,32 +77,32 @@ class ListOfCardTest { cardList.add(someCard); cardList.delete(someCard); - assertFalse(cardList.find(someCard)); + assertFalse(cardList.contains(someCard)); } @Test public void testDelete_ValueContainedByAnotherGroup_NoEffect(){ - ListOf anotherList = new ListOf<>(); + ListWrapper anotherList = new ListWrapper<>(); anotherList.add(someCard); int currentSize = cardList.get().size(); - assertFalse(cardList.find(someCard)); + assertFalse(cardList.contains(someCard)); cardList.delete(someCard); - assertTrue(anotherList.find(someCard)); + assertTrue(anotherList.contains(someCard)); assertEquals(currentSize, cardList.get().size()); } @Test public void testFind_ContainedValue_ReturnTrue(){ cardList.add(someCard); - assertTrue(cardList.find(someCard)); + assertTrue(cardList.contains(someCard)); } @Test public void testFind_NotContainedValue_ReturnFalse(){ cardList.add(new PrivateCard("Tom","Joe")); - assertFalse(cardList.find(someCard)); + assertFalse(cardList.contains(someCard)); } @Test @@ -109,14 +110,14 @@ class ListOfCardTest { cardList.add(someCard); Card anotherCard = new PrivateCard("Tom", "Joe"); - ListOf anotherList = new ListOf<>(); + ListWrapper anotherList = new ListWrapper<>(); anotherList.add(anotherCard); - ListOf mergedLists = cardList.merge(anotherList); + ListWrapper mergedLists = cardList.merge(anotherList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someCard)); - assertTrue(mergedLists.find(anotherCard)); + assertTrue(mergedLists.contains(someCard)); + assertTrue(mergedLists.contains(anotherCard)); assertEquals(2, mergedLists.get().size()); } @@ -124,10 +125,10 @@ class ListOfCardTest { public void testMerge_SameLists_NoChange(){ cardList.add(someCard); - ListOf mergedLists = cardList.merge(cardList); + ListWrapper mergedLists = cardList.merge(cardList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someCard)); + assertTrue(mergedLists.contains(someCard)); assertEquals(cardList.get().size(), mergedLists.get().size()); } @@ -138,10 +139,10 @@ class ListOfCardTest { cardList.add(someCard); cardList.add(anotherCard); - ListOf anotherList = new ListOf<>(); + ListWrapper anotherList = new ListWrapper<>(); anotherList.add(anotherCard); - ListOf mergedLists = cardList.merge(anotherList); + ListWrapper mergedLists = cardList.merge(anotherList); assertNotNull(mergedLists); assertEquals(2, mergedLists.get().size()); @@ -150,14 +151,14 @@ class ListOfCardTest { } @Test public void testMerge_EmptyCardList_SameCardList(){ - ListOf anotherList = new ListOf<>(); + ListWrapper anotherList = new ListWrapper<>(); cardList.add(someCard); - ListOf mergedLists = cardList.merge(anotherList); + ListWrapper mergedLists = cardList.merge(anotherList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someCard)); + assertTrue(mergedLists.contains(someCard)); assertEquals(1, mergedLists.get().size()); } diff --git a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfGroupTest.java b/src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperGroupTest.java similarity index 72% rename from src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfGroupTest.java rename to src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperGroupTest.java index 022ff480..cd9e6c65 100644 --- a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfGroupTest.java +++ b/src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperGroupTest.java @@ -1,4 +1,4 @@ -package fr.unantes.software.construction.address.nonRegression; +package fr.unantes.software.construction.address.wrapper; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -8,18 +8,19 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import fr.unantes.software.construction.address.Group; +import fr.unantes.software.construction.address.ListWrapper; import java.util.Vector; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -class ListOfGroupTest { +class ListWrapperGroupTest { - ListOf groupList; + ListWrapper groupList; Group someGroup; @BeforeEach void setUp() { - groupList = new ListOf(); + groupList = new ListWrapper(); someGroup = new Group("a Group",""); } @@ -38,7 +39,7 @@ class ListOfGroupTest { groupList.set(anotherList); for(Group each : groups){ - assertTrue(groupList.find(each)); + assertTrue(groupList.contains(each)); } } @@ -51,7 +52,7 @@ class ListOfGroupTest { @Test public void testAdd_newValue_Succeed(){ assertDoesNotThrow(() -> groupList.add(someGroup)); - assertTrue(groupList.find(someGroup)); + assertTrue(groupList.contains(someGroup)); } @Test @@ -75,32 +76,32 @@ class ListOfGroupTest { groupList.add(someGroup); groupList.delete(someGroup); - assertFalse(groupList.find(someGroup)); + assertFalse(groupList.contains(someGroup)); } @Test public void testDelete_ValueContainedByAnotherGroup_NoEffect(){ - ListOf anotherList = new ListOf(); + ListWrapper anotherList = new ListWrapper(); anotherList.add(someGroup); int currentSize = groupList.size(); - assertFalse(groupList.find(someGroup)); + assertFalse(groupList.contains(someGroup)); groupList.delete(someGroup); - assertTrue(anotherList.find(someGroup)); + assertTrue(anotherList.contains(someGroup)); assertEquals(currentSize, groupList.size()); } @Test public void testFind_ContainedValue_ReturnTrue(){ groupList.add(someGroup); - assertTrue(groupList.find(someGroup)); + assertTrue(groupList.contains(someGroup)); } @Test public void testFind_NotContainedValue_ReturnFalse(){ groupList.add(new Group("anotherGroup", "")); - assertFalse(groupList.find(someGroup)); + assertFalse(groupList.contains(someGroup)); } @Test @@ -108,14 +109,14 @@ class ListOfGroupTest { groupList.add(someGroup); Group anotherGroup = new Group("secondGroup", ""); - ListOf anotherList = new ListOf(); + ListWrapper anotherList = new ListWrapper(); anotherList.add(anotherGroup); - ListOf mergedLists = groupList.merge(anotherList); + ListWrapper mergedLists = groupList.merge(anotherList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someGroup)); - assertTrue(mergedLists.find(anotherGroup)); + assertTrue(mergedLists.contains(someGroup)); + assertTrue(mergedLists.contains(anotherGroup)); assertEquals(2, mergedLists.size()); } @@ -123,10 +124,10 @@ class ListOfGroupTest { public void testMerge_SameLists_NoChange(){ groupList.add(someGroup); - ListOf mergedLists = groupList.merge(groupList); + ListWrapper mergedLists = groupList.merge(groupList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someGroup)); + assertTrue(mergedLists.contains(someGroup)); assertEquals(groupList.size(), mergedLists.size()); } @@ -137,10 +138,10 @@ class ListOfGroupTest { groupList.add(someGroup); groupList.add(anotherGroup); - ListOf anotherList = new ListOf(); + ListWrapper anotherList = new ListWrapper(); anotherList.add(anotherGroup); - ListOf mergedLists = groupList.merge(anotherList); + ListWrapper mergedLists = groupList.merge(anotherList); assertNotNull(mergedLists); assertEquals(2, mergedLists.size()); @@ -149,14 +150,14 @@ class ListOfGroupTest { } @Test public void testMerge_EmptyGroupList_SameGroupList(){ - ListOf anotherList = new ListOf(); + ListWrapper anotherList = new ListWrapper(); groupList.add(someGroup); - ListOf mergedLists = groupList.merge(anotherList); + ListWrapper mergedLists = groupList.merge(anotherList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someGroup)); + assertTrue(mergedLists.contains(someGroup)); assertEquals(1, mergedLists.size()); } diff --git a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfMailTest.java b/src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperMailTest.java similarity index 76% rename from src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfMailTest.java rename to src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperMailTest.java index 97568cfc..ed4cb452 100644 --- a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfMailTest.java +++ b/src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperMailTest.java @@ -1,4 +1,4 @@ -package fr.unantes.software.construction.address.nonRegression; +package fr.unantes.software.construction.address.wrapper; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -7,19 +7,20 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +import fr.unantes.software.construction.address.ListWrapper; import fr.unantes.software.construction.address.Mail; import java.util.Vector; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -class ListOfMailTest { +class ListWrapperMailTest { - ListOf mailList; + ListWrapper mailList; Mail someMail; @BeforeEach void setUp() { - mailList = new ListOf(); + mailList = new ListWrapper(); someMail = new Mail("someHome@mail.com","someWork@mail.com"); } @@ -39,7 +40,7 @@ class ListOfMailTest { mailList.set(anotherList); for(Mail each : mails){ - assertTrue(mailList.find(each)); + assertTrue(mailList.contains(each)); } } @@ -52,7 +53,7 @@ class ListOfMailTest { void testAdd_NewMail_addMailToList(){ mailList.add(someMail); - assertTrue(mailList.find(someMail)); + assertTrue(mailList.contains(someMail)); } @Test @@ -65,7 +66,7 @@ class ListOfMailTest { mailList.add(oneMail); mailList.add(anotherMail); - assertTrue(mailList.find(oneMail)); + assertTrue(mailList.contains(oneMail)); assertEquals("anotherWork@mail.com", oneMail.getWork()); assertEquals("someHome@mail.com",oneMail.getHome()); assertEquals(1,mailList.size()); @@ -81,7 +82,7 @@ class ListOfMailTest { mailList.add(oneMail); mailList.add(anotherMail); - assertTrue(mailList.find(oneMail)); + assertTrue(mailList.contains(oneMail)); assertEquals("someWork@mail.com", oneMail.getWork()); assertNotEquals("anotherHome@mail.com",oneMail.getHome()); assertEquals(2,mailList.size()); @@ -97,13 +98,13 @@ class ListOfMailTest { mailList.add(someMail); mailList.delete(someMail); - assertFalse(mailList.find(someMail)); + assertFalse(mailList.contains(someMail)); assertEquals(0,mailList.size()); } @Test void testDelete_NotContainedMail_NoEffect(){ - ListOf anotherList = new ListOf(); + ListWrapper anotherList = new ListWrapper<>(); Mail anotherMail = new Mail(null,null); mailList.add(someMail); @@ -111,10 +112,10 @@ class ListOfMailTest { mailList.delete(anotherMail); - assertTrue(mailList.find(someMail)); - assertFalse(mailList.find(anotherMail)); + assertTrue(mailList.contains(someMail)); + assertFalse(mailList.contains(anotherMail)); - assertTrue(anotherList.find(anotherMail)); + assertTrue(anotherList.contains(anotherMail)); assertEquals(1,anotherList.size()); } @@ -128,7 +129,7 @@ class ListOfMailTest { Mail anotherMail = new Mail("anotherHome@mail.com","anotherWork@mail.com"); mailList.add(someMail); - assertFalse(mailList.find(anotherMail)); + assertFalse(mailList.contains(anotherMail)); } @Test @@ -136,7 +137,7 @@ class ListOfMailTest { Mail anotherMail = new Mail("someHome@mail.com","anotherWork@mail.com"); mailList.add(someMail); - assertTrue(mailList.find(anotherMail)); + assertTrue(mailList.contains(anotherMail)); } @Test @@ -144,7 +145,7 @@ class ListOfMailTest { Mail anotherMail = new Mail("anotherHome@mail.com","someWork@mail.com"); mailList.add(someMail); - assertFalse(mailList.find(anotherMail)); + assertFalse(mailList.contains(anotherMail)); } @Test @@ -152,14 +153,14 @@ class ListOfMailTest { mailList.add(someMail); Mail anotherMail = new Mail("anotherHome@mail.com", "anotherWork@mail.com"); - ListOf anotherList = new ListOf(); + ListWrapper anotherList = new ListWrapper(); anotherList.add(anotherMail); - ListOf mergedLists = mailList.merge(anotherList); + ListWrapper mergedLists = mailList.merge(anotherList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someMail)); - assertTrue(mergedLists.find(anotherMail)); + assertTrue(mergedLists.contains(someMail)); + assertTrue(mergedLists.contains(anotherMail)); assertEquals(2, mergedLists.size()); } @@ -167,10 +168,10 @@ class ListOfMailTest { public void testMerge_SameLists_NoChange(){ mailList.add(someMail); - ListOf mergedLists = mailList.merge(mailList); + ListWrapper mergedLists = mailList.merge(mailList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someMail)); + assertTrue(mergedLists.contains(someMail)); assertEquals(mailList.size(), mergedLists.size()); } @@ -182,10 +183,10 @@ class ListOfMailTest { mailList.add(someMail); mailList.add(anotherMail); - ListOf anotherList = new ListOf(); + ListWrapper anotherList = new ListWrapper(); anotherList.add(anotherMail); - ListOf mergedLists = mailList.merge(anotherList); + ListWrapper mergedLists = mailList.merge(anotherList); assertNotNull(mergedLists); assertEquals(2, mergedLists.size()); @@ -194,14 +195,14 @@ class ListOfMailTest { } @Test public void testMerge_EmptyMailList_SameGroupList(){ - ListOf anotherList = new ListOf(); + ListWrapper anotherList = new ListWrapper(); mailList.add(someMail); - ListOf mergedLists = mailList.merge(anotherList); + ListWrapper mergedLists = mailList.merge(anotherList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someMail)); + assertTrue(mergedLists.contains(someMail)); assertEquals(1, mergedLists.size()); } diff --git a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfPhoneTest.java b/src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperPhoneTest.java similarity index 73% rename from src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfPhoneTest.java rename to src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperPhoneTest.java index 1aafe15b..3a8b996d 100644 --- a/src/main/test/fr/unantes/software/construction/address/nonRegression/ListOfPhoneTest.java +++ b/src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperPhoneTest.java @@ -1,18 +1,20 @@ -package fr.unantes.software.construction.address.nonRegression; +package fr.unantes.software.construction.address.wrapper; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; + +import fr.unantes.software.construction.address.ListWrapper; import fr.unantes.software.construction.address.Phone; import java.util.Vector; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -class ListOfPhoneTest { +class ListWrapperPhoneTest { - ListOf phoneList = new ListOf<>(); + ListWrapper phoneList = new ListWrapper<>(); Phone somePhone; @BeforeEach @@ -35,7 +37,7 @@ class ListOfPhoneTest { phoneList.set(anotherList); for(Phone each : phones){ - assertTrue(phoneList.find(each)); + assertTrue(phoneList.contains(each)); } } @@ -48,7 +50,7 @@ class ListOfPhoneTest { void testAdd_NewPhone_addPhoneToList(){ phoneList.add(somePhone); - assertTrue(phoneList.find(somePhone)); + assertTrue(phoneList.contains(somePhone)); } @Test @@ -59,10 +61,18 @@ class ListOfPhoneTest { phoneList.add(onePhone); phoneList.add(anotherPhone); - assertTrue(phoneList.find(onePhone)); + assertTrue(phoneList.contains(onePhone)); assertEquals(1,phoneList.get().size()); } + @Test + void testFind_PhoneNumberInCommon_ReturnTrue(){ + Phone anotherPhone = new Phone(somePhone.getPhoneNumber(),"another comment"); + + phoneList.add(somePhone); + assertTrue(phoneList.contains(anotherPhone)); + } + @Test void testAdd_Null_ExceptionThrown(){ assertThrows(NullPointerException.class, () -> phoneList.add(null)); @@ -73,13 +83,13 @@ class ListOfPhoneTest { phoneList.add(somePhone); phoneList.delete(somePhone); - assertFalse(phoneList.find(somePhone)); + assertFalse(phoneList.contains(somePhone)); assertEquals(0,phoneList.get().size()); } @Test void testDelete_NotContainedMail_NoEffect(){ - ListOf anotherList = new ListOf(); + ListWrapper anotherList = new ListWrapper(); Phone anotherPhone = new Phone(0606060606,"another comment"); phoneList.add(somePhone); @@ -87,10 +97,10 @@ class ListOfPhoneTest { phoneList.delete(anotherPhone); - assertTrue(phoneList.find(somePhone)); - assertFalse(phoneList.find(anotherPhone)); + assertTrue(phoneList.contains(somePhone)); + assertFalse(phoneList.contains(anotherPhone)); - assertTrue(anotherList.find(anotherPhone)); + assertTrue(anotherList.contains(anotherPhone)); assertEquals(1,anotherList.get().size()); } @@ -104,15 +114,7 @@ class ListOfPhoneTest { Phone anotherPhone = new Phone(0606060606,"another comment"); phoneList.add(somePhone); - assertFalse(phoneList.find(anotherPhone)); - } - - @Test - void testFind_PhoneNumberInCommon_ReturnTrue(){ - Phone anotherPhone = new Phone(somePhone.getPhoneNumber(),"another comment"); - - phoneList.add(somePhone); - assertTrue(phoneList.find(anotherPhone)); + assertFalse(phoneList.contains(anotherPhone)); } @@ -120,15 +122,15 @@ class ListOfPhoneTest { public void testMerge_TwoDifferentLists_ReturnListWithBothValue(){ phoneList.add(somePhone); - ListOf anotherList = new ListOf(); + ListWrapper anotherList = new ListWrapper(); Phone anotherPhone = new Phone(0606060606,"another comment"); anotherList.add(anotherPhone); - ListOf mergedLists = phoneList.merge(anotherList); + ListWrapper mergedLists = phoneList.merge(anotherList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(somePhone)); - assertTrue(mergedLists.find(anotherPhone)); + assertTrue(mergedLists.contains(somePhone)); + assertTrue(mergedLists.contains(anotherPhone)); assertEquals(2, mergedLists.get().size()); } @@ -136,16 +138,16 @@ class ListOfPhoneTest { public void testMerge_SameLists_NoChange(){ phoneList.add(somePhone); - ListOf mergedLists = phoneList.merge(phoneList); + ListWrapper mergedLists = phoneList.merge(phoneList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(somePhone)); + assertTrue(mergedLists.contains(somePhone)); assertEquals(phoneList.get().size(), mergedLists.get().size()); } @Test public void testMerge_ListsWithSharedValues_NoDuplicate(){ - ListOf anotherList = new ListOf(); + ListWrapper anotherList = new ListWrapper(); Phone anotherPhone = new Phone(0606060606,"another comment"); @@ -154,7 +156,7 @@ class ListOfPhoneTest { anotherList.add(anotherPhone); - ListOf mergedLists = phoneList.merge(anotherList); + ListWrapper mergedLists = phoneList.merge(anotherList); assertNotNull(mergedLists); assertEquals(2, mergedLists.get().size()); @@ -163,14 +165,14 @@ class ListOfPhoneTest { } @Test public void testMerge_EmptyPhoneList_SameGroupList(){ - ListOf anotherList = new ListOf(); + ListWrapper anotherList = new ListWrapper(); phoneList.add(somePhone); - ListOf mergedLists = phoneList.merge(anotherList); + ListWrapper mergedLists = phoneList.merge(anotherList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(somePhone)); + assertTrue(mergedLists.contains(somePhone)); assertEquals(1, mergedLists.get().size()); } -- GitLab From 79a6ddef6cc407543c484cfacfccff8b1a2c04db Mon Sep 17 00:00:00 2001 From: Gries Robin Date: Thu, 26 Mar 2020 14:16:42 +0100 Subject: [PATCH 089/120] Add a ListWrapper as a better abstraction for AddressList, CardList, GroupList --- .../construction/address/Address.java | 10 +- .../construction/address/AddressBook.java | 15 +- .../construction/address/AddressList.java | 25 +- .../software/construction/address/Card.java | 20 +- .../construction/address/CardList.java | 19 +- .../software/construction/address/City.java | 5 +- .../construction/address/GroupList.java | 13 +- .../construction/address/ListWrapper.java | 134 +++++++++++ .../software/construction/address/Mail.java | 13 +- .../construction/address/MailList.java | 10 +- .../software/construction/address/Phone.java | 11 +- .../construction/address/PhoneList.java | 12 +- .../construction/address/AddressBookTest.java | 19 +- .../construction/address/AddressListTest.java | 27 ++- .../construction/address/CardListTest.java | 50 ++-- .../construction/address/CompanyCardTest.java | 51 ++-- .../construction/address/GroupListTest.java | 2 + .../construction/address/MailListTest.java | 30 +-- .../construction/address/PhoneListTest.java | 26 +-- .../construction/address/PrivateCardTest.java | 50 ++-- .../wrapper/ListWrapperAddressTest.java | 177 ++++++++++++++ .../address/wrapper/ListWrapperCardTest.java | 173 ++++++++++++++ .../address/wrapper/ListWrapperGroupTest.java | 172 ++++++++++++++ .../address/wrapper/ListWrapperMailTest.java | 217 ++++++++++++++++++ .../address/wrapper/ListWrapperPhoneTest.java | 185 +++++++++++++++ 25 files changed, 1273 insertions(+), 193 deletions(-) create mode 100644 src/main/java/fr/unantes/software/construction/address/ListWrapper.java create mode 100644 src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperAddressTest.java create mode 100644 src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperCardTest.java create mode 100644 src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperGroupTest.java create mode 100644 src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperMailTest.java create mode 100644 src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperPhoneTest.java diff --git a/src/main/java/fr/unantes/software/construction/address/Address.java b/src/main/java/fr/unantes/software/construction/address/Address.java index baf32138..60b8e750 100755 --- a/src/main/java/fr/unantes/software/construction/address/Address.java +++ b/src/main/java/fr/unantes/software/construction/address/Address.java @@ -11,7 +11,10 @@ import org.apache.commons.lang3.Validate; * @version 1.0 * @date 17/12/2004. */ -public abstract class Address { +public abstract class Address { + + private static final String XML_LIST_OPEN_TAG = ""; + private static final String XML_LIST_CLOSE_TAG = ""; protected Integer streetNumber; protected String streetName; @@ -173,4 +176,9 @@ public abstract class Address { public abstract String toXML(); + public String getXMLListOpenTag() { return XML_LIST_OPEN_TAG; } + + public String getXMLListClosingTag() { return XML_LIST_CLOSE_TAG;} + + } \ No newline at end of file diff --git a/src/main/java/fr/unantes/software/construction/address/AddressBook.java b/src/main/java/fr/unantes/software/construction/address/AddressBook.java index 4cd58dd8..5213cc02 100755 --- a/src/main/java/fr/unantes/software/construction/address/AddressBook.java +++ b/src/main/java/fr/unantes/software/construction/address/AddressBook.java @@ -12,15 +12,15 @@ public class AddressBook { private String name; - private CardList cards; + private ListWrapper cards; public AddressBook() { - cards = new CardList(); + cards = new ListWrapper<>(); } - public AddressBook(String name, CardList cards) { + public AddressBook(String name, ListWrapper cards) { this.name = name; - this.cards = new CardList(); + this.cards = new ListWrapper<>(); this.cards.set(cards.get()); } @@ -28,7 +28,7 @@ public class AddressBook { return name; } - public CardList getCards() { + public ListWrapper getCards() { return cards; } @@ -36,10 +36,9 @@ public class AddressBook { name = names; } - public void setCards(CardList cards) { + public void setCards(ListWrapper cards) { this.cards.set(cards.get()); } - /** * Fusione deux reprtoires. Rend un nouvel objet. @@ -49,7 +48,7 @@ public class AddressBook { * @return */ public AddressBook merge(AddressBook addressBook, String name) { - CardList newCard = this.cards.merge(addressBook.getCards()); + ListWrapper newCard = this.cards.merge(addressBook.getCards()); AddressBook newBook = new AddressBook(); newBook.setName(name); diff --git a/src/main/java/fr/unantes/software/construction/address/AddressList.java b/src/main/java/fr/unantes/software/construction/address/AddressList.java index 244268b9..053a7cb0 100755 --- a/src/main/java/fr/unantes/software/construction/address/AddressList.java +++ b/src/main/java/fr/unantes/software/construction/address/AddressList.java @@ -11,7 +11,12 @@ import org.apache.commons.lang3.Validate; import java.util.*; -public class AddressList { +/** + * @deprecated use ListWrapper of Address instead + * Kept for non regression testing + */ +@Deprecated +public class AddressList { /** Les attributs d'instance */ protected Vector addresses; @@ -57,7 +62,7 @@ public class AddressList { */ public void add(Address address) { Validate.notNull(address); - if (!find(address)) + if (!contains(address)) addresses.add(address); } @@ -65,7 +70,7 @@ public class AddressList { * @param address adresse a delete de la liste */ public void delete(Address address) { - if (find(address)) + if (contains(address)) addresses.remove(address); else System.out.println("l'adresse a existe pas"); @@ -74,7 +79,7 @@ public class AddressList { /** * @param address c'est l'adresse recherchee */ - public boolean find(Address address) { + public boolean contains(Address address) { return addresses.contains(address); } @@ -105,23 +110,13 @@ public class AddressList { for (Enumeration e1 = addresses.get().elements(); e1 .hasMoreElements();) { nextAddress = (Address) e1.nextElement(); - if (!(newAddressList.find(nextAddress))) { + if (!(newAddressList.contains(nextAddress))) { newAddressList.add(nextAddress); } } return newAddressList; } - public String toXML() { - String res = ""; - Enumeration e = addresses.elements(); - while (e.hasMoreElements()) { - res = res + ((Address) e.nextElement()).toXML(); - } - res = res + ""; - return res; - } - /** * @return res */ diff --git a/src/main/java/fr/unantes/software/construction/address/Card.java b/src/main/java/fr/unantes/software/construction/address/Card.java index 31d51416..28f71257 100755 --- a/src/main/java/fr/unantes/software/construction/address/Card.java +++ b/src/main/java/fr/unantes/software/construction/address/Card.java @@ -8,11 +8,10 @@ import org.apache.commons.lang3.Validate; * @version 1.0 * @date 17/12/2004. */ -public abstract class Card { - +public abstract class Card { protected String identification; - protected GroupList groups = new GroupList(); - protected AddressList addresses = new AddressList(); + protected ListWrapper groups = new ListWrapper<>(); + protected ListWrapper
addresses = new ListWrapper<>(); protected PhoneList phones = new PhoneList(); protected MailList mails = new MailList(); private Client client; @@ -28,7 +27,7 @@ public abstract class Card { /** * @return addresses */ - public AddressList getAddresses() { + public ListWrapper
getAddresses() { return addresses; } @@ -49,7 +48,7 @@ public abstract class Card { /** * @return groups */ - public GroupList getGroups() { + public ListWrapper getGroups() { return groups; } @@ -57,7 +56,7 @@ public abstract class Card { /** * @param addresses */ - public void setAddresses(AddressList addresses) { + public void setAddresses(ListWrapper
addresses) { Validate.notNull(addresses); this.addresses = addresses; } @@ -81,7 +80,7 @@ public abstract class Card { /** * @param groups */ - public void setGroups(GroupList groups) { + public void setGroups(ListWrapper groups) { Validate.notNull(groups); this.groups = groups; } @@ -96,9 +95,6 @@ public abstract class Card { public abstract CompanyCard mergeCompanyCard(CompanyCard card); public abstract PrivateCard mergePrivateCard(PrivateCard card); - - - public abstract String toXML(); public boolean identicalCard(Card card) { return (identification.equals(card.getIdentification())); @@ -123,4 +119,6 @@ public abstract class Card { } return false; } + + public abstract String toXML(); } diff --git a/src/main/java/fr/unantes/software/construction/address/CardList.java b/src/main/java/fr/unantes/software/construction/address/CardList.java index ac0015bf..1f397f3b 100755 --- a/src/main/java/fr/unantes/software/construction/address/CardList.java +++ b/src/main/java/fr/unantes/software/construction/address/CardList.java @@ -1,9 +1,14 @@ package fr.unantes.software.construction.address; +import java.util.Enumeration; +import java.util.Vector; import org.apache.commons.lang3.Validate; -import java.util.*; - +/** + * @deprecated use a ListWrapper of Card instead + * Kept for non-regression testing. + */ +@Deprecated public class CardList { /** Les attributs d'instance */ @@ -18,7 +23,7 @@ public class CardList { /** * @param cards un objet adresse que l'on veux copier */ - public CardList (CardList cards){ + public CardList(CardList cards){ this.cards = new Vector(); for (Enumeration e = cards.get().elements(); e.hasMoreElements() ;) { this.cards.add(e.nextElement()); @@ -49,19 +54,19 @@ public class CardList { */ public void add(Card card){ Validate.notNull(card); - if(!find(card)) cards.add(card); + if(!contains(card)) cards.add(card); } /** * @param card fiche à supprimer de la liste */ public void delete(Card card){ - if (find(card)) cards.remove(card); + if (contains(card)) cards.remove(card); } /** * @param card c'est la fiche find */ - public boolean find(Card card){ + public boolean contains(Card card){ return cards.contains(card); } @@ -94,6 +99,7 @@ public class CardList { return res; } + public String toXML(){ String res = ""; Enumeration e = cards.elements(); @@ -114,4 +120,5 @@ public class CardList { } return res; } + } diff --git a/src/main/java/fr/unantes/software/construction/address/City.java b/src/main/java/fr/unantes/software/construction/address/City.java index 2864e325..0a29e182 100644 --- a/src/main/java/fr/unantes/software/construction/address/City.java +++ b/src/main/java/fr/unantes/software/construction/address/City.java @@ -6,8 +6,8 @@ import org.apache.commons.lang3.Validate; * A city */ public class City { - public String country; - public String name; + private String country; + private String name; public City(String country, String name) { Validate.notNull(country); @@ -42,6 +42,7 @@ public class City { getName().equals(city.getName()); } + public int hashCode() { return getCountry().hashCode() + getName().hashCode(); } diff --git a/src/main/java/fr/unantes/software/construction/address/GroupList.java b/src/main/java/fr/unantes/software/construction/address/GroupList.java index 0c223f90..8a1e8b3d 100755 --- a/src/main/java/fr/unantes/software/construction/address/GroupList.java +++ b/src/main/java/fr/unantes/software/construction/address/GroupList.java @@ -4,7 +4,14 @@ import org.apache.commons.lang3.Validate; import java.util.*; -public class GroupList { +/** + * @deprecated use ListWrapper of Group instead + * Kept for non regression testing + */ +@Deprecated +public class GroupList { + private static final String XML_LIST_OPEN_TAG = ""; + private static final String XML_LIST_CLOSE_TAG = ""; Vector groups; @@ -111,12 +118,12 @@ public class GroupList { } public String toXML() { - String res = ""; + String res = XML_LIST_OPEN_TAG; Enumeration e = groups.elements(); while (e.hasMoreElements()) { res = res + ((Group) e.nextElement()).toXML(); } - res = res + ""; + res = res + XML_LIST_CLOSE_TAG; return res; } diff --git a/src/main/java/fr/unantes/software/construction/address/ListWrapper.java b/src/main/java/fr/unantes/software/construction/address/ListWrapper.java new file mode 100644 index 00000000..b11fd8fa --- /dev/null +++ b/src/main/java/fr/unantes/software/construction/address/ListWrapper.java @@ -0,0 +1,134 @@ +package fr.unantes.software.construction.address; + + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.lang3.Validate; + +/** + * Issues #12 + * all classes called FooList have the same methods and could be replace + * with a simple List<Foo> + * + * Tests have been made for the original classes FooList and thus can be used for + * non-regression testing + * + * This class is used as an adapter to translate the methods of the java ArrayList to FooList, + * so that Tests can then be run using a List<Foo> and validate that the behavior + * stay the same. + */ +public class ListWrapper { + private List targetList; + + /** + * Empty constructor + */ + public ListWrapper(){ + targetList = new ArrayList<>(); + } + + /** + * Copy constructor + * @param otherList List to copy + */ + public ListWrapper(ListWrapper otherList){ + targetList = otherList.targetList; + } + + /** + * @return a List of element + */ + public List get() { + return targetList; + } + + public void set(List newTargetList) { + if (newTargetList == null) { + throw new NullPointerException(); + } else { + targetList = newTargetList; + } + } + + public void add(T elt) { + if (elt == null) { + throw new NullPointerException(); + } else { + //add() methods in FooList all check that elt doesn't exist yet, + // so they are actually List instead of List + if (this.targetList.contains(elt)) { + return; + } + targetList.add(elt); + } + } + public void delete(T elt){ + Validate.notNull(elt); + targetList.remove(elt); + } + public boolean contains(T elt){ + return targetList.contains(elt); + } + public boolean find(T elt) { return targetList.contains(elt);} + + public int size(){ + return targetList.size(); + } + + /** + * Iterate on otherlist to add each element one by one to this ListOf + * @param otherList a list of elements to add to this ListOf + * @return a new ListOf containing the elements of this ListOf element and the elements of otherList + */ + public ListWrapper merge(ListWrapper otherList){ + Validate.notNull(otherList); + + ListWrapper newList = new ListWrapper<>(this); + + //It's slow , but speed isn't important for this test + for(T t : otherList.get()) { + if( !newList.contains(t) ) { + newList.add(t); + } + } + + return newList; + } + + /** + * Delegate the merge to the methods of java.util.List, but it may have duplicates + * @param otherList a list of elements to add to this ListOf + * @return a new ListOf containing the elements of this ListOf element and the elements of otherList + */ + public ListWrapper delegateMerge( ListWrapper otherList){ + Validate.notNull(otherList); + + ListWrapper newList = new ListWrapper<>(this); + newList.get().addAll(otherList.get()); + + return newList; + } + + /** + * @return a String representing this ListWrapper + */ + public String toString() { + String res = ""; + for (T t : targetList){ + res = res.concat("/n" + t.toString()); + } + return res; + } + + public String toXML() { + //TODO + return null; + } + + + //TODO verifier / tester si les FooList force effectivemment les merge() à rendre une liste + // sans doublons + // si oui , peut etre utiliser un Set + // +} diff --git a/src/main/java/fr/unantes/software/construction/address/Mail.java b/src/main/java/fr/unantes/software/construction/address/Mail.java index 7f3640a8..2c304950 100755 --- a/src/main/java/fr/unantes/software/construction/address/Mail.java +++ b/src/main/java/fr/unantes/software/construction/address/Mail.java @@ -12,30 +12,19 @@ public class Mail { this.work = work; } - /** - * @return _maill - */ + public String getHome() { return home; } - /** - * @return _com_mail - */ public String getWork() { return work; } - /** - * @param home - */ public void setHome(String home) { this.home = home; } - /** - * @param work - */ public void setWork(String work) { this.work = work; } diff --git a/src/main/java/fr/unantes/software/construction/address/MailList.java b/src/main/java/fr/unantes/software/construction/address/MailList.java index f0803f6a..e416f570 100755 --- a/src/main/java/fr/unantes/software/construction/address/MailList.java +++ b/src/main/java/fr/unantes/software/construction/address/MailList.java @@ -11,7 +11,7 @@ import org.apache.commons.lang3.Validate; import java.util.*; -public class MailList { +public class MailList { private Vector mails; @@ -54,7 +54,7 @@ public class MailList { */ public void add(Mail mail) { Validate.notNull(mail); - if (!find(mail)) + if (!contains(mail)) mails.add(mail); else{ Mail nextMail; @@ -78,7 +78,7 @@ public class MailList { */ public void delete(Mail mail) { Validate.notNull(mail); - if (find(mail)) + if (contains(mail)) mails.remove(mail); else System.out.println("le mail n'existe pas"); @@ -88,7 +88,7 @@ public class MailList { * @param mail * c'est le mail recherche */ - public boolean find(Mail mail) { + public boolean contains(Mail mail) { boolean res = false; Mail nextMail; for (Enumeration e = mails.elements(); e.hasMoreElements();) { @@ -126,7 +126,7 @@ public class MailList { for (Enumeration e1 = mails.get().elements(); e1 .hasMoreElements();) { nextMail = (Mail) e1.nextElement(); - if (!(res.find(nextMail))) { + if (!(res.contains(nextMail))) { res.add(nextMail); } } diff --git a/src/main/java/fr/unantes/software/construction/address/Phone.java b/src/main/java/fr/unantes/software/construction/address/Phone.java index eef93155..677e1e5e 100755 --- a/src/main/java/fr/unantes/software/construction/address/Phone.java +++ b/src/main/java/fr/unantes/software/construction/address/Phone.java @@ -1,5 +1,6 @@ package fr.unantes.software.construction.address; +import java.util.Objects; import org.apache.commons.lang3.Validate; import javax.annotation.Nonnull; @@ -10,6 +11,7 @@ import javax.annotation.Nonnull; * @date 17/12/2004. */ public class Phone { + @Nonnull protected Integer phoneNumber; protected String comment; @@ -68,7 +70,11 @@ public class Phone { public String toXML() { return ("" + phoneNumber + comment + ""); } - + + public boolean sameNumberAs(Phone other){ + return this.phoneNumber.equals(other.phoneNumber); + } + public boolean equals(Object another){ if (this == another) return true; @@ -76,6 +82,7 @@ public class Phone { return false; Phone other = (Phone) another; - return (phoneNumber == other.phoneNumber) && comment.equals(other.comment); + return (phoneNumber.equals(other.phoneNumber)) && comment.equals(other.comment); } + } diff --git a/src/main/java/fr/unantes/software/construction/address/PhoneList.java b/src/main/java/fr/unantes/software/construction/address/PhoneList.java index 9c89b7c6..7bc8b51f 100755 --- a/src/main/java/fr/unantes/software/construction/address/PhoneList.java +++ b/src/main/java/fr/unantes/software/construction/address/PhoneList.java @@ -4,7 +4,7 @@ import org.apache.commons.lang3.Validate; import java.util.*; -public class PhoneList { +public class PhoneList { protected Vector phones; @@ -45,7 +45,7 @@ public class PhoneList { */ public void add(Phone phone) { Validate.notNull(phone); - if (!find(phone)) + if (!contains(phone)) phones.add(phone); // si existe deja faire la fusion des deux dans celle deja enregistrer // dans le vecteur. @@ -60,7 +60,7 @@ public class PhoneList { */ public void delete(Phone phone) { Validate.notNull(phone); - if (find(phone)) + if (contains(phone)) phones.remove(phone); else System.out.println("le telephone n'existe pas"); @@ -69,10 +69,10 @@ public class PhoneList { /** * @param phone c'est le telephone recherche */ - public boolean find(Phone phone) { + public boolean contains(Phone phone) { boolean res = false; for (Enumeration e = phones.elements(); e.hasMoreElements();) { - if (((Phone) e.nextElement()).getPhoneNumber() == phone.getPhoneNumber()) + if ( ((Phone) e.nextElement()).sameNumberAs(phone) ) res = true; } return res; @@ -103,7 +103,7 @@ public class PhoneList { for (Enumeration e1 = phones.get().elements(); e1 .hasMoreElements();) { nextPhone = (Phone) e1.nextElement(); - if (!(res.find(nextPhone))) { + if (!(res.contains(nextPhone))) { res.add(nextPhone); } } diff --git a/src/main/test/fr/unantes/software/construction/address/AddressBookTest.java b/src/main/test/fr/unantes/software/construction/address/AddressBookTest.java index 3f84064f..bb97a379 100644 --- a/src/main/test/fr/unantes/software/construction/address/AddressBookTest.java +++ b/src/main/test/fr/unantes/software/construction/address/AddressBookTest.java @@ -6,13 +6,13 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; class AddressBookTest { - CardList someList; + ListWrapper someList; Card someCard; AddressBook addressBook; @BeforeEach void setUp(){ - someList = new CardList(); + someList = new ListWrapper<>(); someCard = new PrivateCard("Chaussette","Louis"); someList.add(someCard); addressBook = new AddressBook(); @@ -22,7 +22,7 @@ class AddressBookTest { void testSetCards_ValidCardList_Succeed(){ assertDoesNotThrow(()->addressBook.setCards(someList)); - assertEquals(someList.find(someCard), addressBook.getCards().find(someCard)); + assertEquals(someList.contains(someCard), addressBook.getCards().contains(someCard)); } @Test @@ -34,7 +34,6 @@ class AddressBookTest { void testSetName_AnyStringValue_Suceed(){ assertDoesNotThrow(()->addressBook.setName("name")); assertEquals("name",addressBook.getName()); - } @Test @@ -42,7 +41,7 @@ class AddressBookTest { addressBook.setCards(someList); AddressBook anotherBook = new AddressBook(); - CardList anotherList = new CardList(); + ListWrapper anotherList = new ListWrapper<>(); Card anotherCard = new PrivateCard("Marco","Polo"); anotherList.add(anotherCard); @@ -51,8 +50,8 @@ class AddressBookTest { AddressBook mergedLists = addressBook.merge(anotherBook,"new name"); assertNotNull(mergedLists); - assertTrue(mergedLists.getCards().find(someCard)); - assertTrue(mergedLists.getCards().find(anotherCard)); + assertTrue(mergedLists.getCards().contains(someCard)); + assertTrue(mergedLists.getCards().contains(anotherCard)); assertEquals(2, mergedLists.getCards().get().size()); } @@ -62,7 +61,7 @@ class AddressBookTest { AddressBook mergedLists = addressBook.merge(addressBook,""); assertNotNull(mergedLists); - assertTrue(mergedLists.getCards().find(someCard)); + assertTrue(mergedLists.getCards().contains(someCard)); assertEquals(addressBook.getCards().get().size(), mergedLists.getCards().get().size()); } @@ -71,7 +70,7 @@ class AddressBookTest { addressBook.setCards(someList); AddressBook anotherBook = new AddressBook(); - CardList anotherList = new CardList(); + ListWrapper anotherList = new ListWrapper<>(); Card anotherCard = new PrivateCard("Marco","Polo"); anotherList.add(someCard); @@ -93,7 +92,7 @@ class AddressBookTest { AddressBook mergedLists = addressBook.merge(anotherBook,""); assertNotNull(mergedLists); - assertTrue(mergedLists.getCards().find(someCard)); + assertTrue(mergedLists.getCards().contains(someCard)); assertEquals(1, mergedLists.getCards().get().size()); } diff --git a/src/main/test/fr/unantes/software/construction/address/AddressListTest.java b/src/main/test/fr/unantes/software/construction/address/AddressListTest.java index 5d68e3fd..0a5d8fe6 100644 --- a/src/main/test/fr/unantes/software/construction/address/AddressListTest.java +++ b/src/main/test/fr/unantes/software/construction/address/AddressListTest.java @@ -1,5 +1,10 @@ package fr.unantes.software.construction.address; +import fr.unantes.software.construction.address.Address; +import fr.unantes.software.construction.address.AddressList; +import fr.unantes.software.construction.address.City; +import fr.unantes.software.construction.address.CompanyAddress; +import fr.unantes.software.construction.address.PrivateAddress; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -33,7 +38,7 @@ class AddressListTest { addressList.set(anotherList); for(Address each : addresses){ - assertTrue(addressList.find(each)); + assertTrue(addressList.contains(each)); } } @@ -46,7 +51,7 @@ class AddressListTest { @Test public void testAdd_newValue_Succeed(){ assertDoesNotThrow(() -> addressList.add(someAddress)); - assertTrue(addressList.find(someAddress)); + assertTrue(addressList.contains(someAddress)); } @Test @@ -70,7 +75,7 @@ class AddressListTest { addressList.add(someAddress); addressList.delete(someAddress); - assertFalse(addressList.find(someAddress)); + assertFalse(addressList.contains(someAddress)); } @Test @@ -79,23 +84,23 @@ class AddressListTest { anotherList.add(someAddress); int currentSize = addressList.get().size(); - assertFalse(addressList.find(someAddress)); + assertFalse(addressList.contains(someAddress)); addressList.delete(someAddress); - assertTrue(anotherList.find(someAddress)); + assertTrue(anotherList.contains(someAddress)); assertEquals(currentSize, addressList.get().size()); } @Test public void testFind_ContainedValue_ReturnTrue(){ addressList.add(someAddress); - assertTrue(addressList.find(someAddress)); + assertTrue(addressList.contains(someAddress)); } @Test public void testFind_NotContainedValue_ReturnFalse(){ addressList.add(new PrivateAddress(1,"Another Private Street", new City("Norvege","Honningsvag"),0,null)); - assertFalse(addressList.find(someAddress)); + assertFalse(addressList.contains(someAddress)); } @Test @@ -109,8 +114,8 @@ class AddressListTest { AddressList mergedLists = addressList.merge(anotherList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someAddress)); - assertTrue(mergedLists.find(anotherAddress)); + assertTrue(mergedLists.contains(someAddress)); + assertTrue(mergedLists.contains(anotherAddress)); assertEquals(2, mergedLists.get().size()); } @@ -121,7 +126,7 @@ class AddressListTest { AddressList mergedLists = addressList.merge(addressList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someAddress)); + assertTrue(mergedLists.contains(someAddress)); assertEquals(addressList.get().size(), mergedLists.get().size()); } @@ -151,7 +156,7 @@ class AddressListTest { AddressList mergedLists = addressList.merge(anotherList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someAddress)); + assertTrue(mergedLists.contains(someAddress)); assertEquals(1, mergedLists.get().size()); } diff --git a/src/main/test/fr/unantes/software/construction/address/CardListTest.java b/src/main/test/fr/unantes/software/construction/address/CardListTest.java index e2e0fbea..deadb2d7 100644 --- a/src/main/test/fr/unantes/software/construction/address/CardListTest.java +++ b/src/main/test/fr/unantes/software/construction/address/CardListTest.java @@ -1,5 +1,11 @@ package fr.unantes.software.construction.address; +import fr.unantes.software.construction.address.Card; +import fr.unantes.software.construction.address.CompanyCard; +import fr.unantes.software.construction.address.ListWrapper; +import fr.unantes.software.construction.address.PrivateCard; +import java.util.ArrayList; +import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -8,17 +14,17 @@ import java.util.Vector; import static org.junit.jupiter.api.Assertions.*; class CardListTest { - CardList cardList; + ListWrapper cardList; Card someCard; @BeforeEach void setUp() { - cardList = new CardList(); + cardList = new ListWrapper(); someCard = new PrivateCard("John","Doe"); } @Test void testSet_ListOfCards_addCardsToCurrentList(){ - Vector anotherList = new Vector(); + Vector anotherList = new Vector<>(); Card[] cards = { someCard, new PrivateCard("Tom","Joe"), new CompanyCard("JohnDoe Corp.") @@ -31,7 +37,7 @@ class CardListTest { cardList.set(anotherList); for(Card each : cards){ - assertTrue(cardList.find(each)); + assertTrue(cardList.contains(each)); } } @@ -44,7 +50,7 @@ class CardListTest { @Test public void testAdd_newValue_Succeed(){ assertDoesNotThrow(() -> cardList.add(someCard)); - assertTrue(cardList.find(someCard)); + assertTrue(cardList.contains(someCard)); } @Test @@ -68,32 +74,32 @@ class CardListTest { cardList.add(someCard); cardList.delete(someCard); - assertFalse(cardList.find(someCard)); + assertFalse(cardList.contains(someCard)); } @Test public void testDelete_ValueContainedByAnotherGroup_NoEffect(){ - CardList anotherList = new CardList(); + ListWrapper anotherList = new ListWrapper(); anotherList.add(someCard); int currentSize = cardList.get().size(); - assertFalse(cardList.find(someCard)); + assertFalse(cardList.contains(someCard)); cardList.delete(someCard); - assertTrue(anotherList.find(someCard)); + assertTrue(anotherList.contains(someCard)); assertEquals(currentSize, cardList.get().size()); } @Test public void testFind_ContainedValue_ReturnTrue(){ cardList.add(someCard); - assertTrue(cardList.find(someCard)); + assertTrue(cardList.contains(someCard)); } @Test public void testFind_NotContainedValue_ReturnFalse(){ cardList.add(new PrivateCard("Tom","Joe")); - assertFalse(cardList.find(someCard)); + assertFalse(cardList.contains(someCard)); } @Test @@ -101,14 +107,14 @@ class CardListTest { cardList.add(someCard); Card anotherCard = new PrivateCard("Tom", "Joe"); - CardList anotherList = new CardList(); + ListWrapper anotherList = new ListWrapper(); anotherList.add(anotherCard); - CardList mergedLists = cardList.merge(anotherList); + ListWrapper mergedLists = cardList.merge(anotherList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someCard)); - assertTrue(mergedLists.find(anotherCard)); + assertTrue(mergedLists.contains(someCard)); + assertTrue(mergedLists.contains(anotherCard)); assertEquals(2, mergedLists.get().size()); } @@ -116,10 +122,10 @@ class CardListTest { public void testMerge_SameLists_NoChange(){ cardList.add(someCard); - CardList mergedLists = cardList.merge(cardList); + ListWrapper mergedLists = cardList.merge(cardList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someCard)); + assertTrue(mergedLists.contains(someCard)); assertEquals(cardList.get().size(), mergedLists.get().size()); } @@ -130,10 +136,10 @@ class CardListTest { cardList.add(someCard); cardList.add(anotherCard); - CardList anotherList = new CardList(); + ListWrapper anotherList = new ListWrapper(); anotherList.add(anotherCard); - CardList mergedLists = cardList.merge(anotherList); + ListWrapper mergedLists = cardList.merge(anotherList); assertNotNull(mergedLists); assertEquals(2, mergedLists.get().size()); @@ -142,14 +148,14 @@ class CardListTest { } @Test public void testMerge_EmptyCardList_SameCardList(){ - CardList anotherList = new CardList(); + ListWrapper anotherList = new ListWrapper(); cardList.add(someCard); - CardList mergedLists = cardList.merge(anotherList); + ListWrapper mergedLists = cardList.merge(anotherList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someCard)); + assertTrue(mergedLists.contains(someCard)); assertEquals(1, mergedLists.get().size()); } diff --git a/src/main/test/fr/unantes/software/construction/address/CompanyCardTest.java b/src/main/test/fr/unantes/software/construction/address/CompanyCardTest.java index 8e745aa0..e84ffa4c 100644 --- a/src/main/test/fr/unantes/software/construction/address/CompanyCardTest.java +++ b/src/main/test/fr/unantes/software/construction/address/CompanyCardTest.java @@ -2,26 +2,25 @@ package fr.unantes.software.construction.address; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.mockito.internal.matchers.Null; import static org.junit.jupiter.api.Assertions.*; class CompanyCardTest { CompanyCard companyCard; - AddressList someAddresses; CompanyAddress anAddress; + ListWrapper
someAddresses; CompanyAddress anAddress; PhoneList somePhones; Phone aPhone; MailList someMails; Mail aMail; - GroupList someGroups; Group aGroup; + ListWrapper someGroups; Group aGroup; @BeforeEach void setUp() { companyCard = new CompanyCard("companyName"); - someAddresses = new AddressList(); + someAddresses = new ListWrapper
(); somePhones = new PhoneList(); someMails = new MailList(); - someGroups = new GroupList(); + someGroups = new ListWrapper(); anAddress = new CompanyAddress(1, "Some Company Street", new City("Groenland", "Qeqertarsuaq"), 0, null,null); someAddresses.add(anAddress); @@ -42,7 +41,7 @@ class CompanyCardTest { */ @Test void testSetAddresses_SomeAddressList_Succeed(){ - AddressList someList = new AddressList(); + ListWrapper
someList = new ListWrapper
(); companyCard.setAddresses(someList); assertEquals(someList, companyCard.getAddresses()); @@ -84,7 +83,7 @@ class CompanyCardTest { @Test void testSetGroups_SomeGroupList_Succeed(){ - GroupList someList = new GroupList(); + ListWrapper someList = new ListWrapper(); companyCard.setGroups(someList); assertEquals(someList, companyCard.getGroups()); @@ -146,10 +145,10 @@ class CompanyCardTest { void testMerge_CompanyCardWithSameId_ReturnPrivateCardWithBothValues(){ CompanyCard anotherCard = new CompanyCard("companyName"); - AddressList anotherAddresses = new AddressList(); + ListWrapper
anotherAddresses = new ListWrapper
(); PhoneList anotherPhones = new PhoneList(); MailList anotherMails = new MailList(); - GroupList anotherGroups = new GroupList(); + ListWrapper anotherGroups = new ListWrapper(); CompanyAddress anotherAddress = new CompanyAddress(1, "Another Company Street", new City("France", "Angouleme"), 16000, null,null); anotherAddresses.add(anotherAddress); @@ -166,16 +165,16 @@ class CompanyCardTest { CompanyCard mergedCard = (CompanyCard) companyCard.merge(anotherCard); - assertTrue(mergedCard.getAddresses().find(anAddress)); - assertTrue(mergedCard.getAddresses().find(anotherAddress)); + assertTrue(mergedCard.getAddresses().contains(anAddress)); + assertTrue(mergedCard.getAddresses().contains(anotherAddress)); assertEquals(2,mergedCard.getAddresses().get().size()); - assertTrue(mergedCard.getPhones().find(aPhone)); - assertTrue(mergedCard.getPhones().find(anotherPhone)); + assertTrue(mergedCard.getPhones().contains(aPhone)); + assertTrue(mergedCard.getPhones().contains(anotherPhone)); assertEquals(2,mergedCard.getPhones().get().size()); - assertTrue(mergedCard.getMails().find(aMail)); - assertTrue(mergedCard.getMails().find(anotherMail)); + assertTrue(mergedCard.getMails().contains(aMail)); + assertTrue(mergedCard.getMails().contains(anotherMail)); assertEquals(2,mergedCard.getMails().get().size()); assertTrue(mergedCard.getGroups().find(aGroup)); @@ -189,13 +188,13 @@ class CompanyCardTest { void testMerge_SameCompanyCard_NoChange(){ CompanyCard mergedCard = (CompanyCard) companyCard.merge(companyCard); - assertTrue(mergedCard.getAddresses().find(anAddress)); + assertTrue(mergedCard.getAddresses().contains(anAddress)); assertEquals(1,mergedCard.getAddresses().get().size()); - assertTrue(mergedCard.getPhones().find(aPhone)); + assertTrue(mergedCard.getPhones().contains(aPhone)); assertEquals(1,mergedCard.getPhones().get().size()); - assertTrue(mergedCard.getMails().find(aMail)); + assertTrue(mergedCard.getMails().contains(aMail)); assertEquals(1,mergedCard.getMails().get().size()); assertTrue(mergedCard.getGroups().find(aGroup)); @@ -206,10 +205,10 @@ class CompanyCardTest { void testMerge_CompanyCardsWithSharedValues_NoDuplicate(){ CompanyCard anotherCard = new CompanyCard("companyName"); - AddressList anotherAddresses = new AddressList(); + ListWrapper
anotherAddresses = new ListWrapper
(); PhoneList anotherPhones = new PhoneList(); MailList anotherMails = new MailList(); - GroupList anotherGroups = new GroupList(); + ListWrapper anotherGroups = new ListWrapper(); CompanyAddress anotherAddress = new CompanyAddress(1, "Another Private Street", new City("France", "Angouleme"), 16000, null,null); Phone anotherPhone = new Phone(0642424242, ""); Mail anotherMail = new Mail("anotherHome@mail.com", null); @@ -231,16 +230,16 @@ class CompanyCardTest { CompanyCard mergedCard = (CompanyCard) companyCard.merge(anotherCard); - assertTrue(mergedCard.getAddresses().find(anAddress)); - assertTrue(mergedCard.getAddresses().find(anotherAddress)); + assertTrue(mergedCard.getAddresses().contains(anAddress)); + assertTrue(mergedCard.getAddresses().contains(anotherAddress)); assertEquals(2,mergedCard.getAddresses().get().size()); - assertTrue(mergedCard.getPhones().find(aPhone)); - assertTrue(mergedCard.getPhones().find(anotherPhone)); + assertTrue(mergedCard.getPhones().contains(aPhone)); + assertTrue(mergedCard.getPhones().contains(anotherPhone)); assertEquals(2,mergedCard.getPhones().get().size()); - assertTrue(mergedCard.getMails().find(aMail)); - assertTrue(mergedCard.getMails().find(anotherMail)); + assertTrue(mergedCard.getMails().contains(aMail)); + assertTrue(mergedCard.getMails().contains(anotherMail)); assertEquals(2,mergedCard.getMails().get().size()); assertTrue(mergedCard.getGroups().find(aGroup)); diff --git a/src/main/test/fr/unantes/software/construction/address/GroupListTest.java b/src/main/test/fr/unantes/software/construction/address/GroupListTest.java index e631a9b7..a89fd993 100644 --- a/src/main/test/fr/unantes/software/construction/address/GroupListTest.java +++ b/src/main/test/fr/unantes/software/construction/address/GroupListTest.java @@ -1,5 +1,7 @@ package fr.unantes.software.construction.address; +import fr.unantes.software.construction.address.Group; +import fr.unantes.software.construction.address.GroupList; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.internal.matchers.Null; diff --git a/src/main/test/fr/unantes/software/construction/address/MailListTest.java b/src/main/test/fr/unantes/software/construction/address/MailListTest.java index c4b7f471..08936a42 100644 --- a/src/main/test/fr/unantes/software/construction/address/MailListTest.java +++ b/src/main/test/fr/unantes/software/construction/address/MailListTest.java @@ -34,7 +34,7 @@ class MailListTest { mailList.set(anotherList); for(Mail each : mails){ - assertTrue(mailList.find(each)); + assertTrue(mailList.contains(each)); } } @@ -47,7 +47,7 @@ class MailListTest { void testAdd_NewMail_addMailToList(){ mailList.add(someMail); - assertTrue(mailList.find(someMail)); + assertTrue(mailList.contains(someMail)); } @Test @@ -60,7 +60,7 @@ class MailListTest { mailList.add(oneMail); mailList.add(anotherMail); - assertTrue(mailList.find(oneMail)); + assertTrue(mailList.contains(oneMail)); assertEquals("anotherWork@mail.com", oneMail.getWork()); assertEquals("someHome@mail.com",oneMail.getHome()); assertEquals(1,mailList.size()); @@ -76,7 +76,7 @@ class MailListTest { mailList.add(oneMail); mailList.add(anotherMail); - assertTrue(mailList.find(oneMail)); + assertTrue(mailList.contains(oneMail)); assertEquals("someWork@mail.com", oneMail.getWork()); assertNotEquals("anotherHome@mail.com",oneMail.getHome()); assertEquals(2,mailList.size()); @@ -92,7 +92,7 @@ class MailListTest { mailList.add(someMail); mailList.delete(someMail); - assertFalse(mailList.find(someMail)); + assertFalse(mailList.contains(someMail)); assertEquals(0,mailList.size()); } @@ -106,10 +106,10 @@ class MailListTest { mailList.delete(anotherMail); - assertTrue(mailList.find(someMail)); - assertFalse(mailList.find(anotherMail)); + assertTrue(mailList.contains(someMail)); + assertFalse(mailList.contains(anotherMail)); - assertTrue(anotherList.find(anotherMail)); + assertTrue(anotherList.contains(anotherMail)); assertEquals(1,anotherList.size()); } @@ -123,7 +123,7 @@ class MailListTest { Mail anotherMail = new Mail("anotherHome@mail.com","anotherWork@mail.com"); mailList.add(someMail); - assertFalse(mailList.find(anotherMail)); + assertFalse(mailList.contains(anotherMail)); } @Test @@ -131,7 +131,7 @@ class MailListTest { Mail anotherMail = new Mail("someHome@mail.com","anotherWork@mail.com"); mailList.add(someMail); - assertTrue(mailList.find(anotherMail)); + assertTrue(mailList.contains(anotherMail)); } @Test @@ -139,7 +139,7 @@ class MailListTest { Mail anotherMail = new Mail("anotherHome@mail.com","someWork@mail.com"); mailList.add(someMail); - assertFalse(mailList.find(anotherMail)); + assertFalse(mailList.contains(anotherMail)); } @Test @@ -153,8 +153,8 @@ class MailListTest { MailList mergedLists = mailList.merge(anotherList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someMail)); - assertTrue(mergedLists.find(anotherMail)); + assertTrue(mergedLists.contains(someMail)); + assertTrue(mergedLists.contains(anotherMail)); assertEquals(2, mergedLists.size()); } @@ -165,7 +165,7 @@ class MailListTest { MailList mergedLists = mailList.merge(mailList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someMail)); + assertTrue(mergedLists.contains(someMail)); assertEquals(mailList.size(), mergedLists.size()); } @@ -196,7 +196,7 @@ class MailListTest { MailList mergedLists = mailList.merge(anotherList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(someMail)); + assertTrue(mergedLists.contains(someMail)); assertEquals(1, mergedLists.size()); } diff --git a/src/main/test/fr/unantes/software/construction/address/PhoneListTest.java b/src/main/test/fr/unantes/software/construction/address/PhoneListTest.java index 536d375e..95909529 100644 --- a/src/main/test/fr/unantes/software/construction/address/PhoneListTest.java +++ b/src/main/test/fr/unantes/software/construction/address/PhoneListTest.java @@ -32,7 +32,7 @@ class PhoneListTest { phoneList.set(anotherList); for(Phone each : phones){ - assertTrue(phoneList.find(each)); + assertTrue(phoneList.contains(each)); } } @@ -45,7 +45,7 @@ class PhoneListTest { void testAdd_NewPhone_addPhoneToList(){ phoneList.add(somePhone); - assertTrue(phoneList.find(somePhone)); + assertTrue(phoneList.contains(somePhone)); } @Test @@ -56,7 +56,7 @@ class PhoneListTest { phoneList.add(onePhone); phoneList.add(anotherPhone); - assertTrue(phoneList.find(onePhone)); + assertTrue(phoneList.contains(onePhone)); assertEquals(1,phoneList.get().size()); } @@ -70,7 +70,7 @@ class PhoneListTest { phoneList.add(somePhone); phoneList.delete(somePhone); - assertFalse(phoneList.find(somePhone)); + assertFalse(phoneList.contains(somePhone)); assertEquals(0,phoneList.get().size()); } @@ -84,10 +84,10 @@ class PhoneListTest { phoneList.delete(anotherPhone); - assertTrue(phoneList.find(somePhone)); - assertFalse(phoneList.find(anotherPhone)); + assertTrue(phoneList.contains(somePhone)); + assertFalse(phoneList.contains(anotherPhone)); - assertTrue(anotherList.find(anotherPhone)); + assertTrue(anotherList.contains(anotherPhone)); assertEquals(1,anotherList.get().size()); } @@ -101,7 +101,7 @@ class PhoneListTest { Phone anotherPhone = new Phone(0606060606,"another comment"); phoneList.add(somePhone); - assertFalse(phoneList.find(anotherPhone)); + assertFalse(phoneList.contains(anotherPhone)); } @Test @@ -109,7 +109,7 @@ class PhoneListTest { Phone anotherPhone = new Phone(somePhone.getPhoneNumber(),"another comment"); phoneList.add(somePhone); - assertTrue(phoneList.find(anotherPhone)); + assertTrue(phoneList.contains(anotherPhone)); } @@ -124,8 +124,8 @@ class PhoneListTest { PhoneList mergedLists = phoneList.merge(anotherList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(somePhone)); - assertTrue(mergedLists.find(anotherPhone)); + assertTrue(mergedLists.contains(somePhone)); + assertTrue(mergedLists.contains(anotherPhone)); assertEquals(2, mergedLists.get().size()); } @@ -136,7 +136,7 @@ class PhoneListTest { PhoneList mergedLists = phoneList.merge(phoneList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(somePhone)); + assertTrue(mergedLists.contains(somePhone)); assertEquals(phoneList.get().size(), mergedLists.get().size()); } @@ -167,7 +167,7 @@ class PhoneListTest { PhoneList mergedLists = phoneList.merge(anotherList); assertNotNull(mergedLists); - assertTrue(mergedLists.find(somePhone)); + assertTrue(mergedLists.contains(somePhone)); assertEquals(1, mergedLists.get().size()); } diff --git a/src/main/test/fr/unantes/software/construction/address/PrivateCardTest.java b/src/main/test/fr/unantes/software/construction/address/PrivateCardTest.java index 2233af30..532a7396 100644 --- a/src/main/test/fr/unantes/software/construction/address/PrivateCardTest.java +++ b/src/main/test/fr/unantes/software/construction/address/PrivateCardTest.java @@ -8,20 +8,20 @@ import static org.junit.jupiter.api.Assertions.*; class PrivateCardTest { PrivateCard someCard; - AddressList someAddresses; PrivateAddress anAddress; + ListWrapper
someAddresses; PrivateAddress anAddress; PhoneList somePhones; Phone aPhone; MailList someMails; Mail aMail; - GroupList someGroups; Group aGroup; + ListWrapper someGroups; Group aGroup; @BeforeEach void setUp() { someCard = new PrivateCard("000"); - someAddresses = new AddressList(); + someAddresses = new ListWrapper
(); somePhones = new PhoneList(); someMails = new MailList(); - someGroups = new GroupList(); + someGroups = new ListWrapper(); anAddress = new PrivateAddress(1, "Some Private Street", new City("Groenland", "Qeqertarsuaq"), 0, null); someAddresses.add(anAddress); @@ -42,7 +42,7 @@ class PrivateCardTest { */ @Test void testSetAddresses_SomeAddressList_Succeed(){ - AddressList someList = new AddressList(); + ListWrapper
someList = new ListWrapper
(); someCard.setAddresses(someList); assertEquals(someList,someCard.getAddresses()); @@ -84,7 +84,7 @@ class PrivateCardTest { @Test void testSetGroups_SomeGroupList_Succeed(){ - GroupList someList = new GroupList(); + ListWrapper someList = new ListWrapper(); someCard.setGroups(someList); assertEquals(someList,someCard.getGroups()); @@ -152,10 +152,10 @@ class PrivateCardTest { void testMerge_PrivateCardWithSameId_ReturnPrivateCardWithBothValues(){ PrivateCard anotherCard = new PrivateCard("000"); - AddressList anotherAddresses = new AddressList(); + ListWrapper
anotherAddresses = new ListWrapper
(); PhoneList anotherPhones = new PhoneList(); MailList anotherMails = new MailList(); - GroupList anotherGroups = new GroupList(); + ListWrapper anotherGroups = new ListWrapper(); PrivateAddress anotherAddress = new PrivateAddress(1, "Another Private Street", new City("France", "Angouleme"), 16000, null); anotherAddresses.add(anotherAddress); @@ -172,16 +172,16 @@ class PrivateCardTest { PrivateCard mergedCard = (PrivateCard) someCard.merge(anotherCard); - assertTrue(mergedCard.getAddresses().find(anAddress)); - assertTrue(mergedCard.getAddresses().find(anotherAddress)); + assertTrue(mergedCard.getAddresses().contains(anAddress)); + assertTrue(mergedCard.getAddresses().contains(anotherAddress)); assertEquals(2,mergedCard.getAddresses().get().size()); - assertTrue(mergedCard.getPhones().find(aPhone)); - assertTrue(mergedCard.getPhones().find(anotherPhone)); + assertTrue(mergedCard.getPhones().contains(aPhone)); + assertTrue(mergedCard.getPhones().contains(anotherPhone)); assertEquals(2,mergedCard.getPhones().get().size()); - assertTrue(mergedCard.getMails().find(aMail)); - assertTrue(mergedCard.getMails().find(anotherMail)); + assertTrue(mergedCard.getMails().contains(aMail)); + assertTrue(mergedCard.getMails().contains(anotherMail)); assertEquals(2,mergedCard.getMails().get().size()); assertTrue(mergedCard.getGroups().find(aGroup)); @@ -195,13 +195,13 @@ class PrivateCardTest { void testMerge_SamePrivateCard_NoChange(){ PrivateCard mergedCard = (PrivateCard) someCard.merge(someCard); - assertTrue(mergedCard.getAddresses().find(anAddress)); + assertTrue(mergedCard.getAddresses().contains(anAddress)); assertEquals(1,mergedCard.getAddresses().get().size()); - assertTrue(mergedCard.getPhones().find(aPhone)); + assertTrue(mergedCard.getPhones().contains(aPhone)); assertEquals(1,mergedCard.getPhones().get().size()); - assertTrue(mergedCard.getMails().find(aMail)); + assertTrue(mergedCard.getMails().contains(aMail)); assertEquals(1,mergedCard.getMails().get().size()); assertTrue(mergedCard.getGroups().find(aGroup)); @@ -212,10 +212,10 @@ class PrivateCardTest { void testMerge_PrivateCardsWithSharedValues_NoDuplicate(){ PrivateCard anotherCard = new PrivateCard("000"); - AddressList anotherAddresses = new AddressList(); + ListWrapper
anotherAddresses = new ListWrapper
(); PhoneList anotherPhones = new PhoneList(); MailList anotherMails = new MailList(); - GroupList anotherGroups = new GroupList(); + ListWrapper anotherGroups = new ListWrapper(); PrivateAddress anotherAddress = new PrivateAddress(1, "Another Private Street", new City("France", "Angouleme"), 16000, null); Phone anotherPhone = new Phone(0642424242, ""); Mail anotherMail = new Mail("anotherHome@mail.com", null); @@ -237,16 +237,16 @@ class PrivateCardTest { PrivateCard mergedCard = (PrivateCard) someCard.merge(anotherCard); - assertTrue(mergedCard.getAddresses().find(anAddress)); - assertTrue(mergedCard.getAddresses().find(anotherAddress)); + assertTrue(mergedCard.getAddresses().contains(anAddress)); + assertTrue(mergedCard.getAddresses().contains(anotherAddress)); assertEquals(2,mergedCard.getAddresses().get().size()); - assertTrue(mergedCard.getPhones().find(aPhone)); - assertTrue(mergedCard.getPhones().find(anotherPhone)); + assertTrue(mergedCard.getPhones().contains(aPhone)); + assertTrue(mergedCard.getPhones().contains(anotherPhone)); assertEquals(2,mergedCard.getPhones().get().size()); - assertTrue(mergedCard.getMails().find(aMail)); - assertTrue(mergedCard.getMails().find(anotherMail)); + assertTrue(mergedCard.getMails().contains(aMail)); + assertTrue(mergedCard.getMails().contains(anotherMail)); assertEquals(2,mergedCard.getMails().get().size()); assertTrue(mergedCard.getGroups().find(aGroup)); diff --git a/src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperAddressTest.java b/src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperAddressTest.java new file mode 100644 index 00000000..91947881 --- /dev/null +++ b/src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperAddressTest.java @@ -0,0 +1,177 @@ +package fr.unantes.software.construction.address.wrapper; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import fr.unantes.software.construction.address.Address; +import fr.unantes.software.construction.address.City; +import fr.unantes.software.construction.address.CompanyAddress; +import fr.unantes.software.construction.address.ListWrapper; +import fr.unantes.software.construction.address.PrivateAddress; +import java.util.ArrayList; +import java.util.List; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class ListWrapperAddressTest { + + ListWrapper
addressList; + Address someAddress; + + @BeforeEach + void setUp() { + addressList = new ListWrapper<>(); + someAddress = new PrivateAddress(1,"Some Private Street", new City("Groenland","Qeqertarsuaq"),0,null); + } + + @Test + void testSet_ListOfGroups_addGroupsToCurrentList(){ + List
anotherList = new ArrayList<>(); + Address[] addresses = { someAddress, + new PrivateAddress(1,"Another Private Street", new City("Norvege","Honningsvag"),0,null), + new CompanyAddress(1,"A Company Street", new City("Australie","Pine Creek"),0,null,null) + }; + + for(Address each : addresses){ + anotherList.add(each); + } + + addressList.set(anotherList); + + for(Address each : addresses){ + assertTrue(addressList.contains(each)); + } + } + + @Test + void testSet_NullValue_ExceptionThrown(){ + assertThrows(Exception.class, ()->addressList.set(null)); + } + + + @Test + public void testAdd_newValue_Succeed(){ + assertDoesNotThrow(() -> addressList.add(someAddress)); + assertTrue(addressList.contains(someAddress)); + } + + @Test + public void testAdd_alreadyContainedValue_noDuplicate(){ + addressList.add(someAddress); + int currentSize = addressList.get().size(); + + addressList.add(someAddress); + assertEquals(currentSize,addressList.get().size()); + } + + @Test + public void testAdd_NullValue_ExceptionThrown(){ + int currentSize = addressList.get().size(); + assertThrows(Exception.class, () -> addressList.add(null)); + assertEquals(currentSize,addressList.get().size()); + } + + @Test + public void testDelete_ContainedValue_Succeed(){ + addressList.add(someAddress); + addressList.delete(someAddress); + + assertFalse(addressList.contains(someAddress)); + } + + @Test + public void testDelete_ValueContainedByAnotherGroup_NoEffect(){ + ListWrapper
anotherList = new ListWrapper<>(); + anotherList.add(someAddress); + + int currentSize = addressList.get().size(); + assertFalse(addressList.contains(someAddress)); + + addressList.delete(someAddress); + assertTrue(anotherList.contains(someAddress)); + assertEquals(currentSize, addressList.get().size()); + } + + @Test + public void testFind_ContainedValue_ReturnTrue(){ + addressList.add(someAddress); + assertTrue(addressList.contains(someAddress)); + } + + @Test + public void testFind_NotContainedValue_ReturnFalse(){ + addressList.add(new PrivateAddress(1,"Another Private Street", new City("Norvege","Honningsvag"),0,null)); + assertFalse(addressList.contains(someAddress)); + } + + @Test + public void testMerge_TwoDifferentLists_ReturnListWithBothValue(){ + addressList.add(someAddress); + + Address anotherAddress = new PrivateAddress(1,"Another Private Street", new City("Norvege","Honningsvag"),0,null); + ListWrapper
anotherList = new ListWrapper<>(); + anotherList.add(anotherAddress); + + ListWrapper
mergedLists = addressList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.contains(someAddress)); + assertTrue(mergedLists.contains(anotherAddress)); + assertEquals(2, mergedLists.get().size()); + } + + @Test + public void testMerge_SameLists_NoChange(){ + addressList.add(someAddress); + + ListWrapper
mergedLists = addressList.merge(addressList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.contains(someAddress)); + assertEquals(addressList.get().size(), mergedLists.get().size()); + } + + @Test + public void testMerge_ListsWithSharedValues_NoDuplicate(){ + Address anotherAddress = new PrivateAddress(1,"Another Private Street", new City("Norvege","Honningsvag"),0,null); + + addressList.add(someAddress); + addressList.add(anotherAddress); + + ListWrapper
anotherList = new ListWrapper<>(); + anotherList.add(anotherAddress); + + ListWrapper
mergedLists = addressList.merge(anotherList); + + assertNotNull(mergedLists); + assertEquals(2, mergedLists.get().size()); + + + } + @Test + public void testMerge_EmptyGroupList_SameGroupList(){ + ListWrapper
anotherList = new ListWrapper<>(); + + addressList.add(someAddress); + + ListWrapper
mergedLists = addressList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.contains(someAddress)); + assertEquals(1, mergedLists.get().size()); + } + + @Test + public void testMerge_NullGroupList_ExceptionThrown(){ + addressList.add(someAddress); + + assertThrows(NullPointerException.class, ()->addressList.merge(null)); + } + + + +} \ No newline at end of file diff --git a/src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperCardTest.java b/src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperCardTest.java new file mode 100644 index 00000000..c0fac659 --- /dev/null +++ b/src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperCardTest.java @@ -0,0 +1,173 @@ +package fr.unantes.software.construction.address.wrapper; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import fr.unantes.software.construction.address.Card; +import fr.unantes.software.construction.address.CompanyCard; +import fr.unantes.software.construction.address.ListWrapper; +import fr.unantes.software.construction.address.PrivateCard; +import java.util.ArrayList; +import java.util.List; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class ListWrapperCardTest { + ListWrapper cardList; + Card someCard; + @BeforeEach + void setUp() { + cardList = new ListWrapper<>(); + someCard = new PrivateCard("John","Doe"); + } + + @Test + void testSet_ListOfCards_addCardsToCurrentList(){ + List anotherList = new ArrayList<>(); + Card[] cards = { someCard, + new PrivateCard("Tom","Joe"), + new CompanyCard("JohnDoe Corp.") + }; + + for(Card each : cards){ + anotherList.add(each); + } + + cardList.set(anotherList); + + for(Card each : cards){ + assertTrue(cardList.contains(each)); + } + } + + @Test + void testSet_NullValue_ExceptionThrown(){ + assertThrows(Exception.class, ()-> cardList.set(null)); + } + + + @Test + public void testAdd_newValue_Succeed(){ + assertDoesNotThrow(() -> cardList.add(someCard)); + assertTrue(cardList.contains(someCard)); + } + + @Test + public void testAdd_alreadyContainedValue_noDuplicate(){ + cardList.add(someCard); + int currentSize = cardList.get().size(); + + cardList.add(someCard); + assertEquals(currentSize, cardList.get().size()); + } + + @Test + public void testAdd_NullValue_ExceptionThrown(){ + int currentSize = cardList.get().size(); + assertThrows(Exception.class, () -> cardList.add(null)); + assertEquals(currentSize, cardList.get().size()); + } + + @Test + public void testDelete_ContainedValue_Succeed(){ + cardList.add(someCard); + cardList.delete(someCard); + + assertFalse(cardList.contains(someCard)); + } + + @Test + public void testDelete_ValueContainedByAnotherGroup_NoEffect(){ + ListWrapper anotherList = new ListWrapper<>(); + anotherList.add(someCard); + + int currentSize = cardList.get().size(); + assertFalse(cardList.contains(someCard)); + + cardList.delete(someCard); + assertTrue(anotherList.contains(someCard)); + assertEquals(currentSize, cardList.get().size()); + } + + @Test + public void testFind_ContainedValue_ReturnTrue(){ + cardList.add(someCard); + assertTrue(cardList.contains(someCard)); + } + + @Test + public void testFind_NotContainedValue_ReturnFalse(){ + cardList.add(new PrivateCard("Tom","Joe")); + assertFalse(cardList.contains(someCard)); + } + + @Test + public void testMerge_TwoDifferentLists_ReturnListWithBothValue(){ + cardList.add(someCard); + + Card anotherCard = new PrivateCard("Tom", "Joe"); + ListWrapper anotherList = new ListWrapper<>(); + anotherList.add(anotherCard); + + ListWrapper mergedLists = cardList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.contains(someCard)); + assertTrue(mergedLists.contains(anotherCard)); + assertEquals(2, mergedLists.get().size()); + } + + @Test + public void testMerge_SameLists_NoChange(){ + cardList.add(someCard); + + ListWrapper mergedLists = cardList.merge(cardList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.contains(someCard)); + assertEquals(cardList.get().size(), mergedLists.get().size()); + } + + @Test + public void testMerge_ListsWithSharedValues_NoDuplicate(){ + Card anotherCard = new PrivateCard("Tom", "Joe"); + + cardList.add(someCard); + cardList.add(anotherCard); + + ListWrapper anotherList = new ListWrapper<>(); + anotherList.add(anotherCard); + + ListWrapper mergedLists = cardList.merge(anotherList); + + assertNotNull(mergedLists); + assertEquals(2, mergedLists.get().size()); + + + } + @Test + public void testMerge_EmptyCardList_SameCardList(){ + ListWrapper anotherList = new ListWrapper<>(); + + cardList.add(someCard); + + ListWrapper mergedLists = cardList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.contains(someCard)); + assertEquals(1, mergedLists.get().size()); + } + + @Test + public void testMerge_NullCardList_ExceptionThrown(){ + cardList.add(someCard); + + assertThrows(NullPointerException.class, ()-> cardList.merge(null)); + } + + +} \ No newline at end of file diff --git a/src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperGroupTest.java b/src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperGroupTest.java new file mode 100644 index 00000000..cd9e6c65 --- /dev/null +++ b/src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperGroupTest.java @@ -0,0 +1,172 @@ +package fr.unantes.software.construction.address.wrapper; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import fr.unantes.software.construction.address.Group; +import fr.unantes.software.construction.address.ListWrapper; +import java.util.Vector; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class ListWrapperGroupTest { + + ListWrapper groupList; + Group someGroup; + + @BeforeEach + void setUp() { + groupList = new ListWrapper(); + someGroup = new Group("a Group",""); + } + + @Test + void testSet_ListOfGroups_addGroupsToCurrentList(){ + Vector anotherList = new Vector(); + Group[] groups = { someGroup, + new Group("Group1",null), + new Group("Group2","Comment2"), + }; + + for(Group each : groups){ + anotherList.add(each); + } + + groupList.set(anotherList); + + for(Group each : groups){ + assertTrue(groupList.contains(each)); + } + } + + @Test + void testSet_NullValue_ExceptionThrown(){ + assertThrows(Exception.class, ()->groupList.set(null)); + } + + + @Test + public void testAdd_newValue_Succeed(){ + assertDoesNotThrow(() -> groupList.add(someGroup)); + assertTrue(groupList.contains(someGroup)); + } + + @Test + public void testAdd_alreadyContainedValue_noDuplicate(){ + groupList.add(someGroup); + int currentSize = groupList.size(); + + groupList.add(someGroup); + assertEquals(currentSize,groupList.size()); + } + + @Test + public void testAdd_NullValue_ExceptionThrown(){ + int currentSize = groupList.size(); + assertThrows(Exception.class, () -> groupList.add(null)); + assertEquals(currentSize,groupList.size()); + } + + @Test + public void testDelete_ContainedValue_Succeed(){ + groupList.add(someGroup); + groupList.delete(someGroup); + + assertFalse(groupList.contains(someGroup)); + } + + @Test + public void testDelete_ValueContainedByAnotherGroup_NoEffect(){ + ListWrapper anotherList = new ListWrapper(); + anotherList.add(someGroup); + + int currentSize = groupList.size(); + assertFalse(groupList.contains(someGroup)); + + groupList.delete(someGroup); + assertTrue(anotherList.contains(someGroup)); + assertEquals(currentSize, groupList.size()); + } + + @Test + public void testFind_ContainedValue_ReturnTrue(){ + groupList.add(someGroup); + assertTrue(groupList.contains(someGroup)); + } + + @Test + public void testFind_NotContainedValue_ReturnFalse(){ + groupList.add(new Group("anotherGroup", "")); + assertFalse(groupList.contains(someGroup)); + } + + @Test + public void testMerge_TwoDifferentLists_ReturnListWithBothValue(){ + groupList.add(someGroup); + + Group anotherGroup = new Group("secondGroup", ""); + ListWrapper anotherList = new ListWrapper(); + anotherList.add(anotherGroup); + + ListWrapper mergedLists = groupList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.contains(someGroup)); + assertTrue(mergedLists.contains(anotherGroup)); + assertEquals(2, mergedLists.size()); + } + + @Test + public void testMerge_SameLists_NoChange(){ + groupList.add(someGroup); + + ListWrapper mergedLists = groupList.merge(groupList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.contains(someGroup)); + assertEquals(groupList.size(), mergedLists.size()); + } + + @Test + public void testMerge_ListsWithSharedValues_NoDuplicate(){ + Group anotherGroup = new Group("secondGroup", ""); + + groupList.add(someGroup); + groupList.add(anotherGroup); + + ListWrapper anotherList = new ListWrapper(); + anotherList.add(anotherGroup); + + ListWrapper mergedLists = groupList.merge(anotherList); + + assertNotNull(mergedLists); + assertEquals(2, mergedLists.size()); + + + } + @Test + public void testMerge_EmptyGroupList_SameGroupList(){ + ListWrapper anotherList = new ListWrapper(); + + groupList.add(someGroup); + + ListWrapper mergedLists = groupList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.contains(someGroup)); + assertEquals(1, mergedLists.size()); + } + + @Test + public void testMerge_NullGroupList_ExceptionThrown(){ + groupList.add(someGroup); + + assertThrows(NullPointerException.class, ()->groupList.merge(null)); + } + + +} \ No newline at end of file diff --git a/src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperMailTest.java b/src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperMailTest.java new file mode 100644 index 00000000..ed4cb452 --- /dev/null +++ b/src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperMailTest.java @@ -0,0 +1,217 @@ +package fr.unantes.software.construction.address.wrapper; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import fr.unantes.software.construction.address.ListWrapper; +import fr.unantes.software.construction.address.Mail; +import java.util.Vector; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class ListWrapperMailTest { + + ListWrapper mailList; + Mail someMail; + + @BeforeEach + void setUp() { + mailList = new ListWrapper(); + someMail = new Mail("someHome@mail.com","someWork@mail.com"); + } + + @Test + void testSet_ListOfMails_addMailsToCurrentList(){ + Vector anotherList = new Vector(); + Mail[] mails = { new Mail(null,null), + new Mail("home1@mail.com",null), + new Mail(null, "work1@mail.co.jp"), + new Mail("home2@mail.fr","work2@mail.fr") + }; + + for(Mail each : mails){ + anotherList.add(each); + } + + mailList.set(anotherList); + + for(Mail each : mails){ + assertTrue(mailList.contains(each)); + } + } + + @Test + void testSet_NullValue_ExceptionThrown(){ + assertThrows(Exception.class, ()->mailList.set(null)); + } + + @Test + void testAdd_NewMail_addMailToList(){ + mailList.add(someMail); + + assertTrue(mailList.contains(someMail)); + } + + @Test + void testAdd_AlreadyExistingHomeMail_Fusion(){ + Mail oneMail = new Mail("someHome@mail.com",null); + Mail anotherMail = new Mail("someHome@mail.com","anotherWork@mail.com"); + + assertEquals(oneMail.getHome(),anotherMail.getHome()); + + mailList.add(oneMail); + mailList.add(anotherMail); + + assertTrue(mailList.contains(oneMail)); + assertEquals("anotherWork@mail.com", oneMail.getWork()); + assertEquals("someHome@mail.com",oneMail.getHome()); + assertEquals(1,mailList.size()); + } + + @Test + void testAdd_AlreadyExistingWorkMail_NoFusion(){ + Mail oneMail = new Mail(null,"someWork@mail.com"); + Mail anotherMail = new Mail("anotherHome@mail.com","someWork@mail.com"); + + assertEquals(oneMail.getWork(),anotherMail.getWork()); + + mailList.add(oneMail); + mailList.add(anotherMail); + + assertTrue(mailList.contains(oneMail)); + assertEquals("someWork@mail.com", oneMail.getWork()); + assertNotEquals("anotherHome@mail.com",oneMail.getHome()); + assertEquals(2,mailList.size()); + } + + @Test + void testAdd_Null_ExceptionThrown(){ + assertThrows(NullPointerException.class, () -> mailList.add(null)); + } + + @Test + void testDelete_ExistingMail_Succeed(){ + mailList.add(someMail); + + mailList.delete(someMail); + assertFalse(mailList.contains(someMail)); + assertEquals(0,mailList.size()); + } + + @Test + void testDelete_NotContainedMail_NoEffect(){ + ListWrapper anotherList = new ListWrapper<>(); + Mail anotherMail = new Mail(null,null); + + mailList.add(someMail); + anotherList.add(anotherMail); + + mailList.delete(anotherMail); + + assertTrue(mailList.contains(someMail)); + assertFalse(mailList.contains(anotherMail)); + + assertTrue(anotherList.contains(anotherMail)); + assertEquals(1,anotherList.size()); + } + + @Test + void testDelete_NullValue_ExceptionThrown(){ + assertThrows(NullPointerException.class, () -> mailList.delete(null)); + } + + @Test + void testFind_NoMailInCommon_ReturnFalse(){ + Mail anotherMail = new Mail("anotherHome@mail.com","anotherWork@mail.com"); + + mailList.add(someMail); + assertFalse(mailList.contains(anotherMail)); + } + + @Test + void testFind_HomeMailInCommon_ReturnTrue(){ + Mail anotherMail = new Mail("someHome@mail.com","anotherWork@mail.com"); + + mailList.add(someMail); + assertTrue(mailList.contains(anotherMail)); + } + + @Test + void testFind_WorkMailInCommon_ReturnFalse(){ + Mail anotherMail = new Mail("anotherHome@mail.com","someWork@mail.com"); + + mailList.add(someMail); + assertFalse(mailList.contains(anotherMail)); + } + + @Test + public void testMerge_TwoDifferentLists_ReturnListWithBothValue(){ + mailList.add(someMail); + + Mail anotherMail = new Mail("anotherHome@mail.com", "anotherWork@mail.com"); + ListWrapper anotherList = new ListWrapper(); + anotherList.add(anotherMail); + + ListWrapper mergedLists = mailList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.contains(someMail)); + assertTrue(mergedLists.contains(anotherMail)); + assertEquals(2, mergedLists.size()); + } + + @Test + public void testMerge_SameLists_NoChange(){ + mailList.add(someMail); + + ListWrapper mergedLists = mailList.merge(mailList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.contains(someMail)); + assertEquals(mailList.size(), mergedLists.size()); + } + + @Test + public void testMerge_ListsWithSharedValues_NoDuplicate(){ + Mail anotherMail = new Mail("anotherHome@mail.com", "anotherWork@mail.com"); + + + mailList.add(someMail); + mailList.add(anotherMail); + + ListWrapper anotherList = new ListWrapper(); + anotherList.add(anotherMail); + + ListWrapper mergedLists = mailList.merge(anotherList); + + assertNotNull(mergedLists); + assertEquals(2, mergedLists.size()); + + + } + @Test + public void testMerge_EmptyMailList_SameGroupList(){ + ListWrapper anotherList = new ListWrapper(); + + mailList.add(someMail); + + ListWrapper mergedLists = mailList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.contains(someMail)); + assertEquals(1, mergedLists.size()); + } + + @Test + public void testMerge_NullGroupList_ExceptionThrown(){ + mailList.add(someMail); + + assertThrows(NullPointerException.class, ()->mailList.merge(null)); + } + + +} \ No newline at end of file diff --git a/src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperPhoneTest.java b/src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperPhoneTest.java new file mode 100644 index 00000000..3a8b996d --- /dev/null +++ b/src/main/test/fr/unantes/software/construction/address/wrapper/ListWrapperPhoneTest.java @@ -0,0 +1,185 @@ +package fr.unantes.software.construction.address.wrapper; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import fr.unantes.software.construction.address.ListWrapper; +import fr.unantes.software.construction.address.Phone; +import java.util.Vector; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class ListWrapperPhoneTest { + + ListWrapper phoneList = new ListWrapper<>(); + Phone somePhone; + + @BeforeEach + void setUp() { + somePhone = new Phone(0600000000,"some comment"); + } + + @Test + void testSet_ListOfPhones_addPhonesToCurrentList(){ + Vector anotherList = new Vector<>(); + Phone[] phones = { somePhone, + new Phone(0600000001,null), + new Phone(0600000010,"another comment") + }; + + for(Phone each : phones){ + anotherList.add(each); + } + + phoneList.set(anotherList); + + for(Phone each : phones){ + assertTrue(phoneList.contains(each)); + } + } + + @Test + void testSet_NullValue_ExceptionThrown(){ + assertThrows(Exception.class, ()->phoneList.set(null)); + } + + @Test + void testAdd_NewPhone_addPhoneToList(){ + phoneList.add(somePhone); + + assertTrue(phoneList.contains(somePhone)); + } + + @Test + void testAdd_AlreadyExistingPhone_Fusion(){ + Phone onePhone = new Phone(somePhone.getPhoneNumber(), null); + Phone anotherPhone = new Phone(somePhone.getPhoneNumber(), "a different comment"); + + phoneList.add(onePhone); + phoneList.add(anotherPhone); + + assertTrue(phoneList.contains(onePhone)); + assertEquals(1,phoneList.get().size()); + } + + @Test + void testFind_PhoneNumberInCommon_ReturnTrue(){ + Phone anotherPhone = new Phone(somePhone.getPhoneNumber(),"another comment"); + + phoneList.add(somePhone); + assertTrue(phoneList.contains(anotherPhone)); + } + + @Test + void testAdd_Null_ExceptionThrown(){ + assertThrows(NullPointerException.class, () -> phoneList.add(null)); + } + + @Test + void testDelete_ExistingMail_Succeed(){ + phoneList.add(somePhone); + + phoneList.delete(somePhone); + assertFalse(phoneList.contains(somePhone)); + assertEquals(0,phoneList.get().size()); + } + + @Test + void testDelete_NotContainedMail_NoEffect(){ + ListWrapper anotherList = new ListWrapper(); + Phone anotherPhone = new Phone(0606060606,"another comment"); + + phoneList.add(somePhone); + anotherList.add(anotherPhone); + + phoneList.delete(anotherPhone); + + assertTrue(phoneList.contains(somePhone)); + assertFalse(phoneList.contains(anotherPhone)); + + assertTrue(anotherList.contains(anotherPhone)); + assertEquals(1,anotherList.get().size()); + } + + @Test + void testDelete_NullValue_ExceptionThrown(){ + assertThrows(NullPointerException.class, () -> phoneList.delete(null)); + } + + @Test + void testFind_NoPhoneInCommon_ReturnFalse(){ + Phone anotherPhone = new Phone(0606060606,"another comment"); + + phoneList.add(somePhone); + assertFalse(phoneList.contains(anotherPhone)); + } + + + @Test + public void testMerge_TwoDifferentLists_ReturnListWithBothValue(){ + phoneList.add(somePhone); + + ListWrapper anotherList = new ListWrapper(); + Phone anotherPhone = new Phone(0606060606,"another comment"); + anotherList.add(anotherPhone); + + ListWrapper mergedLists = phoneList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.contains(somePhone)); + assertTrue(mergedLists.contains(anotherPhone)); + assertEquals(2, mergedLists.get().size()); + } + + @Test + public void testMerge_SameLists_NoChange(){ + phoneList.add(somePhone); + + ListWrapper mergedLists = phoneList.merge(phoneList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.contains(somePhone)); + assertEquals(phoneList.get().size(), mergedLists.get().size()); + } + + @Test + public void testMerge_ListsWithSharedValues_NoDuplicate(){ + ListWrapper anotherList = new ListWrapper(); + Phone anotherPhone = new Phone(0606060606,"another comment"); + + + phoneList.add(somePhone); + phoneList.add(anotherPhone); + + anotherList.add(anotherPhone); + + ListWrapper mergedLists = phoneList.merge(anotherList); + + assertNotNull(mergedLists); + assertEquals(2, mergedLists.get().size()); + + + } + @Test + public void testMerge_EmptyPhoneList_SameGroupList(){ + ListWrapper anotherList = new ListWrapper(); + + phoneList.add(somePhone); + + ListWrapper mergedLists = phoneList.merge(anotherList); + + assertNotNull(mergedLists); + assertTrue(mergedLists.contains(somePhone)); + assertEquals(1, mergedLists.get().size()); + } + + @Test + public void testMerge_NullGroupList_ExceptionThrown(){ + phoneList.add(somePhone); + assertThrows(NullPointerException.class, ()->phoneList.merge(null)); + } + +} \ No newline at end of file -- GitLab From fa27fc2b531dca934cb8d8c00a0b2ad9eb35038c Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Thu, 26 Mar 2020 14:22:29 +0100 Subject: [PATCH 090/120] Modified Card and related tests to differenciate roles --- .../software/construction/address/Card.java | 9 ++++++++- .../construction/address/CompanyCardTest.java | 20 +++++++++++++++++-- .../construction/address/PrivateCardTest.java | 20 +++++++++++++++++-- 3 files changed, 44 insertions(+), 5 deletions(-) diff --git a/src/main/java/fr/unantes/software/construction/address/Card.java b/src/main/java/fr/unantes/software/construction/address/Card.java index a0bec384..0957ee46 100755 --- a/src/main/java/fr/unantes/software/construction/address/Card.java +++ b/src/main/java/fr/unantes/software/construction/address/Card.java @@ -4,6 +4,7 @@ import fr.unantes.software.construction.Client; import fr.unantes.software.construction.references.SingleReference; import org.apache.commons.lang3.Validate; +import java.util.Iterator; import java.util.UUID; /** @@ -63,7 +64,13 @@ public abstract class Card { */ public void setAddresses(AddressList addresses) { Validate.notNull(addresses); - this.addresses = addresses; + Iterator
it = addresses.get().iterator(); + Address nextValue; + while(it.hasNext()){ + nextValue = it.next(); + if(nextValue.getRole().equals(getOwner().get().getRole())) + this.addresses.add(nextValue); + } } /** diff --git a/src/main/test/fr/unantes/software/construction/address/CompanyCardTest.java b/src/main/test/fr/unantes/software/construction/address/CompanyCardTest.java index 7512e7e3..28048b25 100644 --- a/src/main/test/fr/unantes/software/construction/address/CompanyCardTest.java +++ b/src/main/test/fr/unantes/software/construction/address/CompanyCardTest.java @@ -19,11 +19,27 @@ class CompanyCardTest { * Superclass related tests */ @Test - void testSetAddresses_SomeAddressList_Succeed(){ + void testSetAddresses_CompanyAddressList_Succeed(){ AddressList someList = new AddressList(); + CompanyAddress companyAddress = new CompanyAddress(1,"",new City("",""),48150,null,null); + someList.add(companyAddress); + + companyCard.setAddresses(someList); + + assertTrue(companyCard.getAddresses().find(companyAddress)); + } + + @Test + void testSetAddresses_AddressListContainingPrivateAddress_OnlyKeepCompany(){ + AddressList someList = new AddressList(); + CompanyAddress companyAddress = new CompanyAddress(1,"",new City("",""),48150,null,null); + someList.add(companyAddress); + PrivateAddress privateAddress = new PrivateAddress(1,"",new City("",""),48150,null); + someList.add(privateAddress); companyCard.setAddresses(someList); - assertEquals(someList, companyCard.getAddresses()); + assertTrue(companyCard.getAddresses().find(companyAddress)); + assertFalse(companyCard.getAddresses().find(privateAddress)); } @Test diff --git a/src/main/test/fr/unantes/software/construction/address/PrivateCardTest.java b/src/main/test/fr/unantes/software/construction/address/PrivateCardTest.java index 11206a2c..645497cc 100644 --- a/src/main/test/fr/unantes/software/construction/address/PrivateCardTest.java +++ b/src/main/test/fr/unantes/software/construction/address/PrivateCardTest.java @@ -20,11 +20,27 @@ class PrivateCardTest { * Superclass related tests */ @Test - void testSetAddresses_SomeAddressList_Succeed(){ + void testSetAddresses_CompanyAddressList_Succeed(){ AddressList someList = new AddressList(); + PrivateAddress privateAddress = new PrivateAddress(1,"",new City("",""),48150,null); + someList.add(privateAddress); + + someCard.setAddresses(someList); + + assertTrue(someCard.getAddresses().find(privateAddress)); + } + + @Test + void testSetAddresses_AddressListContainingPrivateAddress_OnlyKeepCompany(){ + AddressList someList = new AddressList(); + CompanyAddress companyAddress = new CompanyAddress(1,"",new City("",""),48150,null,null); + someList.add(companyAddress); + PrivateAddress privateAddress = new PrivateAddress(1,"",new City("",""),48150,null); + someList.add(privateAddress); someCard.setAddresses(someList); - assertEquals(someList,someCard.getAddresses()); + assertTrue(someCard.getAddresses().find(privateAddress)); + assertFalse(someCard.getAddresses().find(companyAddress)); } @Test -- GitLab From 4cc7e6add45ecd704b0729b9e4f043a9978b17b9 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Thu, 26 Mar 2020 14:31:33 +0100 Subject: [PATCH 091/120] Fixed errors in tests name --- .../software/construction/address/PrivateCardTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/test/fr/unantes/software/construction/address/PrivateCardTest.java b/src/main/test/fr/unantes/software/construction/address/PrivateCardTest.java index 645497cc..b5d72081 100644 --- a/src/main/test/fr/unantes/software/construction/address/PrivateCardTest.java +++ b/src/main/test/fr/unantes/software/construction/address/PrivateCardTest.java @@ -20,7 +20,7 @@ class PrivateCardTest { * Superclass related tests */ @Test - void testSetAddresses_CompanyAddressList_Succeed(){ + void testSetAddresses_PrivateAddressList_Succeed(){ AddressList someList = new AddressList(); PrivateAddress privateAddress = new PrivateAddress(1,"",new City("",""),48150,null); someList.add(privateAddress); @@ -31,7 +31,7 @@ class PrivateCardTest { } @Test - void testSetAddresses_AddressListContainingPrivateAddress_OnlyKeepCompany(){ + void testSetAddresses_AddressListContainingCompanyAddress_OnlyKeepPrivate(){ AddressList someList = new AddressList(); CompanyAddress companyAddress = new CompanyAddress(1,"",new City("",""),48150,null,null); someList.add(companyAddress); -- GitLab From f346beec6e554cde30bf0ce3e790e0a85077f066 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Thu, 26 Mar 2020 15:20:00 +0100 Subject: [PATCH 092/120] Added tests to handle role restriction with account --- .../software/construction/AccountTest.java | 32 ++++++++++++++++--- .../construction/CompanyClientTest.java | 28 ++++++++++++++++ .../construction/PrivateClientTest.java | 27 ++++++++++++++++ 3 files changed, 83 insertions(+), 4 deletions(-) diff --git a/src/main/test/fr/unantes/software/construction/AccountTest.java b/src/main/test/fr/unantes/software/construction/AccountTest.java index c4c45a2f..946d74f7 100644 --- a/src/main/test/fr/unantes/software/construction/AccountTest.java +++ b/src/main/test/fr/unantes/software/construction/AccountTest.java @@ -2,6 +2,8 @@ package fr.unantes.software.construction; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.shadow.com.univocity.parsers.annotations.Validate; + import java.time.LocalDateTime; import static org.junit.jupiter.api.Assertions.*; @@ -174,9 +176,30 @@ class AccountTest { } + @Test + void testAddOwners_DifferentRoleClients_ExceptionThrown(){ + Account newAccount = new Account(null,50,0); + + Client privateClient = new PrivateClient("Phillippe", "Chappuis"); + Client companyClient = new CompanyClient("Zep"); + + newAccount.addOwner(privateClient); + + assertTrue(newAccount.getOwner().contains(privateClient)); + assertThrows(Exception.class, () -> newAccount.addOwner(companyClient)); + + newAccount.removeOwner(privateClient); + newAccount.addOwner(companyClient); + + assertTrue(newAccount.getOwner().contains(companyClient)); + assertThrows(Exception.class, () -> newAccount.addOwner(privateClient)); + + } + @Test void testRemoveOwner_AlreadyExistingOwner_NoDuplicate(){ Account newAccount = new Account(null,50,0); + PrivateClient client = new PrivateClient("Dupuis"); newAccount.addOwner(client); assertTrue(newAccount.getOwner().contains(client)); @@ -194,13 +217,14 @@ class AccountTest { @Test void testRemoveOwner_ExistingOwner_RemoveFromReferences(){ + Account newAccount = new Account(null, 0,0); PrivateClient client = new PrivateClient("Dupuis"); - account.addOwner(client); - assertTrue(account.getOwner().contains(client)); + newAccount.addOwner(client); + assertTrue(newAccount.getOwner().contains(client)); - account.removeOwner(client); + newAccount.removeOwner(client); - assertFalse(account.getOwner().contains(client)); + assertFalse(newAccount.getOwner().contains(client)); } @Test diff --git a/src/main/test/fr/unantes/software/construction/CompanyClientTest.java b/src/main/test/fr/unantes/software/construction/CompanyClientTest.java index 113aee98..fe329b32 100644 --- a/src/main/test/fr/unantes/software/construction/CompanyClientTest.java +++ b/src/main/test/fr/unantes/software/construction/CompanyClientTest.java @@ -53,4 +53,32 @@ class CompanyClientTest { public void testSetAddress_NullAddress_ExceptionThrown() { assertThrows(Exception.class, () -> client.setAddress(null)); } + + @Test + public void testAddAccount_SharedWithNoOne_Succeed(){ + Account account = new Account(null, 0,0); + assertNull(account.getRole()); + + client.addAccount(account); + + assertTrue(client.containsAccount(account)); + assertEquals(client.getRole(), account.getRole()); + } + + @Test + public void testAddAccount_SharedWithCompanyOwner_Succeed(){ + Account account = new Account(new CompanyClient("Doe Corp."), 0,0); + + client.addAccount(account); + + assertTrue(client.containsAccount(account)); + } + + @Test + public void testAddAccount_SharedWithPrivateOwner_ExceptionThrown(){ + Account account = new Account(new PrivateClient("Doe"), 0,0); + + assertThrows(Exception.class, () -> client.addAccount(account)); + + } } \ No newline at end of file diff --git a/src/main/test/fr/unantes/software/construction/PrivateClientTest.java b/src/main/test/fr/unantes/software/construction/PrivateClientTest.java index f9f27ce0..b1429b8d 100644 --- a/src/main/test/fr/unantes/software/construction/PrivateClientTest.java +++ b/src/main/test/fr/unantes/software/construction/PrivateClientTest.java @@ -62,4 +62,31 @@ class PrivateClientTest { public void testSetAddress_NullAddress_ExceptionThrown() { assertThrows(Exception.class, () -> client.setAddress(null)); } + + @Test + public void testAddAccount_SharedWithNoOne_Succeed(){ + Account account = new Account(null, 0,0); + assertNull(account.getRole()); + + client.addAccount(account); + + assertTrue(client.containsAccount(account)); + assertEquals(client.getRole(), account.getRole()); + } + + @Test + public void testAddAccount_SharedWithPrivateOwner_Succeed(){ + Account account = new Account(new PrivateClient("Doe"), 0,0); + + client.addAccount(account); + + assertTrue(client.containsAccount(account)); + } + + @Test + public void testAddAccount_SharedWithCompanyOwner_ExceptionThrown(){ + Account account = new Account(new CompanyClient("Doe Corp."), 0,0); + + assertThrows(Exception.class, () -> client.addAccount(account)); + } } \ No newline at end of file -- GitLab From 8570d62b12cb342bd5c96f0246c79e253dc52daa Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Thu, 26 Mar 2020 15:20:32 +0100 Subject: [PATCH 093/120] Modified Client and Account to match new behavior --- .../fr/unantes/software/construction/Account.java | 14 ++++++++++++++ .../fr/unantes/software/construction/Client.java | 4 +++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/java/fr/unantes/software/construction/Account.java b/src/main/java/fr/unantes/software/construction/Account.java index 13fc26df..a91d7ffa 100755 --- a/src/main/java/fr/unantes/software/construction/Account.java +++ b/src/main/java/fr/unantes/software/construction/Account.java @@ -5,6 +5,7 @@ import fr.unantes.software.construction.references.MultipleReference; import fr.unantes.software.construction.references.OneToManyReference; import org.apache.commons.lang3.Validate; +import javax.management.relation.Role; import java.time.LocalDateTime; import java.util.UUID; @@ -136,6 +137,8 @@ public class Account { * */ public void addOwner(Client owner) { + if(hasRole()) + Validate.isTrue(getRole().equals(owner.getRole())); getOwner().add(owner); } /** @@ -147,6 +150,17 @@ public class Account { getOwner().remove(owner); } + public String getRole(){ + if(hasRole()) + return getOwner().get(0).getRole(); + else + return null; + } + + public boolean hasRole(){ + return getOwner().size()>0; + } + public void addHistory(Operation o) { operations.add(o); o.setAccount(this); diff --git a/src/main/java/fr/unantes/software/construction/Client.java b/src/main/java/fr/unantes/software/construction/Client.java index e6131dfd..543c568a 100644 --- a/src/main/java/fr/unantes/software/construction/Client.java +++ b/src/main/java/fr/unantes/software/construction/Client.java @@ -63,7 +63,7 @@ public abstract class Client { public void setAccounts(Account[] value) { for(Account each : value){ if(!containsAccount(each)) - accounts.add(each); + addAccount(each); } } @@ -72,6 +72,8 @@ public abstract class Client { * @uml.property name="accounts" */ public void addAccount(Account element) { + if(element.hasRole()) + Validate.isTrue(getRole().equals(element.getRole())); accounts.add(element); } -- GitLab From 3103d29ea4e41de3f2ab70ab0fe9434bc0a8b093 Mon Sep 17 00:00:00 2001 From: Eleonore BURGAUD Date: Wed, 1 Apr 2020 10:35:12 +0200 Subject: [PATCH 094/120] First GUI implementation for login --- pom.xml | 20 ++++++ .../ui/GraphicalUserInterface.java | 47 ++++-------- .../construction/ui/HomeController.java | 4 ++ .../construction/ui/LoginController.java | 71 +++++++++++++++++++ src/main/resources/homeView.fxml | 14 ++++ src/main/resources/loginView.fxml | 18 +++++ 6 files changed, 139 insertions(+), 35 deletions(-) create mode 100644 src/main/java/fr/unantes/software/construction/ui/HomeController.java create mode 100644 src/main/java/fr/unantes/software/construction/ui/LoginController.java create mode 100644 src/main/resources/homeView.fxml create mode 100644 src/main/resources/loginView.fxml diff --git a/pom.xml b/pom.xml index c8b4cae8..adb7e1eb 100644 --- a/pom.xml +++ b/pom.xml @@ -80,6 +80,26 @@ javafx-controls 13 + + org.openjfx + javafx-fxml + 11.0.1 + + + org.openjfx + javafx-fxml + 11.0.1 + + + org.openjfx + javafx-fxml + 11.0.1 + + + com.lambdaworks + scrypt + 1.4.0 + diff --git a/src/main/java/fr/unantes/software/construction/ui/GraphicalUserInterface.java b/src/main/java/fr/unantes/software/construction/ui/GraphicalUserInterface.java index e279aa73..effbe86f 100644 --- a/src/main/java/fr/unantes/software/construction/ui/GraphicalUserInterface.java +++ b/src/main/java/fr/unantes/software/construction/ui/GraphicalUserInterface.java @@ -1,45 +1,22 @@ package fr.unantes.software.construction.ui; import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; import javafx.scene.Scene; -import javafx.scene.control.Button; -import javafx.scene.control.Label; -import javafx.scene.control.TextField; -import javafx.scene.layout.GridPane; import javafx.stage.Stage; public class GraphicalUserInterface extends Application { - - public void start(Stage stage) throws Exception { - GridPane root = new GridPane(); - - // name box - TextField field1 = new TextField(); - Label lbl1 = new Label("Name:"); - lbl1.setLabelFor(field1); - Button loginButton = new Button(); - - // password box - TextField field2 = new TextField(); - Label lbl2 = new Label("Password:"); - lbl1.setLabelFor(field2); - - - loginButton.setText("Login"); - /* - loginButton.setOnAction(event -> { - System.out.println("login with name=" + field1.getText() + " and password=" + field2.getText()); - }); - */ - - root.add(lbl1, 0, 0); - root.add(field1, 2, 0); - root.add(lbl2, 0, 1); - root.add(field2, 2, 1); - root.add(loginButton, 0, 3); - - Scene scene = new Scene(root, 280, 200); - stage.setScene(scene); + public LoginController loginController; + public FXMLLoader loadLogin; + + public void start(Stage stage) throws Exception {loadLogin = new FXMLLoader(getClass().getResource("/loginView.fxml")); + Parent root = loadLogin.load(); + loginController = loadLogin.getController(); + loginController.setGraphicUserInterface(this); + loadLogin.setController(loginController); + stage.setTitle("Bank - Login"); + stage.setScene(new Scene(root)); stage.show(); } } diff --git a/src/main/java/fr/unantes/software/construction/ui/HomeController.java b/src/main/java/fr/unantes/software/construction/ui/HomeController.java new file mode 100644 index 00000000..5bbde906 --- /dev/null +++ b/src/main/java/fr/unantes/software/construction/ui/HomeController.java @@ -0,0 +1,4 @@ +package fr.unantes.software.construction.ui; + +public class HomeController { +} diff --git a/src/main/java/fr/unantes/software/construction/ui/LoginController.java b/src/main/java/fr/unantes/software/construction/ui/LoginController.java new file mode 100644 index 00000000..f1b34d18 --- /dev/null +++ b/src/main/java/fr/unantes/software/construction/ui/LoginController.java @@ -0,0 +1,71 @@ +package fr.unantes.software.construction.ui; + +import fr.unantes.software.construction.Client; +import fr.unantes.software.construction.security.ClientController; +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.fxml.Initializable; +import javafx.scene.Parent; +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.control.PasswordField; +import javafx.scene.control.TextField; +import javafx.scene.layout.Pane; + +import java.io.IOException; +import java.net.URL; +import java.util.ResourceBundle; + +public class LoginController implements Initializable { + + @FXML + public Button buttonLogin; + @FXML + public Label errorText; + @FXML + public Pane loginPane; + @FXML + public TextField fieldUsername; + @FXML + public PasswordField fieldPassword; + + private GraphicalUserInterface graphicUserInterface; + public ClientController clientController; + + @Override + public void initialize(URL url, ResourceBundle resourceBundle) { + buttonLogin.setOnAction((ActionEvent event) -> connecting()); + } + + private void connecting() { + if (validUser()) { + switchTo("/loginView.fxml"); + } else { + errorText.setVisible(true); + } + } + + private void switchTo(String value) { + try { + Parent root = FXMLLoader.load(getClass().getResource(value)); + loginPane.getScene().setRoot(root); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private boolean validUser() { + return clientController.validatePassword((Client) clientController.getNamesToUsers().get(fieldUsername.getCharacters().toString()),fieldPassword.getCharacters().toString()); + } + + /** + * associate a GUI to LoginController + * + * @param newValue + */ + public void setGraphicUserInterface(GraphicalUserInterface newValue){ + graphicUserInterface = newValue; + } + +} diff --git a/src/main/resources/homeView.fxml b/src/main/resources/homeView.fxml new file mode 100644 index 00000000..fb4ec87c --- /dev/null +++ b/src/main/resources/homeView.fxml @@ -0,0 +1,14 @@ + + + + + + + + + + + diff --git a/src/main/resources/loginView.fxml b/src/main/resources/loginView.fxml new file mode 100644 index 00000000..2f937579 --- /dev/null +++ b/src/main/resources/loginView.fxml @@ -0,0 +1,18 @@ + + + + + + + + + + + +