|
|
|
@ -16,39 +16,32 @@ import static org.junit.jupiter.api.Assertions.fail;
|
|
|
|
|
|
|
|
|
|
|
|
public class WatchListTest {
|
|
|
|
public class WatchListTest {
|
|
|
|
private WatchList watchlist;
|
|
|
|
private WatchList watchlist;
|
|
|
|
private Main mainObj;
|
|
|
|
|
|
|
|
private StypeMap smap;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@BeforeEach
|
|
|
|
@BeforeEach
|
|
|
|
public void runBefore() {
|
|
|
|
public void runBefore() {
|
|
|
|
mainObj = new Main(true);
|
|
|
|
watchlist = new WatchList();
|
|
|
|
watchlist = mainObj.getWatchList();
|
|
|
|
|
|
|
|
smap = new StypeMap();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testAddStock() {
|
|
|
|
public void testAddStock() {
|
|
|
|
StockType nyyyse = smap.getStype("Nyse");
|
|
|
|
|
|
|
|
for (int i = 0; i < 100; i++) {
|
|
|
|
for (int i = 0; i < 100; i++) {
|
|
|
|
watchlist.addStock(Integer.toString(i), nyyyse);
|
|
|
|
watchlist.addStock(Integer.toString(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testSize() {
|
|
|
|
public void testSize() {
|
|
|
|
assertEquals(watchlist.size(), 0);
|
|
|
|
assertEquals(watchlist.size(), 0);
|
|
|
|
StockType nyyyse = smap.getStype("Nyse");
|
|
|
|
|
|
|
|
for (int i = 0; i < 100; i++) {
|
|
|
|
for (int i = 0; i < 100; i++) {
|
|
|
|
watchlist.addStock(Integer.toString(i), nyyyse);
|
|
|
|
watchlist.addStock(Integer.toString(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assertEquals(watchlist.size(), 100);
|
|
|
|
assertEquals(watchlist.size(), 100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testDelStockNoThrow() {
|
|
|
|
public void testDelStockNoThrow() {
|
|
|
|
StockType nyyyse = smap.getStype("Nyse");
|
|
|
|
|
|
|
|
for (int i = 0; i < 100; i++) {
|
|
|
|
for (int i = 0; i < 100; i++) {
|
|
|
|
watchlist.addStock(Integer.toString(i), nyyyse);
|
|
|
|
watchlist.addStock(Integer.toString(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (int i = 0; i < 50; i++) {
|
|
|
|
for (int i = 0; i < 50; i++) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
@ -62,9 +55,8 @@ public class WatchListTest {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testDelNotExistsStock() {
|
|
|
|
public void testDelNotExistsStock() {
|
|
|
|
StockType nyyyse = smap.getStype("Nyse");
|
|
|
|
|
|
|
|
for (int i = 0; i < 100; i++) {
|
|
|
|
for (int i = 0; i < 100; i++) {
|
|
|
|
watchlist.addStock(Integer.toString(i), nyyyse);
|
|
|
|
watchlist.addStock(Integer.toString(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
watchlist.delStock(Integer.toString(-1));
|
|
|
|
watchlist.delStock(Integer.toString(-1));
|
|
|
|
@ -76,17 +68,30 @@ public class WatchListTest {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testSaveLoad() {
|
|
|
|
public void testSaveLoad() {
|
|
|
|
StockType nyyyse = smap.getStype("Nyse");
|
|
|
|
|
|
|
|
for (int i = 0; i < 100; i++) {
|
|
|
|
for (int i = 0; i < 100; i++) {
|
|
|
|
watchlist.addStock(Integer.toString(i), nyyyse);
|
|
|
|
watchlist.addStock(Integer.toString(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
watchlist.save("");
|
|
|
|
watchlist.save("");
|
|
|
|
assertTrue(watchlist.fileExists(watchlist.DEFAULT_SAVEFILE));
|
|
|
|
assertTrue(watchlist.fileExists(watchlist.DEFAULT_SAVEFILE));
|
|
|
|
Main testMain = new Main(true);
|
|
|
|
WatchList testlist = new WatchList();
|
|
|
|
WatchList testlist = testMain.getWatchList();
|
|
|
|
|
|
|
|
testlist.load("");
|
|
|
|
testlist.load("");
|
|
|
|
assertEquals(watchlist.size(), testlist.size());
|
|
|
|
assertEquals(watchlist.size(), testlist.size());
|
|
|
|
File testFile = new File(watchlist.DEFAULT_SAVEFILE);
|
|
|
|
File testFile = new File(watchlist.DEFAULT_SAVEFILE);
|
|
|
|
testFile.delete();
|
|
|
|
testFile.delete();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void testFileNotFound() {
|
|
|
|
|
|
|
|
//redirect stdout: https://stackoverflow.com/questions/1119385/junit-test-for-system-out-println
|
|
|
|
|
|
|
|
ByteArrayOutputStream outContent = new ByteArrayOutputStream();
|
|
|
|
|
|
|
|
ByteArrayOutputStream errContent = new ByteArrayOutputStream();
|
|
|
|
|
|
|
|
PrintStream originalOut = System.out;
|
|
|
|
|
|
|
|
PrintStream originalErr = System.err;
|
|
|
|
|
|
|
|
System.setOut(new PrintStream(outContent));
|
|
|
|
|
|
|
|
System.setErr(new PrintStream(errContent));
|
|
|
|
|
|
|
|
watchlist.load("thisfiledoesnotexist-andwillneverexists");
|
|
|
|
|
|
|
|
assertEquals("File not found: thisfiledoesnotexist-andwillneverexists\n", outContent.toString());
|
|
|
|
|
|
|
|
System.setOut(originalOut);
|
|
|
|
|
|
|
|
System.setErr(originalErr);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|