@Test public void testGetAddressBookFromPath() throws IOException { URL path = this.getClass().getResource("/AddressBook"); AddressBook addressBook = AddressBookFactory.getAddressBookFromPath(path.getPath()); assertEquals("We expect 5 persons in address book", 5, addressBook.size()); }
@Test public void testMapToPersonListwithEmptyList() { List<String> data = new ArrayList<>(); List<Person> result = AddressBookFactory.mapToPersonList(data); assertTrue("List should be empty", result.isEmpty()); }
@Test public void testMapToPersonList() { Person a = new Person("A", Gender.FEMALE, formatter.parseDateTime("01/01/80")); Person b = new Person("B", Gender.MALE, formatter.parseDateTime("01/03/30")); List<String> data = new ArrayList<>(); data.add(" A , Female , 01/01/80"); data.add(" B , Male, 01/03/30"); List<Person> result = AddressBookFactory.mapToPersonList(data); assertEquals("We expect 2 persons in list", 2, result.size()); assertEquals("We expect first person to be A", a, result.get(0)); assertEquals("We expect second person to be B", b, result.get(1)); }
@Test(expected = IOException.class) public void testLoadFileContentwithMissingFile() throws IOException { File file = new File("ThisWillNotExist.ForSure"); AddressBookFactory.loadFileContent(file); }
@Test public void testLoadFileContentwithNull() throws IOException { List<String> result = AddressBookFactory.loadFileContent(null); assertTrue("List should be empty", result.isEmpty()); }
@Test public void testMapToPersonListwithNullList() { List<Person> result = AddressBookFactory.mapToPersonList(null); assertTrue("List should be empty", result.isEmpty()); }