123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
-
- import static org.junit.Assert.*;
- import org.junit.After;
- import org.junit.Before;
- import org.junit.Test;
- import java.util.*;
-
- /**
- * The test class PhoneBookTest.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- public class PhoneBookTest
- {
- PhoneBook test = new PhoneBook();
- /**
- * Default constructor for test class PhoneBookTest
- */
- public PhoneBookTest()
- {
- }
-
- /**
- * Sets up the test fixture.
- *
- * Called before every test case method.
- */
- @Before
- public void setUp()
- {
- }
-
- @Test
- public void addTest(){
- //Given
- ArrayList<String> list = new ArrayList<String>();
- list.add("5704282076");
- //When
- int expected = 1;
- TreeMap actual = test.add("Chad", list);
-
- //Result
- assertEquals(expected, actual.size());
- }
-
- @Test
- public void removeRecordTest(){
- //Given
- ArrayList<String> list = new ArrayList<String>();
- list.add("5704282076");
- list.add("5707429337");
- test.add("Chad", list);
- //When
- int expected = 0;
- TreeMap actual = test.removeRecord("Chad");
-
- //Result
- assertEquals(expected, actual.size());
- }
-
- @Test
- public void lookUpTest(){
- //Given
- ArrayList<String> list = new ArrayList<String>();
- list.add("5704282076");
- test.add("Chad", list);
- //When
- ArrayList<String> expected = list;
- ArrayList<String> actual = test.lookUp("Chad");
-
- //Result
- assertEquals(expected, actual);
- }
-
- @Test
- public void invertMapTest(){
- //Given
- ArrayList<String> list = new ArrayList<String>();
- list.add("5704282076");
- test.add("Chad", list);
- test.invertMap();
- //When
- String expected = "Chad";
- String actual = test.reverseLookUp("5704282076");
-
- //Result
- assertEquals(expected, actual);
- }
-
- @Test
- public void displayTest(){
- //Given
- ArrayList<String> list = new ArrayList<String>();
- list.add("5704282076");
- ArrayList<String> list1 = new ArrayList<String>();
- list1.add("111-222-333");
- ArrayList<String> list2 = new ArrayList<String>();
- list2.add("222-444-4444");
- test.add("Chad", list);
- test.add("Zebra", list1);
- test.add("Dog", list2);
-
- //When
- String expected = "Chad 5704282076\nDog 222-444-4444\nZebra 111-222-333\n";
- String actual = test.display();
-
- //Result
- assertEquals(expected, actual);
- }
-
- @Test
- public void arrayContainsTest(){
- //Given
- ArrayList<String> list = new ArrayList<String>();
- list.add("5704282076");
- //When
- boolean actual = test.arrayContains(list,"5704282076");
- //Result
- assertTrue(actual);
- }
-
- @Test
- public void removeTest(){
- //Given
- ArrayList<String> list = new ArrayList<String>();
- list.add("5704282076");
- list.add("5707429337");
- ArrayList<String> list1 = new ArrayList<String>();
- list1.add("111-222-333");
- ArrayList<String> list2 = new ArrayList<String>();
- list2.add("222-444-4444");
- test.add("Chad", list);
- test.add("Zebra", list1);
- test.add("Dog", list2);
-
- test.remove("Chad","5704282076");
- //When
- boolean actual = test.arrayContains(list,"5704282076");
- //Result
- assertFalse(actual);
- }
-
- /**
- * Tears down the test fixture.
- *
- * Called after every test case method.
- */
- @After
- public void tearDown()
- {
- }
- }
|