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 test for service #836

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

added test for service #836

wants to merge 7 commits into from

Conversation

DevIgork
Copy link

@DevIgork DevIgork commented Nov 5, 2023

No description provided.


@BeforeEach
public void beforeEach() {
fruitTransaction = new FruitTransactionParser();

Choose a reason for hiding this comment

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

Do we need to create a parser before each test?


@Test
public void produceMapReportService_ZeroQuantity_Ok() {
Map<String, Integer> map = new LinkedHashMap<>();

Choose a reason for hiding this comment

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

You always create a new map in every test, it will be better if you think about initialize it before all tests. Also, if you need to clear the data from the map, think about how you can achieve this.

@ponomvrenko
Copy link

Good job! But there are some points to consider.

Copy link

@mnyshenko mnyshenko left a comment

Choose a reason for hiding this comment

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

A few points to consider

@@ -119,4 +119,4 @@
</plugins>
</pluginManagement>
</build>
</project>
</project>

Choose a reason for hiding this comment

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

Please don't commit this change, it's redundant

Comment on lines 25 to 73
public void fruitTransactionParser_OkCase() {
expected = List.of(new FruitTransaction(Operation.BALANCE, "banana", 20),
new FruitTransaction(Operation.BALANCE, "apple", 100),
new FruitTransaction(Operation.SUPPLY, "banana", 100),
new FruitTransaction(Operation.PURCHASE, "banana", 13),
new FruitTransaction(Operation.RETURN, "apple", 10),
new FruitTransaction(Operation.PURCHASE, "apple", 20),
new FruitTransaction(Operation.PURCHASE, "banana", 5),
new FruitTransaction(Operation.SUPPLY, "banana", 50));
fileData = List.of("b,banana,20",
"b,apple,100",
"s,banana,100",
"p,banana,13",
"r,apple,10",
"p,apple,20",
"p,banana,5",
"s,banana,50");
List<FruitTransaction> actual = fruitTransaction.parse(fileData);
Assert.assertEquals(expected, actual);
}

@Test
public void fruitTransactionParser_EmptyInput_NotOk() {
fileData = List.of();
List<FruitTransaction> actual = fruitTransaction.parse(fileData);
assertTrue(actual.isEmpty());
}

@Test
public void fruitTransactionParser_MalformedInput_NotOk() {
fileData = List.of("b,banana,20", "invalid_line", "s,apple,30");
assertThrows(IllegalArgumentException.class, () -> fruitTransaction.parse(fileData));
}

@Test
public void fruitTransactionParser_CaseInsensitiveOperationCode_Ok() {
fileData = List.of("B,banana,20", "S,apple,30");
expected = List.of(new FruitTransaction(Operation.BALANCE, "banana", 20),
new FruitTransaction(Operation.SUPPLY, "apple", 30));
List<FruitTransaction> actual = fruitTransaction.parse(fileData);
Assert.assertEquals(expected, actual);
}

@Test
public void fruitTransactionParser_InvalidQuantity_NotOk() {
fileData = List.of("b,banana,-20", "s,apple,invalid");
assertThrows(IllegalArgumentException.class, () -> fruitTransaction.parse(fileData));
}
}

Choose a reason for hiding this comment

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

"p,banana,5",
"s,banana,50");
List<FruitTransaction> actual = fruitTransaction.parse(fileData);
Assert.assertEquals(expected, actual);

Choose a reason for hiding this comment

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

Let's import this method as you did with assertTrue, assetThrows and so on

import org.junit.jupiter.api.Test;

class FruitTransactionParserTest {
private static Parser fruitTransaction;

Choose a reason for hiding this comment

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

Should this field be named as a fruitTransaction? It seems to store a parser

Comment on lines 38 to 42
expected = VALID_DATA;
map.put("banana", 152);
map.put("apple", 90);
String actual = produceMapReportService.produceReport(map);
assertEquals(expected, actual);

Choose a reason for hiding this comment

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

you can delete this expected field and just pass VALID_DATA directly into your assert methods, please check other places for this point

}

@Test
public void produceMapReportService_ValidData_Ok() {

Choose a reason for hiding this comment

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

there is no need to include tested class name in each test name, please remove it everywhere

Copy link

@mnyshenko mnyshenko left a comment

Choose a reason for hiding this comment

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

Thanks for your changes, everything is good, but I noticed that you don't have any tests for handlers and dao. Please make tests for these classes

Copy link

@kshuryhin kshuryhin 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, but some improvements needed to be done

Comment on lines 27 to 32
@Test
void getStorage_ValidData_Ok() {
STORAGE.put("data1",1);
STORAGE.put("data2",2);
assertEquals(STORAGE,fruitDao.getStorage());
}

Choose a reason for hiding this comment

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

I would say this method is redundant. We are not testing here any logic

Copy link
Author

Choose a reason for hiding this comment

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

i know 😢

}

@Test
void add() {

Choose a reason for hiding this comment

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

Please, follow your previous naming conventions

Comment on lines 22 to 31
void validData_Ok() {
handler.handle(new FruitTransaction(Operation.BALANCE,"Banana",300));
assertEquals(300, STORAGE.get("Banana"));
}

@Test
void get_InValidData_NotOk() {
assertThrows(IllegalArgumentException.class,
() -> handler.handle(new FruitTransaction(Operation.BALANCE, "Banana", -100)));
}

Choose a reason for hiding this comment

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

Please, be consistent with your test method names. Make sure your method names are consistent among all tests (handlers in this case)

Copy link

@kshuryhin kshuryhin left a comment

Choose a reason for hiding this comment

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

LGTM

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