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

Added solution #820

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

Added solution #820

wants to merge 2 commits into from

Conversation

slaybrute
Copy link

No description provided.

Copy link

@okuzan okuzan left a comment

Choose a reason for hiding this comment

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

unify all test method names
they should end notOk
user lowercase after underscore. By underscore we separate not words, but logical components of the name -
_

}

@Test
@Order(1)
Copy link

Choose a reason for hiding this comment

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

it's generally better to write independent and isolated test methods whenever possible, as test method order dependencies can make your test suite more brittle and harder to maintain

Comment on lines 49 to 62
URL resources = classLoader.getResource(INPUT_1_FILE_NAME);
List<String> readFromFile = fileReader.readFromFile(new File(resources.getFile()));
List<FruitTransaction> fruitTransactions = parseService.parse(readFromFile);
for (FruitTransaction fruitTransaction : fruitTransactions) {
operationStrategy.get(fruitTransaction.getOperation())
.handle(fruitTransaction.getFruit(),
fruitTransaction.getQuantity());
}
String actual = reportService.generateReport();
String expected = HEADER + System.lineSeparator()
+ "apple" + SEPARATOR + 90 + System.lineSeparator()
+ "banana" + SEPARATOR + 152 + System.lineSeparator()
+ "pear" + SEPARATOR + 140;
assertEquals(expected, actual);
Copy link

Choose a reason for hiding this comment

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

a lot of duplicated logic, extract to a private method like this

private void performTest(String fileName, String expectedReport) {
    URL resources = classLoader.getResource(fileName);
    List<String> readFromFile = fileReader.readFromFile(new File(resources.getFile()));
    List<FruitTransaction> fruitTransactions = parseService.parse(readFromFile);
    for (FruitTransaction fruitTransaction : fruitTransactions) {
        operationStrategy.get(fruitTransaction.getOperation())
            .handle(fruitTransaction.getFruit(),
            fruitTransaction.getQuantity());
    }
    String actual = reportService.generateReport();
    assertEquals(expectedReport, actual);
}

Comment on lines +69 to +79
List<FruitTransaction> expected = new ArrayList<>(List.of(
new FruitTransaction("pear", 200, FruitTransaction.Operation.BALANCE),
new FruitTransaction("apple", 150, FruitTransaction.Operation.BALANCE),
new FruitTransaction("banana", 100, FruitTransaction.Operation.BALANCE),
new FruitTransaction("pear", 80, FruitTransaction.Operation.PURCHASE),
new FruitTransaction("banana", 25, FruitTransaction.Operation.SUPPLY),
new FruitTransaction("apple", 10, FruitTransaction.Operation.RETURN),
new FruitTransaction("pear", 20, FruitTransaction.Operation.RETURN),
new FruitTransaction("banana", 5, FruitTransaction.Operation.PURCHASE),
new FruitTransaction("banana", 15, FruitTransaction.Operation.SUPPLY),
new FruitTransaction("banana", 20, FruitTransaction.Operation.PURCHASE)));
Copy link

Choose a reason for hiding this comment

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

move this out of the method, it's hard to read

Comment on lines 41 to 50
URL resources = classLoader.getResource(INPUT_1_FILE_NAME);
List<String> readFromFile = fileReader.readFromFile(new File(resources.getFile()));
List<FruitTransaction> fruitTransactions = parseService.parse(readFromFile);
for (FruitTransaction fruitTransaction : fruitTransactions) {
operationStrategy.get(fruitTransaction.getOperation())
.handle(fruitTransaction.getFruit(),
fruitTransaction.getQuantity());
}
assertEquals(FruitDaoImpl.getFruits().get("banana"), 152);
assertEquals(FruitDaoImpl.getFruits().get("apple"), 90);
Copy link

Choose a reason for hiding this comment

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

same, your method look very similar, avoid code duplication

@slaybrute slaybrute requested a review from okuzan October 27, 2023 19:28
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.

3 participants