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

Tests for fruit shop impl #1058

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

Conversation

RomanChygryn
Copy link

No description provided.

Copy link

@liliia-ponomarenko liliia-ponomarenko 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! Let’s improve your solution;)

Comment on lines +29 to +48
private final FileReaderService fileReader;
private final DataConverterService dataConverter;
private final OperationStrategy operationStrategy;
private final ShopService shopService;
private final ReportGenerator reportGenerator;
private final FileWriterService fileWriter;

public Main(FileReaderService fileReader,
DataConverterService dataConverter,
OperationStrategy operationStrategy,
ShopService shopService,
ReportGenerator reportGenerator,
FileWriterService fileWriter) {
this.fileReader = fileReader;
this.dataConverter = dataConverter;
this.operationStrategy = operationStrategy;
this.shopService = shopService;
this.reportGenerator = reportGenerator;
this.fileWriter = fileWriter;
}
Copy link

Choose a reason for hiding this comment

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

Let's remove it. We don't need to create an instance of Main class, because we have static method main().
In general, it's the right way to declare dependencies and initialize it. You will do the same in book-store project, for example

Suggested change
private final FileReaderService fileReader;
private final DataConverterService dataConverter;
private final OperationStrategy operationStrategy;
private final ShopService shopService;
private final ReportGenerator reportGenerator;
private final FileWriterService fileWriter;
public Main(FileReaderService fileReader,
DataConverterService dataConverter,
OperationStrategy operationStrategy,
ShopService shopService,
ReportGenerator reportGenerator,
FileWriterService fileWriter) {
this.fileReader = fileReader;
this.dataConverter = dataConverter;
this.operationStrategy = operationStrategy;
this.shopService = shopService;
this.reportGenerator = reportGenerator;
this.fileWriter = fileWriter;
}
private final FileReaderService fileReader;
private final DataConverterService dataConverter;
private final OperationStrategy operationStrategy;
private final ShopService shopService;
private final ReportGenerator reportGenerator;
private final FileWriterService fileWriter;
public Main(FileReaderService fileReader,
DataConverterService dataConverter,
OperationStrategy operationStrategy,
ShopService shopService,
ReportGenerator reportGenerator,
FileWriterService fileWriter) {
this.fileReader = fileReader;
this.dataConverter = dataConverter;
this.operationStrategy = operationStrategy;
this.shopService = shopService;
this.reportGenerator = reportGenerator;
this.fileWriter = fileWriter;
}

Comment on lines +50 to +65
public void run(String inputFilePath, String outputFilePath) {
// 1. Read the data from the input CSV file
List<String> inputReport = fileReader.read(inputFilePath);

// 2. Convert the incoming data into FruitTransactions list
List<FruitTransaction> transactions = dataConverter.convertToTransaction(inputReport);

// 3. Process the incoming transactions with applicable OperationHandler implementations
shopService.process(transactions);

// 4. Generate report based on the current Storage state
String resultingReport = reportGenerator.create();

// 5. Write the received report into the destination file
fileWriter.writeToFile(outputFilePath, resultingReport);
}
Copy link

Choose a reason for hiding this comment

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

Let's just make it static and call in main() method

}

@Test
void testWriteToFile_shouldThrowRuntimeException_whenIoExceptionOccurs() throws IOException {
Copy link

Choose a reason for hiding this comment

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

You don't need this test, because you have already verified in your previous tests, that RuntimeException is thrown when an error occurs


@Override
public void doOperation(String fruitName, Integer quantity) {
storageDao.setQuantity(fruitName, quantity);
Copy link

Choose a reason for hiding this comment

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

What happens if the number is negative?)
Let's change it and add tests for it. See if other handlers need it too

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