// ReadNotesTest.java  P. Conrad, for CISC370, 06/18/2007
// Compare Recipe 4.1 from Java Extreme Programming Cookbook, p. 60

import junit.framework.TestCase;

import java.util.ArrayList;


/**
 * Unit tests for the {@link ReadNotes} class.
 * @author Phill Conrad
 */


public class ReadNotesTest extends TestCase {

    /**
     * A unit test to see if the last method for an ArrayList<Chapter>
     * works properly.
     */

    public void testLastOnChapter() {
	Section s1 = new Section("Section 1.1",
				 "My First Section", 
				 "2",
				 "hfjava2-CHP-1-SECT-1");

	Section s2 = new Section("Section 1.2",
				 "The Next Section", 
				 "6",
				 "hfjava2-CHP-1-SECT-2");

	Chapter c = new Chapter("Chapter 1","My First Chapter");	
	c.add(s1);

	Section lastSection = ReadNotes.last(c);
	assertEquals("Section 1.1",lastSection.getName());

	c.add(s2);

	lastSection = ReadNotes.last(c); // static method, so specify class
	assertEquals("Section 1.2",lastSection.getName());


    }

    public void testLastOnArrayListOfChapters() {

	ArrayList<Chapter> al = new ArrayList<Chapter>();

	Chapter c1 = new Chapter("Chapter 1","My First Chapter");	
	Chapter c2 = new Chapter("Chapter 2","The Next Chapter");	

	al.add(c1);

	Chapter lastChapter = ReadNotes.last(al);
	assertEquals("Chapter 1",lastChapter.getName());

	al.add(c2);

	lastChapter = ReadNotes.last(al);
	assertEquals("Chapter 2",lastChapter.getName());


    }


} // class
