import java.io.*;

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

class TestAddressBookWrite
{
  
//--------------------------------
//    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. 
     * Creates a dummy address book of size N.
     */
    public TestAddressBookWrite( int N )
    {
        myBook = new AddressBook(N);
  
        for (int i = 0; i < N; i++) {
           Person person = new Person("Ms. X" + i, 10, 'F');
           myBook.add(person);
        }
    }

//-------------------------------------------------
//      Public Methods:
// 
//          void    testWrite   (   String     )
//
//-------------------------------------------------
    
    /**
     * Writes the address book to the specified file.
     *
     * @param filename the name of a file to store AddressBook
     *
     */
    public void testWrite( String filename )
    {
         fileManager = new AddressBookStorage( filename );
  
         try {
            fileManager.write(myBook);
         }
         catch (IOException e) {
            System.out.println("Error: IOException is thrown.");
         }
    }

}