import java.io.*;

/**
 * This class is for testing the read operation of AddressBookStorage.
 *
 * @author Dr. Caffeine
 */

class TestAddressBookRead
{
  //--------------------------------
//    Data Members
//--------------------------------
    
    /**
     * An AddressBook object to be stored in a file
     */
    AddressBook         myBook;
   
    /**
     * A storage object that handles file i/o for AddressBook
     */
    AddressBookStorage  fileManager;


//--------------------------------
//    Constructors
//--------------------------------
    
    /**
     * Default constructor. 
     */
    public TestAddressBookRead( )
    {
      
    }
    
//-------------------------------------------------
//      Public Methods:
//
//          void    printout   (              )
//          void    testRead   (   String     )
//
//-------------------------------------------------
  
    /**
     * Prints out the data in the AddressBook loaded
     * from the file.
     *
     */ 
    public void printout()
    {
        Person person;
  
        person = myBook.search("Ms. X5");
  
        if (person != null) {
           System.out.println(person.getName());
           System.out.println(person.getAge());
           System.out.println(person.getGender());
        }
        else {
           System.out.println("Error: object not found");
        }
    }
    
    
    /**
     * Read the address book to the specified file.
     *
     * @param filename the name of a file to load AddressBook
     *
     */
    public void testRead( String filename )
    {
        fileManager = new AddressBookStorage( filename );
       
        try {
           myBook = fileManager.read();
           printout();
        }
        catch (IOException e) {
           System.out.println("Error: IOException is thrown.");
        }
    }



}