diff --git a/README.md b/README.md
index fc0952f..16e24a3 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@
Calls various APIs to get data on stock prices and currency rates, which it then uses to convert user input in the form of stock and amount owned to total value of portfolio in euros over time. The value of the portfolio is graphed using a JavaFX GUI.
-![Graph showing 1 AAPL stock owned from March 1st to Match 25th 2019](example.png)
+![Example of graph made by StockTracker](example.png)
## Getting Started
@@ -15,7 +15,7 @@ For functional usage navigate to "Help -> Getting Started" from the menu bar of
* [Java 8](https://www.oracle.com/technetwork/java/javase/overview/java8-2100321.html) - The programming language used
* [Maven](https://maven.apache.org/) - Dependency Management, project building and deployment
* [Alpha Vantage API](https://www.alphavantage.co/) - API for fetching stock price data
-* [Quotes API for Yahoo Finance] (https://financequotes-api.com/) - API for fetching additional stock data
+* [Quotes API for Yahoo Finance](https://financequotes-api.com/) - API for fetching additional stock data
* [ECB SDMX 2.1 RESTful web service](https://sdw-wsrest.ecb.europa.eu/help/) - API for fetching currency data
* [JavaFX](https://openjfx.io/), [JUnit 5](https://junit.org/junit5/)
diff --git a/pom.xml b/pom.xml
index e559146..37900cb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
Laane.Sten
StockTracker
- 1.4.0
+ 1.4.1
UTF-8
@@ -18,7 +18,7 @@
0002
- mulesoft (for xmlparser
+ mulesoft (for xmlparser)
https://repository.mulesoft.org/nexus/content/repositories/public/
diff --git a/src/main/java/stocktracker/StockTracker.java b/src/main/java/stocktracker/StockTracker.java
index 2ad9d54..d3f4db3 100644
--- a/src/main/java/stocktracker/StockTracker.java
+++ b/src/main/java/stocktracker/StockTracker.java
@@ -12,12 +12,10 @@
import java.util.ArrayList;
import java.util.List;
-//TODO: Add more/better jUnit testing
-//TODO: Account for dividends using AlphaVantage + add boolean for reinvesting dividends
-//TODO: Add enum for constants
+//TODO: Add enum for constants (version, path, max_stocks)
public class StockTracker {
- public static final String VERSION = "1.3.0";
+ public static final String VERSION = "1.4.1";
public static final int MAX_STOCKS = 5;
public static final String PATH;
diff --git a/src/main/java/stocktracker/StockTrackerGUI.java b/src/main/java/stocktracker/StockTrackerGUI.java
index 3689885..8320da1 100644
--- a/src/main/java/stocktracker/StockTrackerGUI.java
+++ b/src/main/java/stocktracker/StockTrackerGUI.java
@@ -6,10 +6,12 @@
import javafx.scene.Scene;
import javafx.scene.chart.*;
import javafx.scene.control.*;
+import javafx.scene.input.KeyCode;
import javafx.scene.paint.Color;
import javafx.scene.image.Image;
import javafx.scene.layout.*;
import javafx.scene.paint.ImagePattern;
+import javafx.scene.text.TextAlignment;
import javafx.stage.Screen;
import javafx.stage.Stage;
import jfxtras.styles.jmetro8.JMetro;
@@ -20,7 +22,7 @@
import java.util.*;
//TODO: Add progress bars/loading indication
-//TODO: Add listener for pressing enter in "new tracker" scene as shortcut to go button
+//TODO: Add more styling to make GUI look better
public class StockTrackerGUI extends Application {
private Stage primaryStage;
@@ -175,14 +177,36 @@ public void updateItem(LocalDate date, boolean empty) {
ExtendableTextField tickerCurrencyTextField = new ExtendableTextField(inputDataBox);
tickerCurrencyTextField.setMaxWidth(200);
tickerCurrencyTextField.setPromptText("ticker");
-
+ tickerCurrencyTextField.amountField.setOnKeyPressed(e -> {
+ if (e.getCode().equals(KeyCode.ENTER)) {
+ plotNewData(startDate.getValue());
+ }
+ });
inputDataBox.setAlignment(Pos.CENTER);
+ Label errorLabel = new Label();
+ errorLabel.setTextFill(Color.RED);
+ errorLabel.setTextAlignment(TextAlignment.LEFT);
+ errorLabel.setPrefWidth(270);
Button goButton = new Button("Go!");
- goButton.setOnAction(e -> plotNewData(startDate.getValue()));
+ goButton.setOnAction(e -> {
+ if (checkValidInput() && startDate.getValue() != null) {
+ plotNewData(startDate.getValue());
+ }
+ else {
+ errorLabel.setText("");
+ if (!checkValidInput()) {
+ errorLabel.setText("Input a stock ticker and a corresponding amount\n");
+ }
+ if (startDate.getValue() == null) {
+ errorLabel.setText(errorLabel.getText() + "Pick a date");
+ }
- VBox contentPane = new VBox(startDateBox, inputDataBox, goButton);
+ }
+ });
+
+ VBox contentPane = new VBox(startDateBox, inputDataBox, errorLabel, goButton);
contentPane.setSpacing(30);
contentPane.setAlignment(Pos.CENTER);
root.getChildren().add(contentPane);
@@ -190,6 +214,20 @@ public void updateItem(LocalDate date, boolean empty) {
createScene(root);
}
+ private boolean checkValidInput() {
+ boolean valid = true;
+ for (ExtendableTextField field: stocksTracked) {
+ if (field.getText().equals("") && !field.amountField.getText().equals("") ||
+ !field.getText().equals("") && field.amountField.getText().equals("")) {
+ valid = false;
+ }
+ }
+ if (stocksTracked.get(0).getText().equals("") || stocksTracked.get(0).amountField.getText().equals("")) {
+ valid = false;
+ }
+ return valid;
+ }
+
private void plotNewData(LocalDate startDate) {
ArrayList dataList = new ArrayList<>();
ArrayList amounts = new ArrayList<>();
diff --git a/src/test/java/stocktracker/DataAggregatorTest.java b/src/test/java/stocktracker/DataAggregatorTest.java
index b550467..48480c3 100644
--- a/src/test/java/stocktracker/DataAggregatorTest.java
+++ b/src/test/java/stocktracker/DataAggregatorTest.java
@@ -51,6 +51,7 @@ void testSingleAggregation() {
assertEquals(3, line.split(",").length);
assertDoesNotThrow(() -> LocalDate.parse(line.split(",")[0]));
}
+
@Nested
@DisplayName("compoundAggregation")
class compoundAggregate {
diff --git a/src/test/java/stocktracker/StockTrackerTest.java b/src/test/java/stocktracker/StockTrackerTest.java
index 3e97b9d..b670982 100644
--- a/src/test/java/stocktracker/StockTrackerTest.java
+++ b/src/test/java/stocktracker/StockTrackerTest.java
@@ -2,16 +2,16 @@
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import java.io.File;
-import java.io.IOException;
import java.time.LocalDate;
import java.util.ArrayList;
+import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
-//TODO: These tests are bad. Fix it
class StockTrackerTest {
private static ArrayList testList;
@@ -28,9 +28,9 @@ static void setup() {
testAmounts.add(10);
}
+ @Order(1)
@Test
- void runNewTest()
- {
+ void runNewTest() throws InterruptedException {
StockTracker.createConfig(testList, testAmounts);
StockTracker.writeData("IVV", LocalDate.now().minusDays(139));
StockTracker.writeData("QQQ", LocalDate.now().minusDays(139));
@@ -39,15 +39,23 @@ void runNewTest()
System.out.println("$$$");
StockTracker.calculateMoney(testList, testAmounts);
StockTracker.createSave();
- StockTracker.deleteTempFiles();
System.out.println("Files aggregated, money calculated");
System.out.println("Done");
assertTrue(new File(PATH + "save_data.csv").exists());
assertTrue(new File(PATH + "save_config.csv").exists());
assertFalse(StockTracker.updateSave());
+ Thread.sleep(30000);
}
- //TODO: test actually updating the save
+ @Order(2)
+ @Test
+ void testUpdate() {
+ List originalData = FileManager.readLines(PATH + "save_data.csv");
+ List data = originalData.subList(0, originalData.size()-10);
+ FileManager.writeList(PATH + "save_data.csv", data);
+ assertTrue(StockTracker.updateSave());
+ assertEquals(FileManager.readLines(PATH + "save_data.csv"), originalData);
+ }
@AfterAll
static void teardown() {