-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathLottoTest.java
More file actions
57 lines (47 loc) · 1.55 KB
/
LottoTest.java
File metadata and controls
57 lines (47 loc) · 1.55 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package lotto;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import java.util.List;
import java.util.stream.Stream;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
public class LottoTest {
@DisplayName("로또를 생성한다")
@Test
void createLotto() {
Lotto lotto = new Lotto(1, 2, 3, 4, 5, 6);
assertThat(lotto).isNotNull();
}
@Test
void createLottoFromString() {
assertThat(new Lotto("1,2,3,4,5,6")).isEqualTo(new Lotto(1, 2, 3, 4, 5, 6));
}
@DisplayName("로또 번호는 6개여야 한다")
@ParameterizedTest
@MethodSource("invalidLottoSizes")
void validLottoSize(List<Integer> numbers) {
assertThatIllegalArgumentException()
.isThrownBy(() -> Lotto.fromIntegers(numbers))
.withMessageContaining("6개");
}
@DisplayName("로또 번호는 정렬된다")
@Test
void sortLottoNumbers() {
assertThat(new Lotto("1,2,3,4,8,5")).isEqualTo(new Lotto("1,2,3,4,5,8"));
}
@DisplayName("로또 번호는 중복 시 예외가 발생한다")
@Test
void duplicateLottoNumbers() {
assertThatIllegalArgumentException().isThrownBy(() -> new Lotto("1,2,3,4,8,8"))
.withMessageContaining("중복");
}
static Stream<List<Integer>> invalidLottoSizes() {
return Stream.of(
List.of(),
List.of(1, 2, 3, 4, 5),
List.of(1, 2, 3, 4, 5, 6, 7)
);
}
}