-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implementation of tests for fruitshop #801
base: main
Are you sure you want to change the base?
Conversation
import org.junit.jupiter.api.Test; | ||
|
||
class DataParserImplTest { | ||
private List<String> stringList; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't need these variables as class fields. Create it and execute it in test methods
|
||
@Test | ||
void parseStringToDataObject_parameterIsNull_notOk() { | ||
assertThrows(NullPointerException.class, () -> dataParser.parseStringToDataObject(null)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you have no business logic that sells this error, so this test is not correct
String fileName = null; | ||
assertThrows(NullPointerException.class, () -> reader.readDataFromFile(fileName)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String fileName = null; | |
assertThrows(NullPointerException.class, () -> reader.readDataFromFile(fileName)); | |
assertThrows(NullPointerException.class, () -> reader.readDataFromFile(null)); | |
String fileName = "hello"; | ||
assertThrows(RuntimeException.class, () -> reader.readDataFromFile(fileName)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String fileName = "hello"; | |
assertThrows(RuntimeException.class, () -> reader.readDataFromFile(fileName)); | |
assertThrows(RuntimeException.class, () -> reader.readDataFromFile("hello")); | |
} | ||
|
||
@Test | ||
void readDataFromFile_filaNameDoesntExist_notOk() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
void readDataFromFile_filaNameDoesntExist_notOk() { | |
void readDataFromFile_fileNameDoesntExist_notOk() { | |
private static Map<Operation, OperationHandler> operationHandlerMap; | ||
private List<FruitTransaction> dataLinesObj; | ||
private FruitService fruitService; | ||
|
||
@BeforeAll | ||
static void beforeAll() { | ||
operationHandlerMap = new HashMap<>(); | ||
operationHandlerMap.put(Operation.BALANCE, new BalanceOperationHandler()); | ||
operationHandlerMap.put(Operation.PURCHASE, new PurchaseOperationHandler()); | ||
operationHandlerMap.put(Operation.SUPPLY, new SupplyOperationHandler()); | ||
operationHandlerMap.put(Operation.RETURN, new ReturnOperationHandler()); | ||
} | ||
|
||
@BeforeEach | ||
void setUp() { | ||
Storage.setStorage(new HashMap<>()); | ||
fruitService = new FruitServiceImpl(operationHandlerMap); | ||
dataLinesObj = new ArrayList<>(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private static Map<Operation, OperationHandler> operationHandlerMap; | |
private List<FruitTransaction> dataLinesObj; | |
private FruitService fruitService; | |
@BeforeAll | |
static void beforeAll() { | |
operationHandlerMap = new HashMap<>(); | |
operationHandlerMap.put(Operation.BALANCE, new BalanceOperationHandler()); | |
operationHandlerMap.put(Operation.PURCHASE, new PurchaseOperationHandler()); | |
operationHandlerMap.put(Operation.SUPPLY, new SupplyOperationHandler()); | |
operationHandlerMap.put(Operation.RETURN, new ReturnOperationHandler()); | |
} | |
@BeforeEach | |
void setUp() { | |
Storage.setStorage(new HashMap<>()); | |
fruitService = new FruitServiceImpl(operationHandlerMap); | |
dataLinesObj = new ArrayList<>(); | |
} | |
private FruitService fruitService; | |
@BeforeAll | |
static void beforeAll() { | |
Map<Operation, OperationHandler> operationHandlerMap; | |
operationHandlerMap = new HashMap<>(); | |
operationHandlerMap.put(Operation.BALANCE, new BalanceOperationHandler()); | |
operationHandlerMap.put(Operation.PURCHASE, new PurchaseOperationHandler()); | |
operationHandlerMap.put(Operation.SUPPLY, new SupplyOperationHandler()); | |
operationHandlerMap.put(Operation.RETURN, new ReturnOperationHandler()); | |
fruitService = new FruitServiceImpl(operationHandlerMap); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FruitService isn't static, so I can't initialize it in beforeAll method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make it static)
|
||
@Test | ||
void processFruits_validCase_ok() { | ||
dataLinesObj.add(new FruitTransaction(Operation.BALANCE, "banana", 20)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add the logic to add the object to Storage and use it here.
|
||
@Test | ||
void processFruits_nullAsParameter_notOk() { | ||
assertThrows(NullPointerException.class, () -> fruitService.processFruits(null)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you have no business logic that sells this error, so this test is not correct
@Test | ||
void createReport_nullAsParameter_notOk() { | ||
Storage.setStorage(null); | ||
assertThrows(NullPointerException.class, () -> reportCreator.createReport()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you have no business logic that sells this error, so this test is not correct
|
||
@Test | ||
void getOperationHandler_validCase_ok() { | ||
OperationHandler expected = new SupplyOperationHandler(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make it class field
private OperationStrategy operationStrategy; | ||
private OperationHandler expected; | ||
|
||
@BeforeEach |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make field static and use BeforeAll
private static Map<Operation, OperationHandler> operationHandlerMap; | ||
private List<FruitTransaction> dataLinesObj; | ||
private FruitService fruitService; | ||
|
||
@BeforeAll | ||
static void beforeAll() { | ||
operationHandlerMap = new HashMap<>(); | ||
operationHandlerMap.put(Operation.BALANCE, new BalanceOperationHandler()); | ||
operationHandlerMap.put(Operation.PURCHASE, new PurchaseOperationHandler()); | ||
operationHandlerMap.put(Operation.SUPPLY, new SupplyOperationHandler()); | ||
operationHandlerMap.put(Operation.RETURN, new ReturnOperationHandler()); | ||
} | ||
|
||
@BeforeEach | ||
void setUp() { | ||
Storage.setStorage(new HashMap<>()); | ||
fruitService = new FruitServiceImpl(operationHandlerMap); | ||
dataLinesObj = new ArrayList<>(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make it static)
No description provided.