-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask_3.java
More file actions
38 lines (32 loc) · 1.22 KB
/
task_3.java
File metadata and controls
38 lines (32 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import static org.junit.Assert.assertEquals;
@RunWith(Parameterized.class)
public class CheckIsAdultTest {
private final int age;
private final boolean result;
// Инициализируем поля класса в конструкторе
public CheckIsAdultTest(int age, boolean result) {
this.age = age;
this.result = result;
}
// Помечаем метод аннотацией для параметров
@Parameterized.Parameters
public static Object[][] getTestData() {
return new Object[][] {
{ 17, false },
{ 18, true },
{ 19, true },
{ 16, false }
};
}
@Test
public void checkIsAdultWhenAgeThenResult() {
Program program = new Program();
// Передаем возраст пользователя
boolean isAdult = program.checkIsAdult(age);
// Сравниваем полученный и ожидаемый результат
assertEquals(String.format("Для возраста %d ожидается результат %b", age, result), result, isAdult);
}
}