Skip to content
Snippets Groups Projects
Commit 72e8e463 authored by fabio.rodrigue1's avatar fabio.rodrigue1
Browse files

Ajout unit test et interface finie, sauf polissage

parent 0717b3fd
No related branches found
No related tags found
No related merge requests found
......@@ -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>
......@@ -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>
......@@ -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;
}
}
......@@ -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
......@@ -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;
}
}
......@@ -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;
}
}
......@@ -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;
......
......@@ -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);
......
module ch.app {
requires javafx.controls;
requires javafx.fxml;
opens ch.app to javafx.fxml;
exports ch.app;
}
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");
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment