Skip to content

Выполнение задания - #97

Open
gamu wants to merge 2 commits into
Yandex-Practicum:devfrom
gamu:dev
Open

gamu wants to merge 2 commits into
Yandex-Practicum:devfrom
gamu:dev

Conversation

@gamu

@gamu gamu commented Jul 25, 2023

Copy link
Copy Markdown

No description provided.

Comment thread src/test/java/PersonstTest.java Outdated

public class PersonstTest {
@BeforeEach
public void initEnvironment() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Можно убрать

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Ага, забыл про нее. Я пытался общую инициализацию объектов для теста выделить, но в итоге по другому сделал.

@Override
public Double readDouble(String promt) {
try {
var scanner = new Scanner(System.in);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Лучшее переиспользовать инстанс Scanner, а не создавать каждый раз новый.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Вот проблема. Он видимо перехватывает стандартный ввод/вывод и после чтения ввода из сканера не отрабатывает стандартный System.out.

public int readInteger(String promt) {
var scanner = new Scanner(System.in);
System.out.println(promt);
return scanner.nextInt();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Если передать в этот момент произвольную строку программа завершит работу с исключением. Перед тем, как прочитать инт из сканнера, нужно сначала проверить возможно ли это при помощи соответствующего метода hasNextInt

return String.format("%s: %.2f %s", name, price, getCurencyString());
}
@Override
public boolean equals(Object o) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Не вижу чтобы они сравнивались, зачем тогда equals?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Вот это выражение в тесте assertThat(calculator.getGoods()).hasSameElementsAs(goods) не будет работать. Там через equals сравнение идет.

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.

2 participants