-
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.
Test: Added unit testing for file converter
- Loading branch information
Showing
1 changed file
with
74 additions
and
0 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
src/test/java/edu/ntnu/idi/idatt2003/g40/mappe/FileConverterTest.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 |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| package edu.ntnu.idi.idatt2003.g40.mappe; | ||
|
|
||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.math.BigDecimal; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| class FileConverterTest { | ||
|
|
||
| private FileConverter converter; | ||
|
|
||
| private String validStockAsString1; | ||
| private String validStockAsString2; | ||
| private String validStockAsString3; | ||
| private ArrayList<String> allStocks; | ||
| private String invalidStockAsString1; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| validStockAsString1 = "AAPL, Apple inc., 251.42"; | ||
| validStockAsString2 = "NVID, Nvidia corp., 100.25"; | ||
| validStockAsString3 = "SAMS, Samsung corporation, 103.21"; | ||
|
|
||
| invalidStockAsString1 = "INVALID, This stock has an invalid code!, 100.21"; | ||
|
|
||
| allStocks = new ArrayList<>(); | ||
|
|
||
| allStocks.add(validStockAsString1); | ||
| allStocks.add(validStockAsString2); | ||
| allStocks.add(validStockAsString3); | ||
| allStocks.add(invalidStockAsString1); | ||
|
|
||
| converter = new FileConverter(); | ||
| } | ||
|
|
||
| @Test | ||
| void converter_returns_valid_stock_apple() { | ||
|
|
||
| boolean stockIncluded = false; | ||
|
|
||
| List<Stock> stocksFromConverter = converter.getStocksFromStrings(allStocks); | ||
|
|
||
| for (Stock s : stocksFromConverter) { | ||
| if (s.getSymbol().equals("AAPL")) { | ||
| stockIncluded = true; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| Assertions.assertTrue(stockIncluded); | ||
| } | ||
|
|
||
| @Test | ||
| void converter_ignores_invalid_stock_representation() { | ||
|
|
||
| boolean stockIncluded = false; | ||
|
|
||
| List<Stock> stocksFromConverter = converter.getStocksFromStrings(allStocks); | ||
|
|
||
| for (Stock s : stocksFromConverter) { | ||
| if (s.getSymbol().equals("INVALID")) { | ||
| stockIncluded = true; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| Assertions.assertFalse(stockIncluded); | ||
| } | ||
| } |