Skip to content

Commit

Permalink
fixed according to the comments
Browse files Browse the repository at this point in the history
  • Loading branch information
YevheniiVlasenko committed Nov 3, 2023
1 parent a1fbb6f commit c6e3937
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@

public class CsvDataReaderTest {
private static final String INPUT_VALID_FILE =
"src/test/test-resources/input-files/TestValidInputFile.txt";
"src/test/test-resources/input-files/TestValidInputFile.csv";
private static final String INPUT_EMPTY_FILE =
"src/test/test-resources/input-files/TestEmptyFile.txt";
"src/test/test-resources/input-files/TestEmptyFile.csv";
private static final String INPUT_NONEXISTENT_FILE =
"src/test/test-resources/input-files/doesNotExist.txt";
private static final String INPUT_RANDOM_LINES_FILE =
"src/test/test-resources/input-files/TestRandomLines.txt";
"src/test/test-resources/input-files/TestRandomLines.csv";
private static final CsvDataReader csvDataReader = new CsvDataReader();

@Test
public void readFileLines_allValidConditions_Ok() {
List<String> actual = csvDataReader.readFileLines(INPUT_VALID_FILE);
List<String> expected = List.of("type,fruit,quantity", "b,banana,20");
assertEquals(actual, expected);
assertEquals(expected, actual);
}

@Test
Expand All @@ -42,6 +42,6 @@ public void readFileLines_inputWithCustomLines_Ok() {
"fwpueivwrnv",
"vpaerhgp48g oiwjeiof",
"whvwvoiwn");
assertEquals(actual, expected);
assertEquals(expected, actual);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ public class CsvDataWriterTest {
private static final String VALID_STRING = "Some VALID STrING";
private static final String EMPTY_STRING = "";
private static final String NONEXISTENT_DESTINATION_FILE =
"src/test/test-resources/output-files/nonexistent.txt";
"src/test/test-resources/output-files/nonexistent.csv";
private static final String VALID_DESTINATION_FILE =
"src/test/test-resources/output-files/TestValidFile.txt";
private final CsvDataWriter csvDataWriter = new CsvDataWriter();
"src/test/test-resources/output-files/TestValidFile.csv";
private static CsvDataWriter csvDataWriter = new CsvDataWriter();

@Test
public void writeToFile_allValidConditions_Ok() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void convertToFruitTransactionList_allValidConditions() {
FruitTransaction expected = new FruitTransaction(
FruitTransaction.OperationType.BALANCE, "banana", 20);
FruitTransaction actual = parser.convertToFruitTransactionList(VALID_INPUT).get(0);
assertEquals(actual, expected);
assertEquals(expected, actual);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.junit.jupiter.api.Test;

public class CsvReportGeneratorTest {
private static final String VALID_RESUL_STRING = "fruit,quantity"
private static final String VALID_RESULT_STRING = "fruit,quantity"
+ System.lineSeparator()
+ "banana,152";
private static InventoryDao inventoryDao;
Expand All @@ -31,7 +31,7 @@ public void cleanInventory() {
public void generateReport_allValidConditions() {
inventoryDao.putToInventory("banana", 152);
String actual = csvReportGenerator.generateReport();
assertEquals(actual, VALID_RESUL_STRING);
assertEquals(VALID_RESULT_STRING, actual);
}

@Test
Expand All @@ -49,6 +49,6 @@ public void generateReport_with_RandomDataInInventory_Ok() {
+ "fruit2," + 2 + System.lineSeparator()
+ "fruit1," + 1 + System.lineSeparator()
+ "fruit0," + 0;
assertEquals(actual, expected);
assertEquals(expected, actual);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
import org.junit.jupiter.api.Test;

public class TransactionProcessorImplTest {
private static final HandlerStrategy strategy = new HandlerStrategy(new HashMap<>());
private static HandlerStrategy strategy;
private static InventoryDao inventoryDao;
private static TransactionProcessorImpl transactionProcessor;
private static FruitTransaction testTransaction;

@BeforeAll
static void setUp() {
strategy = new HandlerStrategy(new HashMap<>());
inventoryDao = new InventoryDaoImpl();
transactionProcessor = new TransactionProcessorImpl(strategy);
strategy.getStrategyMap().put(OperationType.BALANCE, new BalanceHandler(inventoryDao));
Expand All @@ -52,20 +53,17 @@ public void processTransaction_withAllValid_Ok() {
() -> {
transactionProcessor.processTransaction(testTransaction);
assertEquals(100, inventoryDao.getAmountByFruit("potato"));

},
() -> {
testTransaction.setOperationType(OperationType.PURCHASE);
testTransaction.setQuantity(15);
transactionProcessor.processTransaction(testTransaction);

assertEquals(85, inventoryDao.getAmountByFruit("potato"));
},
() -> {
testTransaction.setOperationType(OperationType.SUPPLY);
testTransaction.setQuantity(25);
transactionProcessor.processTransaction(testTransaction);

assertEquals(110, inventoryDao.getAmountByFruit("potato"));
},
() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ public class HandlerStrategyTest {
private static InventoryDao inventoryDao;
private static final Map<OperationType, OperationHandler> testMap = new HashMap<>();
private static HandlerStrategy handlerStrategy = new HandlerStrategy(testMap);

private static BalanceHandler balanceHandler;
private static PurchaseHandler purchaseHandler;
private static ReturnHandler returnHandler;
private static SupplyHandler supplyHandler;

@BeforeAll
public static void setUP() {
public static void setUp() {
handlerStrategy = new HandlerStrategy(testMap);
inventoryDao = new InventoryDaoImpl();
balanceHandler = new BalanceHandler(inventoryDao);
Expand All @@ -41,7 +40,7 @@ public static void setUP() {
}

@Test
public void etHandlerByOperationType_validTypes_Ok() {
public void getHandlerByOperationType_validTypes_Ok() {
assertAll(
() -> assertEquals(balanceHandler,
handlerStrategy.getHandlerByOperationType(OperationType.BALANCE),
Expand All @@ -60,7 +59,8 @@ public void etHandlerByOperationType_validTypes_Ok() {

@Test
public void getHandlerByOperationType_byNullOperationType_NotOk() {
assertThrows(RuntimeException.class, () -> handlerStrategy.getHandlerByOperationType(null));
assertThrows(RuntimeException.class,
() -> handlerStrategy.getHandlerByOperationType(null));
}

@Test
Expand Down

0 comments on commit c6e3937

Please sign in to comment.