package cl.fatman.capital.fund;

import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.time.LocalDate;
import java.util.List;
import java.util.ArrayList;

public class PersistenceDataTest {
	
	private PersistenceData connection;
	
	@Before
	public void setUp() {
		connection = PersistenceData.getInstance();
		connection.connect();
	}
	
	@After
	public void tearDown() {
		connection.close();
	}
	
	@Test
	public void createFomentUnitTest() {
		LocalDate fuDate = LocalDate.now();
		List<FomentUnit> fuList = new ArrayList<FomentUnit>();
		fuList.add(new FomentUnit(0.003, fuDate));
		connection.insertObjectList(fuList);
		List<?> tmpList = connection.selectAllObjects("from FomentUnit", FomentUnit.class);
		assertEquals("Foment Unit lists should be equals.", fuList.size(), tmpList.size());
	}
	
	@Test
	public void createFundEntryTest() {
		List<Fund> fundList = new ArrayList<Fund>();
		fundList.add(new Fund("Fake", "0-K", "A", "REM",  "Accionario"));
		fundList.add(new Fund("Fake", "0-K", "B", "REM",  "Accionario"));
		fundList.add(new Fund("Fake", "0-K", "C", "REM",  "Accionario"));
		connection.insertObjectList(fundList);
		List<?> tmpList = connection.selectAllObjects("from Fund", Fund.class);
		assertEquals("Fund lists should be equals", fundList.size(), tmpList.size());
	}
	
	@Test
	public void createFundRateEntryTest() {
		List<FundRate> frList = new ArrayList<FundRate>();
		List<Fund> fundList = new ArrayList<Fund>();
		LocalDate frDate = LocalDate.now();
		FundRate frTmp = null;
		Fund fundTmp = new Fund("Fake", "0-K", "A", "REM",  "Accionario");
		fundList.add(fundTmp);
		connection.insertObjectList(fundList);
		for (int i = 0; i < 10; i++) {
			frTmp = new FundRate(i/10000, frDate);
			frTmp.setFund(fundTmp);
			frList.add(frTmp);
		}
		connection.insertObjectList(frList);
		List<?> tmpList = connection.selectAllObjects("from FundRate", FundRate.class);
		assertEquals("Fund Rate lists should be equals", frList.size(), tmpList.size());
	}
}
@@ -456,32 +456,246 @@
 ();%0A%09%7D%0A%09%0A%09@Test%0A
+%09public void selectEmptyFomentUnitTest() %7B%0A%09%09List%3C?%3E tmpList = connection.selectAllObjects(%22from FomentUnit%22, FomentUnit.class);%0A%09%09assertEquals(%22Foment Unit lists should be empty.%22, 0, tmpList.size());%0A%09%7D%0A%09%0A%09@Test%0A
 %09public void cre
@@ -1071,32 +1071,221 @@
 ));%0A%09%7D%0A%09%0A%09@Test%0A
+%09public void selectEmptyFundTest() %7B%0A%09%09List%3C?%3E tmpList = connection.selectAllObjects(%22from Fund%22, Fund.class);%0A%09%09assertEquals(%22Fund lists should be empty.%22, 0, tmpList.size());%0A%09%7D%0A%09%0A%09@Test%0A
 %09public void cre
@@ -1291,21 +1291,16 @@
 eateFund
-Entry
 Test() %7B
@@ -1705,24 +1705,25 @@
 ld be equals
+.
 %22, fundList.
@@ -1764,32 +1764,238 @@
 st%0A%09public void 
+selectEmptyFundRateTest() %7B%0A%09%09List%3C?%3E tmpList = connection.selectAllObjects(%22from FundRate%22, FundRate.class);%0A%09%09assertEquals(%22Fund Rate lists should be equals%22, 0, tmpList.size());%0A%09%7D%0A%09%0A%09@Test%0A%09public void 
 createFundRateEn
@@ -1996,13 +1996,8 @@
 Rate
-Entry
 Test

Update the junit test method and add more tests to junit.