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 #789

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

Tests #789

wants to merge 7 commits into from

Conversation

SalnikovMarkiian
Copy link

No description provided.

Copy link

@Cayman4010 Cayman4010 left a comment

Choose a reason for hiding this comment

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

Oh, fantastic job! I didn`t think that we have to create so many tests... I am tired after reading this like after my work :)


@AfterEach
public void tearDown() {
Storage.storage.clear();

Choose a reason for hiding this comment

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

I think double storage.clear is redundant (initStorage and tearDown), but I`m not sure.

import org.junit.jupiter.api.Test;

public class ReportServiceImplTest {
private static final String LINE_SEPARATOR = System.lineSeparator();

Choose a reason for hiding this comment

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

It may be a redundant constant. Andrew told me about it in previous task.

Copy link
Author

Choose a reason for hiding this comment

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

i use LINE_SEPARATOR for resolve DRY problem, the constant helps not to repeat

Choose a reason for hiding this comment

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

DRY is not the case here - you don't have to use any constants to avoid DRY violation in your tests

read carefully what is DRY principle - multiple calls to System.lineSeparator() don't violate it

public class WriteServiceImplTest {
private static final String PATH_TO_FILE = "src/test/java/resources/report.csv";
private static final String INVALID_PATH = "invalid/path/to/file";
private static final String LINE_SEPARATOR = System.lineSeparator();

Choose a reason for hiding this comment

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

same

Copy link
Author

Choose a reason for hiding this comment

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

I still do not understand why constants do not have a good tone here

Choose a reason for hiding this comment

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

answered above

Copy link

@NazarSmith228 NazarSmith228 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 24 to 27
private static final String PINEAPPLE = "pineapple";
private static final String BANANA = "banana";
private static final String ORANGE = "orange";
private static final String DRAGON_FRUIT = "dragonFruit";

Choose a reason for hiding this comment

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

constants are bad for tests - pls avoid them

public void setUp() {
initFruitShopService();
initStorage();

Choose a reason for hiding this comment

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

redundant blank line

Comment on lines 54 to 56
@AfterEach
public void tearDown() {
Storage.storage.clear();

Choose a reason for hiding this comment

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

you can remove this hook, since you do the cleanup in @BeforeEach

Comment on lines 15 to 17
private static final String HEAD_FILE = "operation,fruit,quantity";
private static final String INVALID_BALANCE_STRING = "b,apple,5A";
private static final String VALID_SUPPLY_ORANGE = "s,orange,5";

Choose a reason for hiding this comment

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

constants are bad for tests - pls avoid them

Comment on lines 49 to 51
Storage.storage.put(PINEAPPLE, 10);
Storage.storage.put(BANANA, 20);
Storage.storage.put(ORANGE, 30);

Choose a reason for hiding this comment

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

it is not the best option to add some random data before every test since it complicates the reading process

for instance in one of your tests you have a FruitTransaction(Operation.PURCHASE, PINEAPPLE, 5), and then you do some assertion over pineapples. it's hard for me to understand the final value, since I always need to get back to @BeforeEach and check what exactly you stored before the test


@Test
public void writeToFile_Ok() throws IOException {
String expectedReport = "fruit,quantity" + LINE_SEPARATOR

Choose a reason for hiding this comment

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

can we use multi-line string here?


@Test
public void writeToFile_InvalidPath_notOk() {
String report = "fruit,quantity" + LINE_SEPARATOR

Choose a reason for hiding this comment

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

you can avoid real import here and pass some dummy string, since you expect exception at the end

Comment on lines 22 to 25
@AfterEach
public void tearDown() {
Storage.storage.clear();
}

Choose a reason for hiding this comment

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

you can compose this in @BeforeEach

Comment on lines 15 to 16
private static final String VALID_FRUIT_NAME = "dragonFruit";
private static final int INITIAL_BALANCE = 10;

Choose a reason for hiding this comment

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

constants are bad for tests - pls avoid them

Comment on lines 24 to 27
@AfterEach
public void tearDown() {
Storage.storage.clear();
}

Choose a reason for hiding this comment

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

you can compose this in @BeforeEach

import org.junit.jupiter.api.Test;

public class ParseServiceImplTest {

Choose a reason for hiding this comment

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

remove empty line

}

@Test
public void test_ParseWithEmptyInput() {

Choose a reason for hiding this comment

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

is it ok case or notOk?

Comment on lines 27 to 29
List<String> expected = Files.readAllLines(Path.of(VALID_PATH_TO_VALID_FILE));
List<String> actual = readService.readFromFile(VALID_PATH_TO_VALID_FILE);
assertEquals(expected, actual);

Choose a reason for hiding this comment

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

agree

import org.junit.jupiter.api.Test;

public class ReportServiceImplTest {

Choose a reason for hiding this comment

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

remove empty line

purchaseHandler = new PurchaseHandler();
}

@AfterEach

Choose a reason for hiding this comment

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

Try to be consistent: in some test classes you clear the Storage by using AfterEach annotation, in some classes by using BeforeEach annotation

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