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

created tests for FruitShop #785

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

Conversation

validatorr
Copy link

No description provided.

Copy link

@pavlov-n pavlov-n left a comment

Choose a reason for hiding this comment

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

Good job. Global comment: names for test.methods + i'm not sure about initialisation in beforeAll, but if you think it's correct, leave it for mentors

Comment on lines 49 to 56
String expected = "fruit,quantity\n"
+ "banana,152\r\n"
+ "apple,90\r\n";
List<String> inputData = new ReadServiceImpl().readInputData(INPUT_PATH);
List<FruitTransaction> parseData = new ParseServiceImpl().parseInputData(inputData);
operationService = new OperationService(operationStrategy);
operationService.processOperation(parseData);
String actual = new ReportServiceImpl().createReport();

Choose a reason for hiding this comment

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

Comment on lines 30 to 37
emptyList = new ArrayList<>();
inputData = new ArrayList<>(Arrays.asList(
"type,fruit,quantity",
"b,banana,100",
"s,banana,100",
"p,banana,100",
"r,banana,100"));
parseData = parseService.parseInputData(inputData);

Choose a reason for hiding this comment

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

I think you need to use it in test methods.

import java.util.Map;

public class ReportServiceImpl implements ReportService {
private static final String FIRST_ROW = "fruit,quantity\n";

Choose a reason for hiding this comment

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

use System.lineSeparator(), not \n.

Comment on lines 25 to 27
String expected = FIRST_ROW
+ "banana,20\r\n"
+ "apple,15\r\n";

Choose a reason for hiding this comment

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

use System.lineSeparator()

Copy link

@Andriy-dz Andriy-dz left a comment

Choose a reason for hiding this comment

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

Good Job! Lets improve your solution)

+ System.lineSeparator();
List<String> inputData = new ReadServiceImpl().readInputData(INPUT_PATH);
List<FruitTransaction> parseData = new ParseServiceImpl().parseInputData(inputData);
operationService = new OperationService(operationStrategy);

Choose a reason for hiding this comment

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

u must initializate it in BeforeAll method

List<FruitTransaction> parseData = new ParseServiceImpl().parseInputData(inputData);
operationService = new OperationService(operationStrategy);
operationService.processOperation(parseData);
String actual = new ReportServiceImpl().createReport();

Choose a reason for hiding this comment

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

u must test here only operationService. Dont use another services

Comment on lines 16 to 25
private static final int BALANCE_INDEX = 0;
private static final int SUPPLY_INDEX = 1;
private static final int PURCHASE_INDEX = 2;
private static final int RETURN_INDEX = 3;
private static final String FRUIT = "banana";
private static final int QUANTITY = 100;
private static ParseService parseService;
private static List<String> inputData;
private static List<String> emptyList;
private static List<FruitTransaction> parseData;

Choose a reason for hiding this comment

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

Suggested change
private static final int BALANCE_INDEX = 0;
private static final int SUPPLY_INDEX = 1;
private static final int PURCHASE_INDEX = 2;
private static final int RETURN_INDEX = 3;
private static final String FRUIT = "banana";
private static final int QUANTITY = 100;
private static ParseService parseService;
private static List<String> inputData;
private static List<String> emptyList;
private static List<FruitTransaction> parseData;
private static ParseService parseService;

you don't really need these variables. Create them and use them in the test methods you need. Likewise in other test classes

}

@Test
void correctParseData_Ok() {

Choose a reason for hiding this comment

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

which method is being tested here - not an informative method name. The same in other tests

"p,banana,100",
"r,banana,100"));
parseData = parseService.parseInputData(inputData);
FruitTransaction balanceTransaction = parseData.get(BALANCE_INDEX);

Choose a reason for hiding this comment

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

here you can create a list that you expect to return as a result of executing the method and compare

Comment on lines 25 to 29
String expected = FIRST_ROW
+ "banana,20"
+ System.lineSeparator()
+ "apple,15"
+ System.lineSeparator();

Choose a reason for hiding this comment

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

lets use StrringBuilder

class WriteServiceImplTest {
private static final String OUTPUT_PATH = "src/main/java/resources/output.csv";
private static final String REPORT = "fruit,quantity\n"
+ "banana,152\r\n"

Choose a reason for hiding this comment

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

why not System.lineSeparator()?


@Test
void writeReport_Ok() {
String actual = writerService.writeToFile(OUTPUT_PATH, REPORT);

Choose a reason for hiding this comment

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

here it is better to read the result from the corresponding file and compare the data


@Test
void getSuppleHandler_Ok() {
operationHandler = new SupplyOperationHandler();

Choose a reason for hiding this comment

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

lets initializate it in BeforeAll method

import org.junit.jupiter.api.Test;

class ReportServiceImplTest {
//private static final String FIRST_ROW = "fruit,quantity" + System.lineSeparator();

Choose a reason for hiding this comment

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

Don't forget to remove commented code

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.

4 participants