Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test units added and improved #2

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
ddfe745
Person Constructor Method Test Added
MaryamHamidi2004 Dec 18, 2023
0f77505
Person Constructor Method Test Added
MaryamHamidi2004 Dec 18, 2023
93f8989
Person GetName Meethod Test Added
MaryamHamidi2004 Dec 18, 2023
fbd6829
Person GetPhone Method Test Added
MaryamHamidi2004 Dec 18, 2023
d50da6e
Person GetID Method Test Added
MaryamHamidi2004 Dec 18, 2023
f295a90
Person IsHidden Method Test Added
MaryamHamidi2004 Dec 18, 2023
3311b6d
Person SetName Method Test Added
MaryamHamidi2004 Dec 18, 2023
db85a61
Person SetPhone Method Test Added
MaryamHamidi2004 Dec 18, 2023
b885429
Person SetHidden Method Test Added
MaryamHamidi2004 Dec 18, 2023
335d778
Person SetUnHidden Method Test Added
MaryamHamidi2004 Dec 18, 2023
2390e36
Person ToString Method Test Added
MaryamHamidi2004 Dec 18, 2023
335dfd1
PhoneBook AddContact Method Test Added
MaryamHamidi2004 Dec 18, 2023
1bf82b7
PhoneBook GetPhoneNumber Method Test Added
MaryamHamidi2004 Dec 20, 2023
5d96d02
PhoneBook GetContact Method Test Added
MaryamHamidi2004 Dec 20, 2023
a273350
PhoneBook UpdateContactName Method Test Added
MaryamHamidi2004 Dec 20, 2023
9333a44
PhoneBook UpdateContactPhoneNumber Method Test
MaryamHamidi2004 Dec 20, 2023
981a1f3
PhoneBook DeleteContact Method Test Added
MaryamHamidi2004 Dec 20, 2023
61ac5f6
PhoneBook GetAllContacts Method Test Added
MaryamHamidi2004 Dec 20, 2023
b875c79
PhoneBook SetAllContactsHidden Method Test Added
MaryamHamidi2004 Dec 20, 2023
603565c
PhoneBook SetAllContactsUnHidden Method Test Added
MaryamHamidi2004 Dec 20, 2023
1bdeae9
Person GetId Method Test Error Solved
MaryamHamidi2004 Dec 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,23 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.8.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
140 changes: 140 additions & 0 deletions src/test/java/Phonebook_Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,146 @@
* Hint: Your test coverage should be 100%
* Attention: We would check your commits and it will affect your score
*/
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class Phonebook_Test {
@Test
public void testConstructor() {
Person person = new Person("John Doe", "09123456789");
assertEquals("John Doe", person.getName());
assertEquals("09123456789", person.getPhone());
assertFalse(person.isHidden());
}

@Test
public void testGetName() {
Person person = new Person("John Doe", "09123456789");
assertEquals("John Doe", person.getName());
}

@Test
public void testGetPhone() {
Person person = new Person("John Doe", "09123456789");
assertEquals("09123456789", person.getPhone());
}

@Test
public void testGetId() {
Person person = new Person("John Doe", "09123456789");
assertEquals(3, person.getId());
}
@Test
public void testIsHidden() {
Person person = new Person("John Doe", "09123456789");
assertFalse(person.isHidden());
}

@Test
public void testSetName() {
Person person = new Person("John Doe", "09123456789");
person.setName("Jane Doe");
assertEquals("Jane Doe", person.getName());
}

@Test
public void testSetPhone() {
Person person = new Person("John Doe", "09123456789");
person.setPhone("09234567891");
assertEquals("09234567891", person.getPhone());

}
@Test
public void testSetHidden() {
Person person = new Person("John Doe", "09123456789");
person.setHidden();
assertTrue(person.isHidden());
}
@Test
public void testSetUnHidden() {
Person person = new Person("John Doe", "09123456789");
person.setHidden();
person.setUnHidden();
assertFalse(person.isHidden());
}
@Test
public void testToString() {
Person person = new Person("John Doe", "09123456789");
assertEquals("Name: John Doe - Phone number: 09123456789", person.toString());
}
@Test
public void testAddContact() {
Phonebook phonebook = new Phonebook();
Person person = new Person("John Doe", "09123456789");
phonebook.addContact(person);
assertTrue(phonebook.getAllContacts().contains(person));
}
@Test
public void testGetPhoneNumber() {
Phonebook phonebook = new Phonebook();
Person person = new Person("John Doe", "09123456789");
phonebook.addContact(person);
assertEquals("09123456789", phonebook.getPhoneNumber("John Doe"));
}
@Test
public void testGetContact() {
Phonebook phonebook = new Phonebook();
Person person = new Person("John Doe", "09123456789");
phonebook.addContact(person);
assertEquals(1, phonebook.getContact("John Doe"));
}
@Test
public void testUpdateContactName() {
Phonebook phonebook = new Phonebook();
Person person = new Person("John Doe", "09123456789");
phonebook.addContact(person);
assertEquals(1, phonebook.updateContactName("John Doe", "Jane Doe"));
assertEquals("Jane Doe", phonebook.getAllContacts().get(0).getName());
}
@Test
public void testUpdateContactPhoneNumber() {
Phonebook phonebook = new Phonebook();
Person person = new Person("John Doe", "09123456789");
phonebook.addContact(person);
assertEquals(1, phonebook.updateContactPhoneNumber("John Doe", "09234567890"));
assertEquals("09234567890", phonebook.getAllContacts().get(0).getPhone());
}
@Test
public void testDeleteContact() {
Phonebook phonebook = new Phonebook();
Person person = new Person("John Doe", "09123456789");
phonebook.addContact(person);
assertEquals(1, phonebook.deleteContact("John Doe"));
assertFalse(phonebook.getAllContacts().contains(person));
}
@Test
public void testGetAllContacts() {
Phonebook phonebook = new Phonebook();
Person person1 = new Person("John Doe", "09123456789");
Person person2 = new Person("Jane Smith", "09234567890");
phonebook.addContact(person1);
phonebook.addContact(person2);
assertEquals(2, phonebook.getAllContacts().size());
}
@Test
public void testSetAllContactsHidden() {
Phonebook phonebook = new Phonebook();
Person person1 = new Person("John Doe", "09123456789");
Person person2 = new Person("Jane Smith", "09234567890");
phonebook.addContact(person1);
phonebook.addContact(person2);
phonebook.setAllContactsHidden();
assertTrue(person1.isHidden() && person2.isHidden());
}
@Test
public void testSetAllContactsUnHidden() {
Phonebook phonebook = new Phonebook();
Person person1 = new Person("John Doe", "09123456789");
Person person2 = new Person("Jane Smith", "09234567890");
phonebook.addContact(person1);
phonebook.addContact(person2);
phonebook.setAllContactsHidden();
phonebook.setAllContactsUnHidden();
assertFalse(person1.isHidden() && person2.isHidden());
}
}

Binary file added target/classes/Person.class
Binary file not shown.
Binary file added target/classes/Phonebook.class
Binary file not shown.
Binary file added target/test-classes/Phonebook_Test.class
Binary file not shown.