déportation des tests des méthodes startCar, stopCar et changeVitesse vers la classe CarTest
This commit is contained in:
parent
1f0e3fb296
commit
acee079799
4 changed files with 54 additions and 42 deletions
BIN
carApp/.DS_Store
vendored
BIN
carApp/.DS_Store
vendored
Binary file not shown.
BIN
carApp/src/.DS_Store
vendored
BIN
carApp/src/.DS_Store
vendored
Binary file not shown.
|
|
@ -1,42 +1,83 @@
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.PrintStream;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
public class CarTest {
|
public class CarTest {
|
||||||
|
|
||||||
private Car voiture;
|
private Car car;
|
||||||
|
private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
|
||||||
|
private final PrintStream originalOut = System.out;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
voiture = new Car("Sedan", "Bleu");
|
car = new Car("Sedan", "Bleu");
|
||||||
|
System.setOut(new PrintStream(outContent));
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
public void restoreStreams() {
|
||||||
|
System.setOut(originalOut);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAccelerate() {
|
public void testAccelerate() {
|
||||||
voiture.accelerate();
|
car.accelerate();
|
||||||
assertThat(voiture.getSpeed()).isEqualTo(10);
|
assertThat(car.getSpeed()).isEqualTo(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSlowDown() {
|
public void testSlowDown() {
|
||||||
voiture.accelerate();
|
car.accelerate();
|
||||||
voiture.slowDown();
|
car.slowDown();
|
||||||
assertThat(voiture.getSpeed()).isEqualTo(0);
|
assertThat(car.getSpeed()).isEqualTo(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAccelerateToMax() {
|
public void testAccelerateToMax() {
|
||||||
for (int i = 0; i < 12; i++) {
|
for (int i = 0; i < 12; i++) {
|
||||||
voiture.accelerate();
|
car.accelerate();
|
||||||
}
|
}
|
||||||
assertThat(voiture.getSpeed()).isEqualTo(120);
|
assertThat(car.getSpeed()).isEqualTo(120);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSlowDownToMin() {
|
public void testSlowDownToMin() {
|
||||||
voiture.accelerate();
|
car.accelerate();
|
||||||
voiture.slowDown();
|
car.slowDown();
|
||||||
voiture.slowDown();
|
car.slowDown();
|
||||||
assertThat(voiture.getSpeed()).isEqualTo(0);
|
assertThat(car.getSpeed()).isEqualTo(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStartCar() {
|
||||||
|
Driver driver = new Driver("John", 20);
|
||||||
|
car.startCar(driver);
|
||||||
|
assertThat(outContent.toString().trim()).isEqualTo("John démarre la voiture.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStopCar() {
|
||||||
|
Driver driver = new Driver("John", 20);
|
||||||
|
car.stopCar(driver);
|
||||||
|
assertThat(outContent.toString().trim()).isEqualTo("John arrête la voiture.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testChangeSpeed() {
|
||||||
|
Driver driver = new Driver("John", 20);
|
||||||
|
car.changeSpeed(driver, 80);
|
||||||
|
assertThat(car.getSpeed()).isEqualTo(80);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testChangeSpeedToSame() {
|
||||||
|
Driver driver = new Driver("John", 20);
|
||||||
|
car.changeSpeed(driver, 10);
|
||||||
|
assertThat(car.getSpeed()).isEqualTo(10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -26,33 +26,4 @@ public class DriverTest {
|
||||||
public void testIsAdult() {
|
public void testIsAdult() {
|
||||||
assertThat(driver.isAdult()).isTrue();
|
assertThat(driver.isAdult()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testStartCar() {
|
|
||||||
Car voiture = new Car("Sedan", "Bleu");
|
|
||||||
driver.startCar(voiture);
|
|
||||||
assertThat(outContent.toString().trim()).isEqualTo("John démarre la voiture.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testStopCar() {
|
|
||||||
Car voiture = new Car("Sedan", "Bleu");
|
|
||||||
driver.stopCar(voiture);
|
|
||||||
assertThat(outContent.toString().trim()).isEqualTo("John arrête la voiture.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testChangeSpeed() {
|
|
||||||
Car voiture = new Car("Sedan", "Bleu");
|
|
||||||
driver.changeSpeed(voiture, 80);
|
|
||||||
assertThat(voiture.getSpeed()).isEqualTo(80);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testChangeSpeedToSame() {
|
|
||||||
Car voiture = new Car("Sedan", "Bleu");
|
|
||||||
voiture.accelerate();
|
|
||||||
driver.changeSpeed(voiture, 10);
|
|
||||||
assertThat(voiture.getSpeed()).isEqualTo(10);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Loading…
Add table
Reference in a new issue