-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from IDATT2003-gruppe06/file-io-development
Added: JavaDoc, Logger, Unit tests, and cleaned up exception messages
- Loading branch information
Showing
9 changed files
with
130 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/main/java/millions/controller/fileIO/InvalidFormatException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 5 additions & 2 deletions
7
src/main/java/millions/controller/fileIO/StockFileWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,14 @@ | ||
| package millions.controller.fileIO; | ||
|
|
||
| import millions.model.Stock; | ||
|
|
||
| import java.nio.file.Path; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Interface for writing stock data to a file. | ||
| */ | ||
| public interface StockFileWriter { | ||
| public void formatString(); | ||
| public boolean write(Path path); | ||
| String formatString(List<Stock> stocks); | ||
| boolean write(List<Stock> stocks, Path path); | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,33 +1,75 @@ | ||
| package millions; | ||
|
|
||
| import millions.controller.fileIO.CSV.CSVStockFileParser; | ||
| import millions.controller.fileIO.InvalidFormatException; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
|
||
| public class CSVStockFileParserTest { | ||
|
|
||
| static String exampleString; | ||
| final CSVStockFileParser parser = new CSVStockFileParser(); | ||
|
|
||
| @BeforeAll | ||
| public static void setUpTestFile() throws Exception { | ||
| public static void setUpTestString() { | ||
| exampleString = "# Top 500 US Stocks by Market Cap\n"; | ||
| exampleString += "# Ticker,Name,Price\n"; | ||
| exampleString += "\n"; | ||
| exampleString += "NVDA,Nvidia,191.27\n"; | ||
| exampleString += "AAPL,Apple Inc.,276.43\n"; | ||
| exampleString += "MSFT,Microsoft,404.68\n"; | ||
|
|
||
| } | ||
|
|
||
| @Test | ||
| public void parseStockFileTest(){ | ||
| List<String> testList = List.of(exampleString.split("\n")); | ||
|
|
||
| CSVStockFileParser parser = new CSVStockFileParser(); | ||
| assertEquals(3, parser.parse(testList).size()); | ||
| } | ||
|
|
||
| @Test | ||
| public void InvalidFormatExceptionTest() { | ||
| exampleString += "Line with incorrect amount of data"; | ||
| List<String> testList = List.of(exampleString.split("\n")); | ||
| Exception e = assertThrows(InvalidFormatException.class, () -> {parser.parse(testList);}); | ||
| String expectedMessage = "Incorrect format for CSV File: incorrect amount of data fields detected on one or more lines"; | ||
| assertEquals(expectedMessage, e.getMessage()); | ||
| } | ||
|
|
||
| @Test | ||
| public void NumberConversionExceptionTest() { | ||
| exampleString += "Company, Company Inc., NotANumber"; | ||
| List<String> testList = List.of(exampleString.split("\n")); | ||
| Exception e = assertThrows(InvalidFormatException.class, () -> {parser.parse(testList);}); | ||
| String expectedMessage = "Error with number conversion on line: Company, Company Inc., NotANumber\n" + | ||
| "Last field must be a number"; | ||
| assertEquals(expectedMessage, e.getMessage()); | ||
| } | ||
|
|
||
| @Test | ||
| public void EmptySymbolFieldExceptionTest() { | ||
| exampleString += ",test,1"; | ||
| List<String> testList = List.of(exampleString.split("\n")); | ||
| Exception e = assertThrows(InvalidFormatException.class, () -> {parser.parse(testList);}); | ||
| String expectedMessage = "Illegal argument on line: ,test,1\n" + | ||
| "Symbol cannot be null or blank"; | ||
| assertEquals(expectedMessage, e.getMessage()); | ||
| } | ||
| @Test | ||
| public void EmptyCompanyNameFieldExceptionTest() { | ||
| exampleString += "test,,1"; | ||
| List<String> testList = List.of(exampleString.split("\n")); | ||
| Exception e = assertThrows(InvalidFormatException.class, () -> {parser.parse(testList);}); | ||
| String expectedMessage = "Illegal argument on line: test,,1\n" + | ||
| "Company cannot be null or blank"; | ||
| assertEquals(expectedMessage, e.getMessage()); | ||
| } | ||
| } |
This file was deleted.
Oops, something went wrong.