From a31033dac7fcad2917d57fa06f28d05f550fe58e Mon Sep 17 00:00:00 2001 From: "zabiulla.ahmadi" <zabiullah.ahmadi@etu.hesge.ch> Date: Sun, 8 Jan 2023 14:03:07 +0100 Subject: [PATCH] test search implement --- src/Family/Family.java | 13 ++-- src/Friends/Friends.java | 11 ++- src/Professional/Professional.java | 11 ++- .../ContactException/ContactException.java | 4 ++ src/test/java/MainTest.java | 68 ++++++++++++------- 5 files changed, 72 insertions(+), 35 deletions(-) create mode 100644 src/main/java/ContactException/ContactException.java diff --git a/src/Family/Family.java b/src/Family/Family.java index 6a3427b..1bd19ef 100644 --- a/src/Family/Family.java +++ b/src/Family/Family.java @@ -79,7 +79,8 @@ public class Family extends Contacts { return this; } - public void updateContact(){ + + public void updateContact() { clearConsoleScreen(); PrintInColor(" ==================================================================================\n", GREEN); PrintInColor(String.format("%s\n", "UPDATE CONTACT [Family]"), BLUE); @@ -98,14 +99,14 @@ public class Family extends Contacts { System.out.format("%s %s %s : [] ", BLUE, "YOUR OPTION ", BLUE); Scanner sc = new Scanner(System.in); int option = sc.nextInt(); - while(option < 1 || option > 8){ + while (option < 1 || option > 8) { System.out.format("%s %s %s\n", RED, "ERREUR: PLEASE CHOOSE THE CORRECT OPTION", RED); System.out.format("%s", RESET); System.out.format("%s %s %s : [] ", BLUE, "YOUR OPTION ", BLUE); option = sc.nextInt(); } - switch (option){ + switch (option) { case 1: askName(); break; @@ -133,7 +134,6 @@ public class Family extends Contacts { } } - @Override public void showContact() { @@ -187,4 +187,9 @@ public class Family extends Contacts { } + @Override + public String toString() { + return this.getName(); + } + } diff --git a/src/Friends/Friends.java b/src/Friends/Friends.java index e8c0146..8472a02 100644 --- a/src/Friends/Friends.java +++ b/src/Friends/Friends.java @@ -83,7 +83,7 @@ public class Friends extends Contacts { } - public void updateContact(){ + public void updateContact() { clearConsoleScreen(); PrintInColor(" ==================================================================================\n", GREEN); PrintInColor(String.format("%s\n", "UPDATE CONTACT [FRIENDS]"), BLUE); @@ -102,14 +102,14 @@ public class Friends extends Contacts { System.out.format("%s %s %s : [] ", BLUE, "YOUR OPTION ", BLUE); Scanner sc = new Scanner(System.in); int option = sc.nextInt(); - while(option < 1 || option > 8){ + while (option < 1 || option > 8) { System.out.format("%s %s %s\n", RED, "ERREUR: PLEASE CHOOSE THE CORRECT OPTION", RED); System.out.format("%s", RESET); System.out.format("%s %s %s : [] ", BLUE, "YOUR OPTION ", BLUE); option = sc.nextInt(); } - switch (option){ + switch (option) { case 1: askName(); break; @@ -189,4 +189,9 @@ public class Friends extends Contacts { "----------------------------------------------------------------------------------\n"); } + + @Override + public String toString() { + return this.getName(); + } } diff --git a/src/Professional/Professional.java b/src/Professional/Professional.java index 7374f14..dd9d6da 100644 --- a/src/Professional/Professional.java +++ b/src/Professional/Professional.java @@ -82,7 +82,7 @@ public class Professional extends Contacts { } - public void updateContact(){ + public void updateContact() { clearConsoleScreen(); PrintInColor(" ==================================================================================\n", GREEN); PrintInColor(String.format("%s\n", "UPDATE CONTACT [PROFESSIONAL]"), BLUE); @@ -101,14 +101,14 @@ public class Professional extends Contacts { System.out.format("%s %s %s : [] ", BLUE, "YOUR OPTION ", BLUE); Scanner sc = new Scanner(System.in); int option = sc.nextInt(); - while(option < 1 || option > 8){ + while (option < 1 || option > 8) { System.out.format("%s %s %s\n", RED, "ERREUR: PLEASE CHOOSE THE CORRECT OPTION", RED); System.out.format("%s", RESET); System.out.format("%s %s %s : [] ", BLUE, "YOUR OPTION ", BLUE); option = sc.nextInt(); } - switch (option){ + switch (option) { case 1: askName(); break; @@ -188,4 +188,9 @@ public class Professional extends Contacts { "----------------------------------------------------------------------------------\n"); } + + @Override + public String toString() { + return this.getName(); + } } diff --git a/src/main/java/ContactException/ContactException.java b/src/main/java/ContactException/ContactException.java new file mode 100644 index 0000000..9b6ebaf --- /dev/null +++ b/src/main/java/ContactException/ContactException.java @@ -0,0 +1,4 @@ +package ContactException; + +public class ContactException { +} diff --git a/src/test/java/MainTest.java b/src/test/java/MainTest.java index 4e759d6..1b3f79c 100644 --- a/src/test/java/MainTest.java +++ b/src/test/java/MainTest.java @@ -1,6 +1,5 @@ import static org.junit.Assert.assertEquals; - import java.util.List; import org.junit.Test; @@ -11,17 +10,21 @@ import Friends.Friends; public class MainTest { + Application app; + + public MainTest() { + app = new Application(); + } + @Test public void insertContactTest() { - Application app = new Application(); - - String name = "agnon"; - List<String> lastName = List.of("kurteshi", "burteshi"); + String name = "alex"; + List<String> lastName = List.of("kurteshi", "browman"); String address = "rue du rhone 4, 1203 Genève"; List<String> telephoneNumber = List.of("+41 77 444 33 22"); - List<String> email = List.of("agnon@gmail.com"); - List<String> socialAcount = List.of("https://hello.com/?name=agnon"); + List<String> email = List.of("alex@gmail.com"); + List<String> socialAcount = List.of("https://hello.com/?name=alex"); String profession = "student"; String friendSince = "2022/02/02"; @@ -33,21 +36,17 @@ public class MainTest { assertEquals(app.getContactList().size(), 1); assertEquals(app.getContactList().get(0).getName(), name); assertEquals(app.getContactList().get(0).getType(), contact.getType()); - System.out.println("INSERTION TEST PASSED"); - } @Test public void DeleteContactTest() { - Application app = new Application(); - - String name = "agnon"; - List<String> lastName = List.of("kurteshi", "burteshi"); + String name = "alex"; + List<String> lastName = List.of("kurteshi", "browman"); String address = "rue du rhone 4, 1203 Genève"; List<String> telephoneNumber = List.of("+41 77 444 33 22"); - List<String> email = List.of("agnon@gmail.com"); - List<String> socialAcount = List.of("https://hello.com/?name=agnon"); + List<String> email = List.of("alex@gmail.com"); + List<String> socialAcount = List.of("https://hello.com/?name=alex"); String profession = "student"; String friendSince = "2022/02/02"; @@ -60,22 +59,17 @@ public class MainTest { // after delete size should be 0 assertEquals(app.getContactList().size(), 0); - - System.out.println("DELETION TEST PASSED"); - } @Test public void sort() { - Application app = new Application(); - - String name = "agnon"; - List<String> lastName = List.of("kurteshi", "burteshi"); + String name = "alex"; + List<String> lastName = List.of("kurteshi", "browman"); String address = "rue du rhone 4, 1203 Genève"; List<String> telephoneNumber = List.of("+41 77 444 33 22"); - List<String> email = List.of("agnon@gmail.com"); - List<String> socialAcount = List.of("https://hello.com/?name=agnon"); + List<String> email = List.of("alex@gmail.com"); + List<String> socialAcount = List.of("https://hello.com/?name=alex"); String profession = "student"; String friendSince = "2022/02/02"; @@ -93,7 +87,31 @@ public class MainTest { // if sort is correct then "AAAAAA" should be at index 0 assertEquals(app.getContactList().get(0).getName(), name2); - System.out.println("SORT TEST PASSED"); + + } + + @Test + public void search() { + + String name = "nonexisting"; + List<String> lastName = List.of("kurteshi", "browman"); + String address = "rue du rhone 4, 1203 Genève"; + List<String> telephoneNumber = List.of("+41 77 444 33 22"); + List<String> email = List.of("alex@gmail.com"); + List<String> socialAcount = List.of("https://hello.com/?name=alex"); + String profession = "student"; + String friendSince = "2022/02/02"; + + Contacts contact = new Friends(name, lastName, address, email, telephoneNumber, socialAcount, profession, + friendSince); + + boolean findAlex = app.getContactList().stream().anyMatch(e -> e.getName().equals(name)); + + app.addToContactList(contact); + + boolean findagian = app.getContactList().stream().anyMatch(e -> e.getName().equals(name)); + + assertEquals(!findAlex, findagian); } } -- GitLab