Skip to content
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

1단계 피드백 추가 반영 #5256

Open
wants to merge 9 commits into
base: dongock
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/test/java/study/SetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,17 @@ void contains(int input) {
assertThat(numbers.contains(input)).isTrue();
}

@DisplayName("JUnit CsvSource를 이용한 Test")
@DisplayName("JUnit CsvSource를 이용한 Contain(true) Test")
@ParameterizedTest
@CsvSource(value = {"1:true", "2:true", "3:true", "4:false", "5:false"}, delimiter = ':')
void csvSource(int input, boolean expected) {
@CsvSource(value = {"1:true", "2:true", "3:true"}, delimiter = ':')
void csvSource1(int input, boolean expected) {
assertThat(numbers.contains(input)).isEqualTo(expected);
}

@DisplayName("JUnit CsvSource를 이용한 Contain(false) Test")
@ParameterizedTest
@CsvSource(value = {"4:false", "5:false"}, delimiter = ':')
void csvSource2(int input, boolean expected) {
assertThat(numbers.contains(input)).isEqualTo(expected);
}
}
29 changes: 23 additions & 6 deletions src/test/java/study/StringTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;

import java.util.stream.Stream;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
Expand All @@ -28,19 +35,29 @@ void subString() {
assertThat(substring).isEqualTo("1,2");
}

@Test
@ParameterizedTest
@DisplayName("String의 charAt() 메소드를 활용해 특정 위치의 문자를 가져오는 Test")
void charAt1() {
char charAt = "abc".charAt(0);
assertThat(charAt).isEqualTo("a");
@MethodSource("stringAndIndex")
void charAt1(String input, int index) {
char charAt = "abc".charAt(index);
assertThat(charAt).isEqualTo(input);
}

public static Stream<Arguments> stringAndIndex() {
return Stream.of(
Arguments.of("a", 0),
Arguments.of("b", 1),
Arguments.of("c", 2)
);
}

@Test
@DisplayName("String의 charAt() 메소드를 활용해 특정 위치의 문자를 가져올 때 위치 값 벗어났을 때 Exception Test")
void charAt2() {
int charLength = "abc".length();
assertThrows(IndexOutOfBoundsException.class, () -> {
assertThatThrownBy(() -> {
"abc".charAt(charLength+1);
});
}).isInstanceOf(IndexOutOfBoundsException.class)
.hasMessageContaining("out of range");
}
}