Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sonyasapsan
Copy link

No description provided.

import org.junit.jupiter.api.Test;

class DataParserImplTest {
private List<String> stringList;

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));

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

Comment on lines 22 to 23
String fileName = null;
assertThrows(NullPointerException.class, () -> reader.readDataFromFile(fileName));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
String fileName = null;
assertThrows(NullPointerException.class, () -> reader.readDataFromFile(fileName));
assertThrows(NullPointerException.class, () -> reader.readDataFromFile(null));

Comment on lines 28 to 29
String fileName = "hello";
assertThrows(RuntimeException.class, () -> reader.readDataFromFile(fileName));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
String fileName = "hello";
assertThrows(RuntimeException.class, () -> reader.readDataFromFile(fileName));
assertThrows(RuntimeException.class, () -> reader.readDataFromFile("hello"));

}

@Test
void readDataFromFile_filaNameDoesntExist_notOk() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
void readDataFromFile_filaNameDoesntExist_notOk() {
void readDataFromFile_fileNameDoesntExist_notOk() {

Comment on lines +25 to +43
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<>();
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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);
}

Copy link
Author

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

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));

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));

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());

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();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make it class field

@sonyasapsan sonyasapsan requested a review from Andriy-dz October 6, 2023 14:46
private OperationStrategy operationStrategy;
private OperationHandler expected;

@BeforeEach

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

Comment on lines +25 to +43
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<>();
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make it static)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants