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

0단계 - JUnit 5 학습 #851

Open
wants to merge 3 commits into
base: sunggyun-jo
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
30 changes: 30 additions & 0 deletions src/test/java/racingcar/Car.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package racingcar;

import java.util.Random;

public class Car {

private String carName;

public Car(String carName) {
if (carName == null) {
return;
}

if (carName.length() > 5) {
throw new IllegalArgumentException();
}

this.carName = carName;
}

public boolean movable(int num) {
return num >= 4;
}

public boolean movable() {
Random random = new Random();
var num = random.nextInt(10);
return movable(num);
}
}
26 changes: 26 additions & 0 deletions src/test/java/racingcar/CarTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package racingcar;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

public class CarTest {

@Test
@DisplayName("자동차 이름은 5글자를 넘을 수 없다.")
void throwsExceptionWhenCreateCar() {
assertThatThrownBy(() -> {
Car car = new Car("가나다라마바");
}).isInstanceOf(IllegalArgumentException.class);
}

@Test
@DisplayName("자동차는 무작위 값이 4이상인 경우 움직인다.")
void moving() {
Car car = new Car("가나다라마");
assertThat(car.movable(4)).isTrue();
assertThat(car.movable(3)).isFalse();
}
}