From d7041c07cb80213b88a4c3396a1f9086283fdea1 Mon Sep 17 00:00:00 2001 From: Michael Fross Date: Fri, 30 Jun 2023 11:42:32 -0500 Subject: [PATCH] Added automated testing to Quoter More can always be done, but it's a good start --- pom.xml | 2 +- snap/snapcraft.yaml | 2 +- .../org/fross/quoter/CommandLineParser.java | 4 +- .../org/fross/quoter/HistoricalQuotes.java | 3 +- src/main/java/org/fross/quoter/Main.java | 5 +- src/main/java/org/fross/quoter/Prefs.java | 10 +- .../fross/quoter/CommandLineParserTest.java | 154 ++++++++++++++++++ .../org/fross/quoter/FileExporterTest.java | 152 +++++++++++++++++ src/test/java/org/fross/quoter/IndexTest.java | 59 +++++++ src/test/java/org/fross/quoter/PrefsTest.java | 65 ++++++++ .../java/org/fross/quoter/SymbolTest.java | 60 +++++++ 11 files changed, 505 insertions(+), 11 deletions(-) create mode 100644 src/test/java/org/fross/quoter/CommandLineParserTest.java create mode 100644 src/test/java/org/fross/quoter/FileExporterTest.java create mode 100644 src/test/java/org/fross/quoter/IndexTest.java create mode 100644 src/test/java/org/fross/quoter/PrefsTest.java create mode 100644 src/test/java/org/fross/quoter/SymbolTest.java diff --git a/pom.xml b/pom.xml index 0f16135..9de5242 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ org.fross quoter - 5.0.7 + 5.0.8 jar quoter diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 1cf4bf2..783732a 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -1,5 +1,5 @@ name: quoter -version: '5.0.7' +version: '5.0.8' summary: Command line utility to pull stock and index quotes description: | Quoter fetches online stock quotes and index data for easy display on diff --git a/src/main/java/org/fross/quoter/CommandLineParser.java b/src/main/java/org/fross/quoter/CommandLineParser.java index 01cc1ef..690f9c3 100644 --- a/src/main/java/org/fross/quoter/CommandLineParser.java +++ b/src/main/java/org/fross/quoter/CommandLineParser.java @@ -44,13 +44,13 @@ public class CommandLineParser { @Parameter(names = { "-w", "--width" }, description = "Set screen width in columns for 3 month trend display") protected int clWidth = 120; - + @Parameter(names = { "-n", "--hide-index" }, description = "Do not display index information") protected boolean clHideIndex = false; @Parameter(names = { "-a", "--auto-refresh" }, description = "Set a refresh time for quotes in seconds", validateWith = AutoRefreshValidator.class) protected int clAutoRefresh = 0; - + @Parameter(names = { "-d", "--trend-duration" }, description = "Set the number of historical days to include in the trend") protected int clTrendDuration = 0; diff --git a/src/main/java/org/fross/quoter/HistoricalQuotes.java b/src/main/java/org/fross/quoter/HistoricalQuotes.java index 64f2514..4fbb579 100644 --- a/src/main/java/org/fross/quoter/HistoricalQuotes.java +++ b/src/main/java/org/fross/quoter/HistoricalQuotes.java @@ -246,7 +246,8 @@ public void displayTrend(String symb) { Output.debugPrint("Slots per Cost Unit: " + slotsPerCostUnit); // Display the symbol informational header - Output.printColorln(Ansi.Color.WHITE, "\n\n+--" + NUM_DAYS_IN_TREND + " Day Trend" + "-".repeat(graphWidth - String.valueOf(NUM_DAYS_IN_TREND).length() + 8) + "+"); + Output.printColorln(Ansi.Color.WHITE, + "\n\n+--" + NUM_DAYS_IN_TREND + " Day Trend" + "-".repeat(graphWidth - String.valueOf(NUM_DAYS_IN_TREND).length() + 8) + "+"); Output.printColorln(Ansi.Color.YELLOW, symb.toUpperCase()); Output.printColorln(Ansi.Color.YELLOW, "Current Price: " + symbolData.get("latestPrice")); Output.printColorln(Ansi.Color.YELLOW, NUM_DAYS_IN_TREND + " Day Low: " + String.format("%,.2f", sv)); diff --git a/src/main/java/org/fross/quoter/Main.java b/src/main/java/org/fross/quoter/Main.java index daae41c..0eac18c 100644 --- a/src/main/java/org/fross/quoter/Main.java +++ b/src/main/java/org/fross/quoter/Main.java @@ -97,8 +97,9 @@ public static void main(String[] args) { } // CLI: Debug Switch - if (cli.clDebug == true) + if (cli.clDebug == true) { Debug.enable(); + } // CLI: list Favorites if (cli.clListFavorites == true) { @@ -125,6 +126,8 @@ public static void main(String[] args) { } if (cli.clTrendDuration != 0) { Prefs.set("trendduration", cli.clTrendDuration); + Output.printColorln(Ansi.Color.YELLOW, "Default trend duration has been set for " + cli.clTrendDuration + " days"); + System.exit(0); } // CLI: Display Version & Latest GitHub Release diff --git a/src/main/java/org/fross/quoter/Prefs.java b/src/main/java/org/fross/quoter/Prefs.java index ad481c0..d6e8218 100644 --- a/src/main/java/org/fross/quoter/Prefs.java +++ b/src/main/java/org/fross/quoter/Prefs.java @@ -30,8 +30,7 @@ import java.util.prefs.Preferences; /** - * Prefs: Holds the logic and calls to the java preferences system. Used to save - * and restore the stacks between sessions. + * Prefs: Holds the logic and calls to the java preferences system. Used to save and restore the stacks between sessions. * * @author michael.d.fross * @@ -62,7 +61,7 @@ public static boolean queryBoolean(String key) { public static Double queryDouble(String key) { return prefs.getDouble(key, 0); } - + /** * QueryInt(): Returns an int preference item * @@ -71,7 +70,7 @@ public static Double queryDouble(String key) { */ public static int queryInt(String key) { return prefs.getInt(key, 0); - } + } /** * QueryString(): Returns a String preference item @@ -122,9 +121,10 @@ public static void set(String key, double value) { public static void set(String key, String value) { prefs.put(key, value); } - + /** * remove(): Remove the provided preference + * * @param key */ public static void remove(String key) { diff --git a/src/test/java/org/fross/quoter/CommandLineParserTest.java b/src/test/java/org/fross/quoter/CommandLineParserTest.java new file mode 100644 index 0000000..5470007 --- /dev/null +++ b/src/test/java/org/fross/quoter/CommandLineParserTest.java @@ -0,0 +1,154 @@ +/************************************************************************************************************** + * Quoter.jar + * + * Quoter is a command line program that display stock quotes and index data. + * + * Copyright (c) 2019-2022 Michael Fross + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + ***************************************************************************************************************/ +package org.fross.quoter; + +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 org.junit.jupiter.api.Test; + +import com.beust.jcommander.JCommander; + +class CommandLineParserTest { + // Test all of the short options + @Test + void testShortCommandLineArgs() { + // Test Short Options + String[] argv1 = { "-z", "-w", "100", "-n", "-a", "60", "-d", "30", "-s", "-l", "-r", "-i", "-t", "-x", "out.csv", "-D", "-v", "-h" }; + + CommandLineParser cli = new CommandLineParser(); + JCommander jc = new JCommander(); + jc.setProgramName("Quoter"); + + jc = JCommander.newBuilder().addObject(cli).build(); + jc.parse(argv1); + + assertTrue(cli.clNoColor); + assertEquals(cli.clWidth, 100); + assertTrue(cli.clHideIndex); + assertEquals(cli.clAutoRefresh, 60); + assertEquals(cli.clTrendDuration, 30); + assertTrue(cli.clSave); + assertTrue(cli.clListFavorites); + assertTrue(cli.clRemoveFavorites); + assertTrue(cli.clIgnoreFavorites); + assertTrue(cli.clTrend); + assertEquals(cli.clExport, "out.csv"); + assertTrue(cli.clDebug); + assertTrue(cli.clVersion); + assertTrue(cli.clHelp); + } + + // Test all of the long options + @Test + void testLongCommandLineArgs() { + // Test Long Options + String[] argv1 = { "--no-color", "--width", "100", "--hide-index", "--auto-refresh", "60", "--trend-duration", "30", "--save", "--list-favorites", + "--remove-favorites", "--ignore-favorites", "--trend", "--export", "out.csv", "--debug", "--version", "--help" }; + + CommandLineParser cli = new CommandLineParser(); + JCommander jc = new JCommander(); + jc.setProgramName("Quoter"); + + jc = JCommander.newBuilder().addObject(cli).build(); + jc.parse(argv1); + + assertTrue(cli.clNoColor); + assertEquals(cli.clWidth, 100); + assertTrue(cli.clHideIndex); + assertEquals(cli.clAutoRefresh, 60); + assertEquals(cli.clTrendDuration, 30); + assertTrue(cli.clSave); + assertTrue(cli.clListFavorites); + assertTrue(cli.clRemoveFavorites); + assertTrue(cli.clIgnoreFavorites); + assertTrue(cli.clTrend); + assertEquals(cli.clExport, "out.csv"); + assertTrue(cli.clDebug); + assertTrue(cli.clVersion); + assertTrue(cli.clHelp); + } + + // Test a mixture of short and long option types + @Test + void testMixedCommandLineArgs1() { + // Test Mix of Options + String[] argv3 = { "--no-color", "-?", "-s", "--version", "--trend", "-d 45" }; + + CommandLineParser cli = new CommandLineParser(); + JCommander jc = new JCommander(); + jc.setProgramName("Quoter"); + + jc = JCommander.newBuilder().addObject(cli).build(); + jc.parse(argv3); + + assertTrue(cli.clNoColor); + assertEquals(cli.clWidth, 120); + assertFalse(cli.clHideIndex); + assertEquals(cli.clAutoRefresh, 0); + assertEquals(cli.clTrendDuration, 0); + assertTrue(cli.clSave); + assertFalse(cli.clListFavorites); + assertFalse(cli.clRemoveFavorites); + assertFalse(cli.clIgnoreFavorites); + assertTrue(cli.clTrend); + assertEquals(cli.clExport, ""); + assertFalse(cli.clDebug); + assertTrue(cli.clVersion); + assertTrue(cli.clHelp); + } + + // Test a mixture of short and long option types + void testMixedCommandLineArgs2() { + // Test Mix of Options + String[] argv4 = { "-w", "400", "--hide-index", "--ignore-favorites", "-x", "testoutput", "-v", "-a", "500", "--debug" }; + + CommandLineParser cli = new CommandLineParser(); + JCommander jc = new JCommander(); + jc.setProgramName("Quoter"); + + jc = JCommander.newBuilder().addObject(cli).build(); + jc.parse(argv4); + + assertFalse(cli.clNoColor); + assertEquals(cli.clWidth, 400); + assertTrue(cli.clHideIndex); + assertEquals(cli.clAutoRefresh, 500); + assertEquals(cli.clTrendDuration, 0); + assertFalse(cli.clSave); + assertFalse(cli.clListFavorites); + assertFalse(cli.clRemoveFavorites); + assertTrue(cli.clIgnoreFavorites); + assertFalse(cli.clTrend); + assertEquals(cli.clExport, "testoutput"); + assertTrue(cli.clDebug); + assertTrue(cli.clVersion); + assertFalse(cli.clHelp); + } + +} diff --git a/src/test/java/org/fross/quoter/FileExporterTest.java b/src/test/java/org/fross/quoter/FileExporterTest.java new file mode 100644 index 0000000..284c921 --- /dev/null +++ b/src/test/java/org/fross/quoter/FileExporterTest.java @@ -0,0 +1,152 @@ +/************************************************************************************************************** + * Quoter.jar + * + * Quoter is a command line program that display stock quotes and index data. + * + * Copyright (c) 2019-2022 Michael Fross + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + ***************************************************************************************************************/ +package org.fross.quoter; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; + +import org.fross.library.Output; +import org.fusesource.jansi.Ansi; +import org.junit.jupiter.api.Test; + +class FileExporterTest { + + // Export the symbol data and then read it back in to ensure it's accurate + @Test + void testSymbolExport() { + String testFileName = "target/testSymbol.export"; + + // Delete export test file if it exists + try { + File file = new File(testFileName); + if (file.canWrite()) { + file.delete(); + } + } catch (Exception ex) { + Output.printColorln(Ansi.Color.RED, "Error deleting " + testFileName + " during FileExporterTest"); + fail(ex.getMessage()); + } + + // Export to the test file + FileExporter fe = new FileExporter(testFileName); + + // Create several securities and export it + String[] testSymbols = { "ACN", "AMZN", "F" }; + for (int i = 0; i < testSymbols.length; i++) { + fe.exportSecurities(new Symbol(testSymbols[i])); + } + fe.close(); + + // Lets read the file and ensure that the symbol names exist + try { + File file = new File(testFileName); + + // Read all lines from the file into an array list + ArrayList fileContents = new ArrayList<>(Files.readAllLines(Paths.get(testFileName))); + + // Verify the lines read from the file match the security number + header + assertEquals(testSymbols.length + 1, fileContents.size()); + + // Read each line and verify it against the test symbol array values + String lineRead = ""; + if (file.canRead() && file.isFile()) { + for (int i = 1; i < fileContents.size(); i++) { + if (!fileContents.get(i).isEmpty()) { + lineRead = fileContents.get(i).toUpperCase(); + assertTrue(lineRead.contains(testSymbols[i - 1].toUpperCase())); + } + } + } else { + throw new Exception(); + } + + } catch (Exception ex) { + fail(ex.getMessage()); + } + + } + + // Export the index data and then read it back in to ensure it's accurate + @Test + void testIndexExport() { + String testFileName = "target/testIndex.export"; + + // Delete export test file if it exists + try { + File file = new File(testFileName); + if (file.canWrite()) { + file.delete(); + } + } catch (Exception ex) { + Output.printColorln(Ansi.Color.RED, "Error deleting " + testFileName + " during FileExporterTest"); + fail(ex.getMessage()); + } + + // Export to the test file + FileExporter fe = new FileExporter(testFileName); + + // Create several securities and export it + String[] testIndexes = { "DOW", "NASDAQ", "S&P" }; + for (int i = 0; i < testIndexes.length; i++) { + fe.exportIndexes(new Index(testIndexes[i])); + } + fe.close(); + + // Lets read the file and ensure that the symbol names exist + try { + File file = new File(testFileName); + + // Read all lines from the file into an array list + ArrayList fileContents = new ArrayList<>(Files.readAllLines(Paths.get(testFileName))); + + // Verify the lines read from the file match the security number + header (and the inserted blank lines) + assertEquals(testIndexes.length + 2, fileContents.size()); + + // Read each line and verify it against the test symbol array values + String lineRead = ""; + if (file.canRead() && file.isFile()) { + for (int i = 2; i < fileContents.size(); i++) { + lineRead = fileContents.get(i).toUpperCase(); + assertTrue(lineRead.contains(testIndexes[i - 2].toUpperCase())); + } + } else { + throw new Exception(); + } + + } catch (Exception ex) { + fail(ex.getMessage()); + } + + } + +} diff --git a/src/test/java/org/fross/quoter/IndexTest.java b/src/test/java/org/fross/quoter/IndexTest.java new file mode 100644 index 0000000..a5a4a6e --- /dev/null +++ b/src/test/java/org/fross/quoter/IndexTest.java @@ -0,0 +1,59 @@ +/************************************************************************************************************** + * Quoter.jar + * + * Quoter is a command line program that display stock quotes and index data. + * + * Copyright (c) 2019-2022 Michael Fross + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + ***************************************************************************************************************/ +package org.fross.quoter; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; + +import org.junit.jupiter.api.Test; + +class IndexTest { + // Look through a list of indexes and ensure all the right fields are present + @Test + void test() { + String[] testIndexes = { "DOW", "NASDAQ", "S&P" }; + String[] testFields = { "index", "latestPrice", "change", "changePercent", "ytdChangePercent", "oneYearChangePercent", "timeStamp", "week52High", + "week52Low", "status" }; + + // Loop through each symbol we are testing + for (int i = 0; i < testIndexes.length; i++) { + Index idx = new Index(testIndexes[i]); + + // Loop through each field and ensure it exists in the currently being tested index + for (int j = 0; j < testFields.length; j++) { + try { + assertNotNull(idx.get(testFields[j])); + + } catch (Exception ex) { + fail("'" + testFields[i] + "' does not exist"); + } + } + } + + } + +} diff --git a/src/test/java/org/fross/quoter/PrefsTest.java b/src/test/java/org/fross/quoter/PrefsTest.java new file mode 100644 index 0000000..d061287 --- /dev/null +++ b/src/test/java/org/fross/quoter/PrefsTest.java @@ -0,0 +1,65 @@ +/************************************************************************************************************** + * Quoter.jar + * + * Quoter is a command line program that display stock quotes and index data. + * + * Copyright (c) 2019-2022 Michael Fross + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + ***************************************************************************************************************/ +package org.fross.quoter; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + +import org.junit.jupiter.api.Test; + +class PrefsTest { + + // Add and retrieve some preferences to ensure they are working + @Test + void test() { + try { + // Set one of each type + Prefs.set("test-boolean", true); + Prefs.set("test-int", 71); + Prefs.set("test-double", Double.parseDouble("100.01")); + Prefs.set("test-string", "hello there"); + + // Query to ensure they match + assertTrue(Prefs.queryBoolean("test-boolean")); + assertEquals(71, Prefs.queryInt("test-int")); + assertEquals(100.01, Prefs.queryDouble("test-double")); + assertEquals("hello there", Prefs.queryString("test-string")); + + // Remove the test preferences + Prefs.remove("test-boolean"); + Prefs.remove("test-int"); + Prefs.remove("test-double"); + Prefs.remove("test-string"); + + } catch (Exception ex) { + fail(ex.getMessage()); + } + + } + +} diff --git a/src/test/java/org/fross/quoter/SymbolTest.java b/src/test/java/org/fross/quoter/SymbolTest.java new file mode 100644 index 0000000..025d64f --- /dev/null +++ b/src/test/java/org/fross/quoter/SymbolTest.java @@ -0,0 +1,60 @@ +/************************************************************************************************************** + * Quoter.jar + * + * Quoter is a command line program that display stock quotes and index data. + * + * Copyright (c) 2019-2022 Michael Fross + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + ***************************************************************************************************************/ +package org.fross.quoter; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; + +import org.junit.jupiter.api.Test; + +class SymbolTest { + + // Look through a list of symbols and ensure all the right fields are present + @Test + void test() { + String[] testSymbols = { "IBM", "TSLA", "GOOG" }; + String[] testFields = { "symbol", "latestPrice", "change", "changePercent", "dayHigh", "dayLow", "ytdChangePercent", "oneYearChangePercent", + "timeStamp", "week52High", "week52Low", "status" }; + + // Loop through each symbol we are testing + for (int i = 0; i < testSymbols.length; i++) { + Symbol symb = new Symbol(testSymbols[i]); + + // Loop through each field and ensure it exists in the currently being tested symbol + for (int j = 0; j < testFields.length; j++) { + try { + assertNotNull(symb.get(testFields[j])); + + } catch (Exception ex) { + fail("'" + testFields[i] + "' does not exist"); + } + } + } + + } + +}