diff --git a/javaFXTest/app/pom.xml b/javaFXTest/app/pom.xml index 45edd5b4909698a2b5a08cacbc80b1e22ff1c142..1a61b549f6c97e483e8acaac05650cdf4a2b9c92 100644 --- a/javaFXTest/app/pom.xml +++ b/javaFXTest/app/pom.xml @@ -20,6 +20,12 @@ <artifactId>javafx-fxml</artifactId> <version>19</version> </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.11</version> + <scope>test</scope> + </dependency> </dependencies> <build> <plugins> @@ -32,19 +38,19 @@ </configuration> </plugin> <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>exec-maven-plugin</artifactId> - <version>3.1.0</version> - <executions> - <execution> - <goals> - <goal>java</goal> - </goals> - </execution> - </executions> - <configuration> - <mainClass>ch.App</mainClass> - </configuration> + <groupId>org.codehaus.mojo</groupId> + <artifactId>exec-maven-plugin</artifactId> + <version>3.1.0</version> + <executions> + <execution> + <goals> + <goal>java</goal> + </goals> + </execution> + </executions> + <configuration> + <mainClass>ch.App</mainClass> + </configuration> </plugin> <plugin> <groupId>org.openjfx</groupId> @@ -61,6 +67,14 @@ </execution> </executions> </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <version>2.19.1</version> + <configuration> + <mainClass></mainClass> + </configuration> + </plugin> </plugins> </build> </project> diff --git a/javaFXTest/app/src/main/java/ch/app/Amis.java b/javaFXTest/app/src/main/java/ch/app/Amis.java index 7a80d6a5a6b8fe1cb8acc87838546bcf065afbe7..cd2ce61c79db6514143e7fbec4ae67cf0ddd9413 100644 --- a/javaFXTest/app/src/main/java/ch/app/Amis.java +++ b/javaFXTest/app/src/main/java/ch/app/Amis.java @@ -23,10 +23,15 @@ public class Amis extends Contact{ super(nom,arr_prenoms,adr,arr_nums,arr_mails,arr_comptes_res,prof); nomGroupeAmis = "<aucun>"; } + public Amis(String nom, List<String> arr_prenoms, String adr, + List<String> arr_nums, List<String> arr_mails, List<String> arr_comptes_res, String prof,String nomGroupeAmis) { + super(nom,arr_prenoms,adr,arr_nums,arr_mails,arr_comptes_res,prof); + this.nomGroupeAmis = nomGroupeAmis; + } /** * Print Amis contact */ - protected void PrintC(){ + public void PrintC(){ System.out.printf("Nom : %s\n",nom); @@ -67,5 +72,14 @@ public class Amis extends Contact{ } return l; } - + @Override + public boolean equals(Object obj) { + if(obj instanceof Amis){ + + boolean result = super.equals(obj); + result = this.nomGroupeAmis.equals(((Amis)obj).nomGroupeAmis )? result:false; + return result; + }else + return false; + } } diff --git a/javaFXTest/app/src/main/java/ch/app/Contact.java b/javaFXTest/app/src/main/java/ch/app/Contact.java index 00878a53cc5846e180fd1fe9de65e032d19c0b9d..7497e61adf5c9e4c08f1148b05ce8de89389a71b 100644 --- a/javaFXTest/app/src/main/java/ch/app/Contact.java +++ b/javaFXTest/app/src/main/java/ch/app/Contact.java @@ -359,4 +359,17 @@ public abstract class Contact implements Serializable { this.comptes_res_count = new_res_comptes.size(); } } + @Override + public boolean equals(Object obj) { + boolean result = true; + Contact cObj = (Contact)obj; + result = this.adresse.equals(cObj.adresse) ? result:false; + result = this.comptes_res.equals(cObj.comptes_res) ? result:false; + result = this.mails.equals(cObj.mails) ? result:false; + result = this.nom.equals(cObj.nom) ? result:false; + result = this.numeros.equals(cObj.numeros)? result:false; + result = this.prenoms.equals(cObj.prenoms) ? result:false; + result = this.profession.equals(cObj.profession) ? result:false; + return result; + } } \ No newline at end of file diff --git a/javaFXTest/app/src/main/java/ch/app/Famille.java b/javaFXTest/app/src/main/java/ch/app/Famille.java index bd585115366e081b4cdd878234f2a1e1da45466a..a278f9f800e627c78d9bd217b204081ad5b82b5b 100644 --- a/javaFXTest/app/src/main/java/ch/app/Famille.java +++ b/javaFXTest/app/src/main/java/ch/app/Famille.java @@ -19,7 +19,7 @@ public class Famille extends Contact{ /** * Print Famille contact */ - protected void PrintC(){ + public void PrintC(){ System.out.printf("Nom : %s\n",nom); @@ -69,4 +69,14 @@ public class Famille extends Contact{ } return l; } + @Override + public boolean equals(Object obj) { + if(obj instanceof Famille){ + boolean result = super.equals(obj); + result = this.nbAnimaux == ((Famille)obj).nbAnimaux ? result:false; + return result; + } + else + return false; + } } diff --git a/javaFXTest/app/src/main/java/ch/app/Pro.java b/javaFXTest/app/src/main/java/ch/app/Pro.java index 402bc3920cbba8e7a691654f8cb1e83b86b7eab4..f64fe9657ebb51e4664a2ef9c2ec07f2f57cad9b 100644 --- a/javaFXTest/app/src/main/java/ch/app/Pro.java +++ b/javaFXTest/app/src/main/java/ch/app/Pro.java @@ -22,10 +22,16 @@ public class Pro extends Contact{ super(nom,arr_prenoms,adr,arr_nums,arr_mails,arr_comptes_res,prof); nomCompagnie = "<aucun>"; } + + public Pro(String nom, List<String> arr_prenoms, String adr, + List<String> arr_nums, List<String> arr_mails, List<String> arr_comptes_res, String prof,String nomCompagnie) { + super(nom,arr_prenoms,adr,arr_nums,arr_mails,arr_comptes_res,prof); + this.nomCompagnie = nomCompagnie; + } /** * Print Pro contact */ - protected void PrintC(){ + public void PrintC(){ System.out.printf("Nom : %s\n",nom); @@ -65,7 +71,16 @@ public class Pro extends Contact{ if(contact_lst.get(i) instanceof Pro) l.add(GetContact(i)); } - System.out.println(l.get(0)); return l; } + @Override + public boolean equals(Object obj) { + if(obj instanceof Pro){ + + boolean result = super.equals((Contact)obj); + result = this.nomCompagnie.equals(((Pro)obj).nomCompagnie )? result:false; + return result; + }else + return false; + } } diff --git a/javaFXTest/app/src/main/java/ch/app/contactMenuController.java b/javaFXTest/app/src/main/java/ch/app/contactMenuController.java index cb4bd5e8de17680415c72ee3bd7f053a4bfdad1e..c24b2633be4103afb75ebc14a99505e71058ebe1 100644 --- a/javaFXTest/app/src/main/java/ch/app/contactMenuController.java +++ b/javaFXTest/app/src/main/java/ch/app/contactMenuController.java @@ -138,7 +138,6 @@ public class contactMenuController { @FXML void addContact(ActionEvent event) throws IOException{ - System.out.println("aaaa"); App.status = App.State.ADDCONTACT; App.setRoot("contactShow"); } @@ -156,6 +155,7 @@ public class contactMenuController { @FXML void selectMenuType(ActionEvent event) { btnSearch.setDisable(false); + searchField.clear(); switch (this.searchTypeCbx.getValue()) { case "Tous": this.search = searchStat.TOUS; diff --git a/javaFXTest/app/src/main/java/ch/app/contactShowController.java b/javaFXTest/app/src/main/java/ch/app/contactShowController.java index 65573be382dec4dfa9e4171562102900c102462b..7d9285d4193ae2b77e1769668c80f26c34f9df43 100644 --- a/javaFXTest/app/src/main/java/ch/app/contactShowController.java +++ b/javaFXTest/app/src/main/java/ch/app/contactShowController.java @@ -242,16 +242,14 @@ public class contactShowController { Contact c = null; switch(chosenClass){ case AMIS: - c = new Amis(nom, prenoms, adresse, numeros, mails, compteRes, profession); - ((Amis)c).setNomGroupeAmis(tbxAutre.getText()); + c = new Amis(nom, prenoms, adresse, numeros, mails, compteRes, profession,tbxAutre.getText()); break; case PRO: - c = new Pro(nom, prenoms, adresse, numeros, mails, compteRes, profession); + c = new Pro(nom, prenoms, adresse, numeros, mails, compteRes, profession,tbxAutre.getText()); ((Pro)c).setNomCompagnie(tbxAutre.getText()); break; case FAMILLE: - c = new Famille(nom, prenoms, adresse, numeros, mails, compteRes, profession); - ((Famille)c).setNbAnimaux(Integer.parseInt(tbxAutre.getText())); + c = new Famille(nom, prenoms, adresse, numeros, mails, compteRes, profession,Integer.parseInt(tbxAutre.getText())); break; } Contact.AddContact(c); diff --git a/javaFXTest/app/src/main/java/module-info.java b/javaFXTest/app/src/main/java/module-info.java deleted file mode 100644 index fe2e95541d6c0a9f48109dff054db754acd9dddd..0000000000000000000000000000000000000000 --- a/javaFXTest/app/src/main/java/module-info.java +++ /dev/null @@ -1,7 +0,0 @@ -module ch.app { - requires javafx.controls; - requires javafx.fxml; - - opens ch.app to javafx.fxml; - exports ch.app; -} diff --git a/javaFXTest/app/src/test/java/TestContacts.java b/javaFXTest/app/src/test/java/TestContacts.java new file mode 100644 index 0000000000000000000000000000000000000000..e143ae9d469fd4fac2e4bd19f326f8ce5de1f670 --- /dev/null +++ b/javaFXTest/app/src/test/java/TestContacts.java @@ -0,0 +1,90 @@ +import java.util.List; + +import org.junit.Test; + +import static org.junit.Assert.assertSame; + +import java.io.*; +import java.util.ArrayList; +import ch.app.*; +import ch.app.Contact.Cont_Obj; +public class TestContacts { + @Test + public void addContactTest(){ + Contact.contact_lst_count = 0; + Contact.contact_lst = new ArrayList<Contact>(); + //Contact.PrintAllContacts(); + + Contact newC0 = new Famille("Test", List.of("T","E","S","T"), "testing ground", List.of("999191991"), List.of("test@testers.com"), List.of("@testers"), "Pro Tester", 1); + Contact.AddContact(newC0); + Contact sameC = Contact.contact_lst.get(0); + assertSame(newC0, sameC); + System.out.println("Ajout Contact Réussi"); + } + + @Test + public void getContactTest(){ + Contact.contact_lst_count = 0; + Contact.contact_lst = new ArrayList<Contact>(); + Cont_Obj c = Contact.GetContact(19); + //Test invalid contact get + assert(c.getContactObj() == null && c.getIndexObj() == -1); + System.out.println("Test contact invalide réussi"); + Contact newC = new Famille("Test", List.of("T","E","S","T"), "testing ground", List.of("999191991"), List.of("test@testers.com"), List.of("@testers"), "Pro Tester", 1); + Contact newC2 = new Pro("Test2", List.of("T","E","S","T2"), "testing ground", List.of("999191991"), List.of("test@testers.com"), List.of("@testers"), "Pro Tester","TestCorp"); + Contact.AddContact(newC); + Contact.AddContact(newC2); + c = Contact.GetContact(1); + //c.printContact(); + //((Pro)newC2).PrintC(); + //boolean result = true; + Contact cObj =((Cont_Obj)c).getContactObj(); + //result = ((Pro)newC2).getAdresse().equals(cObj.getAdresse()) ? result:false; + //result = ((Pro)newC2).getComptesRes().equals(cObj.getComptesRes()) ? result:false; + //result = ((Pro)newC2).getMails().equals(cObj.getMails()) ? result:false; + //result = ((Pro)newC2).getNom().equals(cObj.getNom()) ? result:false; + //result = ((Pro)newC2).getNumeros().equals(cObj.getNumeros())? result:false; + //result = ((Pro)newC2).getPrenoms().equals(cObj.getPrenoms()) ? result:false; + //result = ((Pro)newC2).getProfession().equals(cObj.getProfession()) ? result:false; + //Test get Contact + assert(newC2.equals(cObj)); + System.out.println("Test contact get par ID réussi"); + + List<Cont_Obj> cL = Contact.GetContactsByName("Test"); + boolean res = false; + if(cL.size()>0){ + res = newC.equals(cL.get(0).getContactObj()); + } + assert(res); + System.out.println("Test contact get par Nom réussi"); + + } + + @Test + public void deleteContactTest(){ + Contact.contact_lst_count = 0; + Contact.contact_lst = new ArrayList<Contact>(); + Contact newC = new Famille("Test", List.of("T","E","S","T"), "testing ground", List.of("999191991"), List.of("test@testers.com"), List.of("@testers"), "Pro Tester", 1); + Contact newC2 = new Pro("Test2", List.of("T","E","S","T2"), "testing ground", List.of("999191991"), List.of("test@testers.com"), List.of("@testers"), "Pro Tester","TestingCorps"); + Contact newC3 = new Pro("Test3", List.of("T","E","S","T3"), "testing ground", List.of("999191991"), List.of("test@testers.com"), List.of("@testers"), "Pro Tester","TesteEstttt"); + + Contact.AddContact(newC); + Contact.AddContact(newC2); + Contact.AddContact(newC3); + + Contact.RemoveContact(1); + boolean result = false; + if(Contact.GetContactsByName("Test2").size()<= 0){ + result = true; + } + assert(result); + System.out.println("Test supression contact réussi"); + + } + + @Test + public void modifyContactTest(){ + Contact newC = new Amis("Test", List.of("T","E","S","T"), "testing ground", List.of("999191991"), List.of("test@testers.com"), List.of("@testers"), "Pro Tester", "The Testbros"); + + } +}