Skip to content

Commit

Permalink
Created test for project FruitShop. Covered more than 96%.
Browse files Browse the repository at this point in the history
  • Loading branch information
opopovych committed Sep 18, 2023
1 parent 7fda1da commit d19415d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,4 @@ public String getCode() {
}
}

@Override
public String toString() {
return "FruitTransaction{"
+ "operation='" + operation + '\''
+ ", fruit='" + fruit + '\''
+ ", quantity=" + quantity
+ '}';
}
}
2 changes: 0 additions & 2 deletions src/main/java/core/basesyntax/serviceimpl/ReportService.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ public class ReportService {
public String createReport() {
StringBuilder reportBuilder = new StringBuilder();
reportBuilder.append("fruit,quantity");

for (Map.Entry<String, Integer> entry : Storage.DB.entrySet()) {
reportBuilder.append(System.lineSeparator())
.append(entry.getKey())
.append(",")
.append(entry.getValue());
}

return reportBuilder.toString();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package core.basesyntax.serviceimpl;

import core.basesyntax.db.Storage;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -14,8 +15,11 @@ void setUp() {

@Test
void createReport_Ok() {
Storage.DB.put("banana",10);
String actual = reportService.createReport();
String expected = "fruit,quantity";
String expected = "fruit,quantity"
+ System.lineSeparator()
+ "banana,10";
Assertions.assertEquals(expected,actual);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,25 @@ void processData_Ok() {
Assertions.assertEquals(15,Storage.DB.get("apple"));
}

@Test
void fruitTransaction_OK() {
FruitTransaction fruitTransaction = new FruitTransaction(FruitTransaction
.Operation.BALANCE,"apple",20);
FruitTransaction fruitTransaction1 = new FruitTransaction(FruitTransaction
.Operation.SUPPLY, "apple",5);
FruitTransaction fruitTransaction2 = new FruitTransaction(FruitTransaction
.Operation.BALANCE, "banana",20);
transactionService.processData(List.of(fruitTransaction,fruitTransaction1,
fruitTransaction2));
Assertions.assertEquals(25,Storage.DB.get("apple"));
fruitTransaction2.setOperation(FruitTransaction.Operation.PURCHASE);
fruitTransaction2.setQuantity(10);
fruitTransaction2.setFruit("banana");
transactionService.processData(List.of(fruitTransaction,fruitTransaction1,
fruitTransaction2));
Assertions.assertEquals(10,Storage.DB.get("banana"));
}

@AfterEach
void tearDown() {
Storage.DB.clear();
Expand Down

0 comments on commit d19415d

Please sign in to comment.