-
Notifications
You must be signed in to change notification settings - Fork 1k
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
base: main
Are you sure you want to change the base?
Tests #789
Conversation
There was a problem hiding this 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(); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
answered above
There was a problem hiding this 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
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"; |
There was a problem hiding this comment.
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(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redundant blank line
@AfterEach | ||
public void tearDown() { | ||
Storage.storage.clear(); |
There was a problem hiding this comment.
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
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"; |
There was a problem hiding this comment.
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
Storage.storage.put(PINEAPPLE, 10); | ||
Storage.storage.put(BANANA, 20); | ||
Storage.storage.put(ORANGE, 30); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
@AfterEach | ||
public void tearDown() { | ||
Storage.storage.clear(); | ||
} |
There was a problem hiding this comment.
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
private static final String VALID_FRUIT_NAME = "dragonFruit"; | ||
private static final int INITIAL_BALANCE = 10; |
There was a problem hiding this comment.
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
@AfterEach | ||
public void tearDown() { | ||
Storage.storage.clear(); | ||
} |
There was a problem hiding this comment.
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 { | ||
|
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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?
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); |
There was a problem hiding this comment.
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 { | ||
|
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
No description provided.