package br.com.senacagil.springmvc.model;

import static org.junit.Assert.*;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.junit.BeforeClass;
import org.junit.Test;

public class POJOUnitTest {
	private Customer c1, c2;
	private Address addr1, addr2;

	@BeforeClass
	protected void setUp() throws Exception {
		
		System.out.println("in POJO setup");

		addr1 = new Address(11, "Main Street");
		addr2 = new Address();
		addr2.setNumber(21);

		addr2.setStreet("Main Street");

		c1 = new Customer("Melissa", "Thureau", "083-3904-90384", addr1,
				makeDate("05/08/2007"));

		c2 = new Customer();
		c2.setFirstName("Jean-Pierre");
		c2.setLastName("Pernod");
		c2.setPhoneNumber("089-3943-93839");
		c2.setAddr(addr2);
		c2.setRegdate(makeDate("01/01/2005"));
	}

	@Test
	public void testCustomer() throws java.text.ParseException {
		assertEquals("Melissa", c1.getFirstName());
		assertEquals("Thureau", c1.getLastName());
		assertEquals(11, c1.getAddr().getNumber());
		assertEquals("Main Street", c1.getAddr().getStreet());
		assertEquals(makeDate("05/08/2007"), c1.getRegdate());

		assertEquals("Jean-Pierre", c2.getFirstName());
		assertEquals("Pernod", c2.getLastName());
		assertEquals(21, c2.getAddr().getNumber());
		assertEquals("Main Street", c2.getAddr().getStreet());
		assertEquals(makeDate("01/01/2005"), c2.getRegdate());
	}

	@Test
	public void testAddress() {
		assertEquals(11, addr1.getNumber());
		assertEquals("Main Street", addr1.getStreet());
		assertEquals(21, addr2.getNumber());
		assertEquals("Main Street", addr2.getStreet());
	}

	private Date makeDate(String dateString) throws java.text.ParseException {
		return (new SimpleDateFormat("MM/dd/yyyy")).parse(dateString);
	}
}
