Skip to content
This repository was archived by the owner on Jun 2, 2026. It is now read-only.

создание тестов для конструктора#3

Open
lerklyu wants to merge 1 commit into
mainfrom
taskTest
Open

создание тестов для конструктора#3
lerklyu wants to merge 1 commit into
mainfrom
taskTest

Conversation

@lerklyu

@lerklyu lerklyu commented Feb 10, 2026

Copy link
Copy Markdown
Owner

No description provided.

@lerklyu lerklyu requested a review from kegisa February 10, 2026 14:41
private void checkConditions(String ownerName, String accountNumber, double balance, boolean isBlocked) {
if (ownerName == null || ownerName.isBlank()) {
throw new RuntimeException("Имя владельца не может быть пустым");
throw new NullPointerException("Имя владельца не может быть пустым");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

npe неприятная штука, давай везде illegallargument кидать


@DisplayName("Тесты конструктора BankAccount")
public class Main {
public static void main(String[] args) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

main должен отстаься без изменений, посмотри где пишут тесты

}
} No newline at end of file

@Test

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Все тесты нужны перенести в нужно место


BankAccount bankAccount = new BankAccount(ownerName, accountNumber, balance, isBlocked);

assertEquals("Алексеев", bankAccount.getOwnerName());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

у тебя уже есть перменная которая хранит в себе "Алексеев" ты можншь испоьзовать ее, как и везде где так, тоже исправь


BankAccount bankAccount = new BankAccount(ownerName, accountNumber, balance, isBlocked);

assertEquals(0, bankAccount.getBalance(), 0);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

почему тут 3 параметра?

@Test
@DisplayName("Создаёт объект с пустой строкой номера счёта")
public void createBankAccountWitchAccountNumberIsBlank() {
assertThrows(NullPointerException.class,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

А почему тут не проверили что за сообщение будет?


@Test
@DisplayName("Создаёт объект с пустой строкой номера счёта и проверяет текст ошибки")
public void createBankAccountWitchAccountNumberIsBlankAndExceptionMessage() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Не понял чем отличается от прошлого теста?


@Test
@DisplayName("Имя владельца сохраняется точно как передано")
public void shouldPreserveNameExactlyAsPassed() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Для чего этот тест? Не хватает проверки просто успешного кейса, что имя равняется тому что мы задали

12323.00,
false);

assertNotNull(bankAccount);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Тоже не понял зачем этот тест, когда мы создаем объект в успешном тесте, мы потом дергает поля из объекта, и если бы объект был null, то мы получили бы там npe и тест упал


assertEquals(" Капутов ", bankAccount.getOwnerName());
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

А где тесты на другие конструкторы?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants