123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
-
- import static org.junit.Assert.*;
- import org.junit.After;
- import org.junit.Before;
- import org.junit.Test;
-
- /**
- * The test class PhoneBookTest.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- public class PhoneBookTest
- {
- @Test
- public void testAdd(){
- //given
- PhoneBook phoneBook = new PhoneBook();
-
- //actual
- phoneBook.add("eric", "3025884804");
- String actual = phoneBook.lookup("eric");
-
- //expected
- String expected = "3025884804";
-
- //test
- assertEquals(expected, actual);
- }
-
- @Test
- public void testAddMultiple(){
- //given
- PhoneBook phoneBook = new PhoneBook();
-
- //actual
- phoneBook.add("eric", "3025884804");
- phoneBook.add("john", "3025844804");
- phoneBook.add("jane", "3025884704");
- String actual = phoneBook.lookup("eric");
- String actual1 = phoneBook.lookup("john");
- String actual2 = phoneBook.lookup("jane");
-
- //expected
- String expected = "3025884804";
- String expected1 = "3025844804";
- String expected2 = "3025884704";
-
- //test
- assertEquals(expected, actual);
- }
-
- @Test
- public void testRemove(){
- //given
- PhoneBook phoneBook = new PhoneBook();
-
- //actual
- phoneBook.add("eric", "3025884804");
- phoneBook.remove("eric");
- String actual = phoneBook.lookup("eric");
-
- //expected
- String expected = null;
-
- //test
- assertEquals(expected, actual);
- }
-
- @Test
- public void testRemoveMultiple(){
- //given
- PhoneBook phoneBook = new PhoneBook();
-
- //actual
- phoneBook.add("eric", "3025884804");
- phoneBook.add("john", "3025844804");
- phoneBook.add("jane", "3025884704");
- phoneBook.remove("john");
- phoneBook.remove("eric");
- String actual = phoneBook.lookup("john");
- String actual1 = phoneBook.lookup("eric");
- String actual2 = phoneBook.lookup("jane");
-
- //expected
- String expected = null;
- String expected1 = null;
- String expected2 = "3025884704";
-
- //test
- assertEquals(expected, actual);
- assertEquals(expected1, actual1);
- assertEquals(expected2, actual2);
- }
-
- @Test
- public void testReverseLookup(){
- //given
- PhoneBook phoneBook = new PhoneBook();
-
- //actual
- phoneBook.add("eric", "3025884804");
- phoneBook.add("john", "3025844804");
- phoneBook.add("jane", "3025884704");
- String actual = phoneBook.reverseLookup("3025884804");
- String actual1 = phoneBook.reverseLookup("3025844804");
- String actual2 = phoneBook.reverseLookup("3025884704");
- String actual3 = phoneBook.reverseLookup("4025884704");
-
- //expected
- String expected = "eric";
- String expected1 = "john";
- String expected2 = "jane";
- String expected3 = null;
-
- //test
- assertEquals(expected, actual);
- assertEquals(expected1, actual1);
- assertEquals(expected2, actual2);
- }
- }
|