123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
-
- import org.junit.Assert;
- import org.junit.After;
- import org.junit.Before;
- import org.junit.Test;
- import java.util.Iterator;
- import java.util.Map;
- import java.util.Set;
- import java.util.SortedMap;
- import java.util.TreeMap;
- import java.util.ArrayList;
- /**
- * The test class PhoneBookTest.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- public class PhoneBookTest
- {
- PhoneBook book;
- @Before
- public void setUp()
- {
- this.book = new PhoneBook();
- }
-
- @Test
- public void addTest() {
- //Given
-
- //When
- book.add("Leeks", "194-345-3458");
- String lookup = book.lookup("Leeks");
- //Then
- Assert.assertEquals("194-345-3458", lookup);
- }
-
- @Test
- public void lookupTest() {
- //Given
- book.add("Leeks", "194-345-3458");
- book.add("Leeks", "345-234-4643");
- String phoneNumber = book.lookup("Leeks");
- //Then
- Assert.assertEquals("194-345-3458, 345-234-4643", phoneNumber);
- }
-
- @Test
- public void lookupTest1() {
- //Given
- book.add("Leeks", "194-345-3458");
- book.add("Leeks", "345-234-4643");
- String phoneNumber = book.lookup("Banana");
- //Then
- Assert.assertEquals("This entry doesn't exist. Please enter valid entry.", phoneNumber);
- }
-
- @Test
- public void removeTest() {
- //Given
- book.add("Leeks", "194-345-3458");
- book.add("Leeks", "345-234-4643");
- book.remove("Leeks", "194-345-3458");
- //When
- String phoneNumber = book.lookup("Leeks");
- //Then
- Assert.assertEquals("345-234-4643", phoneNumber);
- }
-
- @Test
- public void removeTest1() {
- //Given
- //When
- book.add("Leeks", "194-345-3458");
- book.add("Leeks", "345-234-4643");
- book.remove("Leeks", "194-345-3458");
- book.remove("Leeks", "345-234-4643");
- //Then
- Assert.assertEquals("This entry doesn't exist. Please enter valid entry.", book.lookup("Leeks"));
- }
-
- @Test
- public void reverseLookupTest() {
- //Given
- book.add("Leeks", "194-345-3458");
- //When
- String name = book.reverseLookup("194-345-3458");
- //Then
- Assert.assertEquals("Leeks", name);
- }
-
- @Test
- public void reverseLookupTest1() {
- //Given
- book.add("Leeks", "194-345-3458");
- book.remove("Leeks", "194-345-3458");
- //When
- String name = book.reverseLookup("194-345-3458");
- //Then
- Assert.assertEquals("This entry doesn't exist. Please enter valid entry.", name);
- }
- }
-
|