package com.simstock.fetcher;

import java.util.Calendar;

import org.junit.Test;

import static org.junit.Assert.*;

public class YahooDataFetcherTest {

	private static final String URL = YahooDataFetcher.getBasicURL();
	private static final Calendar fromDate = Calendar.getInstance();
	private static final Calendar toDate = Calendar.getInstance();
	YahooDataFetcher yFetcher = new YahooDataFetcher("GOOG");

	@Test
	public void testStockName() {
		assertEquals(URL + "s=GOOG", yFetcher.getURL());
	}

	@Test
	public void testFromDate() {
		fromDate.set(2014, 1, 1);
		yFetcher = new YahooDataFetcher("GOOG", fromDate);
		assertEquals(URL + "s=GOOG&a=0&b=1&c=2014", yFetcher.getURL());
	}

	@Test
	public void testToDate() {
		fromDate.set(2014, 1, 1);
		toDate.set(2015, 1, 1);
		yFetcher = new YahooDataFetcher("AAPL", fromDate, toDate);
		assertEquals(URL + "s=AAPL&a=0&b=1&c=2014&d=0&e=1&f=2015", yFetcher.getURL());
	}

	@Test
	public void testChangeURL() {
		fromDate.set(2013, 3, 21);
		toDate.set(2014, 2, 11);
		yFetcher.setStockSymbol("YHOO");
		yFetcher.setFromDate(fromDate);
		yFetcher.setToDate(toDate);
		assertEquals(URL + "s=YHOO&a=2&b=21&c=2013&d=1&e=11&f=2014", yFetcher.getURL());
	}
}

@@ -20,24 +20,178 @@
 k.fetcher;%0A%0A
+import static org.junit.Assert.assertEquals;%0Aimport static org.junit.Assert.assertFalse;%0Aimport static org.junit.Assert.assertTrue;%0A%0Aimport java.io.File;%0A
 import java.
@@ -234,43 +234,8 @@
 t;%0A%0A
-import static org.junit.Assert.*;%0A%0A
 publ
@@ -548,16 +548,23 @@
 oid test
+UrlWith
 StockNam
@@ -564,16 +564,20 @@
 tockName
+Only
 () %7B%0A%09%09a
@@ -652,16 +652,23 @@
 oid test
+UrlWith
 FromDate
@@ -847,16 +847,23 @@
 oid test
+UrlWith
 ToDate()
@@ -1040,17 +1040,21 @@
 f=2015%22,
- 
+%0A%09%09%09%09
 yFetcher
@@ -1320,25 +1320,29 @@
 =11&f=2014%22,
- 
+%0A%09%09%09%09
 yFetcher.get
@@ -1351,11 +1351,472 @@
 L());%0A%09%7D
+%0A%0A%09@Test%0A%09public void testCsvNotDownloaded() %7B%0A%09%09yFetcher.setStockSymbol(%22600004.SS%22);%0A%09%09File f = yFetcher.csvFile();%0A%09%09assertFalse(System.currentTimeMillis() - f.lastModified() %3C= 8000);%0A%09%7D%0A%0A%09@Test%0A%09public void testCsvDownloaded() %7B%0A%09%09yFetcher.setStockSymbol(%22600004.SS%22);%0A%09%09File f = yFetcher.csvFile();%0A%09%09yFetcher.downloadCsv(f);%0A%09%09assertTrue(f.isFile());%0A%09%09assertFalse(f.isDirectory());%0A%09%09assertTrue(System.currentTimeMillis() - f.lastModified() %3C= 8000);%0A%09%7D
 %0A%7D%0A

update unit test for the download .csv function