|
|
|
|
@ -1,7 +1,10 @@
|
|
|
|
|
package data;
|
|
|
|
|
|
|
|
|
|
import data.WatchList;
|
|
|
|
|
import data.StypeMap;
|
|
|
|
|
import data.StockType;
|
|
|
|
|
import data.Nyse;
|
|
|
|
|
import data.exceptions.*;
|
|
|
|
|
import ui.Main;
|
|
|
|
|
import java.io.*;
|
|
|
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
|
|
|
@ -9,6 +12,7 @@ import org.junit.jupiter.api.Test;
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.fail;
|
|
|
|
|
|
|
|
|
|
public class WatchListTest {
|
|
|
|
|
private WatchList watchlist;
|
|
|
|
|
@ -18,7 +22,7 @@ public class WatchListTest {
|
|
|
|
|
@BeforeEach
|
|
|
|
|
public void runBefore() {
|
|
|
|
|
mainObj = new Main(true);
|
|
|
|
|
watchlist = mainObj.getWatchList();
|
|
|
|
|
watchlist = mainObj.getWatchList();
|
|
|
|
|
smap = new StypeMap();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -39,19 +43,37 @@ public class WatchListTest {
|
|
|
|
|
}
|
|
|
|
|
assertEquals(watchlist.size(), 100);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testDelStock() {
|
|
|
|
|
public void testDelStockNoThrow() {
|
|
|
|
|
StockType nyyyse = smap.getStype("Nyse");
|
|
|
|
|
for (int i = 0; i < 100; i++) {
|
|
|
|
|
watchlist.addStock(Integer.toString(i), nyyyse);
|
|
|
|
|
}
|
|
|
|
|
for (int i = 0; i < 50; i++) {
|
|
|
|
|
watchlist.delStock(Integer.toString(i));
|
|
|
|
|
try {
|
|
|
|
|
watchlist.delStock(Integer.toString(i));
|
|
|
|
|
} catch (WatchListExceptions e) {
|
|
|
|
|
fail();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
assertEquals(watchlist.size(), 50);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testDelNotExistsStock() {
|
|
|
|
|
StockType nyyyse = smap.getStype("Nyse");
|
|
|
|
|
for (int i = 0; i < 100; i++) {
|
|
|
|
|
watchlist.addStock(Integer.toString(i), nyyyse);
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
watchlist.delStock(Integer.toString(-1));
|
|
|
|
|
fail();
|
|
|
|
|
} catch (WatchListExceptions e) {
|
|
|
|
|
//expected to throw
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testSaveLoad() {
|
|
|
|
|
StockType nyyyse = smap.getStype("Nyse");
|
|
|
|
|
@ -60,9 +82,9 @@ public class WatchListTest {
|
|
|
|
|
}
|
|
|
|
|
watchlist.save("");
|
|
|
|
|
assertTrue(watchlist.fileExists(watchlist.DEFAULT_SAVEFILE));
|
|
|
|
|
Main testMain = new Main(true);
|
|
|
|
|
WatchList testlist = testMain.getWatchList();
|
|
|
|
|
testlist.load("");
|
|
|
|
|
Main testMain = new Main(true);
|
|
|
|
|
WatchList testlist = testMain.getWatchList();
|
|
|
|
|
testlist.load("");
|
|
|
|
|
assertEquals(watchlist.size(), testlist.size());
|
|
|
|
|
File testFile = new File(watchlist.DEFAULT_SAVEFILE);
|
|
|
|
|
testFile.delete();
|