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 persistence;
	private List<FundType> ftList;
	private List<Fund> fList;
	private List<FundRate> frList;
	
	@Before
	public void setUp() {
		ftList = new ArrayList<FundType>();
		fList = new ArrayList<Fund>();
		frList = new ArrayList<FundRate>();
		LocalDate fDate = LocalDate.now();
		persistence = PersistenceData.getInstance();
		persistence.setUp();
		FundType type = new FundType(1, "Deuda < 90 días");
		ftList.add(type);
		for (int i = 1; i <= 10; i++) {
			Fund temp = new Fund("Fake " + i, "0-k", "s-"+i, "VTR", type);
			fList.add(temp);
		}
		for (Fund fund : fList) {
			FundRate ft = new FundRate(0.003, fDate, fund);
			frList.add(ft);
		}
	}
	
	@After
	public void tearDown() {
		persistence.tearDown();
	}
	
	@Test
	public void createFundTypeTest() {
		persistence.insertObjectList(ftList);
		List<?> rList = persistence.selectAllObjects("from FundType", FundType.class);
		assertEquals("Stored list size should be equal to received list size", ftList.size(), rList.size());
	}
	
	@Test
	public void createFundTest() {
		persistence.insertObjectList(ftList);
		persistence.insertObjectList(fList);
		List<?> rList = persistence.selectAllObjects("from Fund", Fund.class);
		assertEquals("Stored list size should be equal to received list size", fList.size(), rList.size());
	}
	
	@Test
	public void createFundRateTest() {
		persistence.insertObjectList(ftList);
		persistence.insertObjectList(fList);
		persistence.insertObjectList(frList);
		List<?> rList = persistence.selectAllObjects("from FundRate", FundRate.class);
		assertEquals("Stored list size should be equal to received list size", frList.size(), rList.size());
	}
	
	@Test
	public void duplicationFailTest() {
		persistence.insertObjectList(ftList);
		List<Fund> tempList = new ArrayList<Fund>();
		for (int i = 0; i < 9; i++) {
			Fund temp = new Fund("Arcano", "0-k", "UNICO", "VTR", ftList.get(0));
			tempList.add(temp);
		}
		persistence.insertObjectList(tempList);
		List<?> rList = persistence.selectAllObjects("from Fund", Fund.class);
		assertEquals("Received list should be empty.", 0, rList.size());
	}
}
@@ -26,16 +26,56 @@
 .fund;%0A%0A
+import static org.hamcrest.Matchers.*;%0A%0A
 import s
@@ -2408,9 +2408,348 @@
 ());%0A%09%7D%0A
+%09%0A%09@Test%0A%09public void selectFundByTypeTest() %7B%0A%09%09persistence.insertObjectList(ftList);%0A%09%09persistence.insertObjectList(fList);%0A%09%09persistence.insertObjectList(frList);%0A%09%09FundType type = ftList.get(0);%0A%09%09List%3C?%3E rList = persistence.selectFundByType(type);%0A%09%09assertThat(%22Fund list should be greater than 1.%22, rList.size(), greaterThan(1));%0A%09%7D%0A
 %7D

Add a test case for the select fund by type query.