Refactor du test, mocker le film
All checks were successful
Gradle Test / test (push) Successful in 54s
All checks were successful
Gradle Test / test (push) Successful in 54s
This commit is contained in:
parent
c2ae3f8f2e
commit
9137e7e133
17 changed files with 14 additions and 17 deletions
|
|
@ -10,6 +10,8 @@ repositories {
|
||||||
dependencies {
|
dependencies {
|
||||||
testImplementation(platform('org.junit:junit-bom:5.10.0'))
|
testImplementation(platform('org.junit:junit-bom:5.10.0'))
|
||||||
testImplementation('org.junit.jupiter:junit-jupiter')
|
testImplementation('org.junit.jupiter:junit-jupiter')
|
||||||
|
testImplementation group: 'org.assertj', name: 'assertj-core', version: '3.24.2'
|
||||||
|
testImplementation "org.mockito:mockito-core:3.+"
|
||||||
}
|
}
|
||||||
|
|
||||||
test {
|
test {
|
||||||
|
|
|
||||||
BIN
lib/aopalliance-1.0.jar
Normal file
BIN
lib/aopalliance-1.0.jar
Normal file
Binary file not shown.
BIN
lib/apiguardian-api-1.1.2.jar
Normal file
BIN
lib/apiguardian-api-1.1.2.jar
Normal file
Binary file not shown.
BIN
lib/guava-19.0.jar
Normal file
BIN
lib/guava-19.0.jar
Normal file
Binary file not shown.
BIN
lib/guice-4.1.0-no_aop.jar
Normal file
BIN
lib/guice-4.1.0-no_aop.jar
Normal file
Binary file not shown.
BIN
lib/javax.inject-1.jar
Normal file
BIN
lib/javax.inject-1.jar
Normal file
Binary file not shown.
BIN
lib/jcommander-1.72.jar
Normal file
BIN
lib/jcommander-1.72.jar
Normal file
Binary file not shown.
BIN
lib/junit-jupiter-5.8.1.jar
Normal file
BIN
lib/junit-jupiter-5.8.1.jar
Normal file
Binary file not shown.
BIN
lib/junit-jupiter-api-5.8.1.jar
Normal file
BIN
lib/junit-jupiter-api-5.8.1.jar
Normal file
Binary file not shown.
BIN
lib/junit-jupiter-engine-5.8.1.jar
Normal file
BIN
lib/junit-jupiter-engine-5.8.1.jar
Normal file
Binary file not shown.
BIN
lib/junit-jupiter-params-5.8.1.jar
Normal file
BIN
lib/junit-jupiter-params-5.8.1.jar
Normal file
Binary file not shown.
BIN
lib/junit-platform-commons-1.8.1.jar
Normal file
BIN
lib/junit-platform-commons-1.8.1.jar
Normal file
Binary file not shown.
BIN
lib/junit-platform-engine-1.8.1.jar
Normal file
BIN
lib/junit-platform-engine-1.8.1.jar
Normal file
Binary file not shown.
BIN
lib/opentest4j-1.2.0.jar
Normal file
BIN
lib/opentest4j-1.2.0.jar
Normal file
Binary file not shown.
BIN
lib/snakeyaml-1.21.jar
Normal file
BIN
lib/snakeyaml-1.21.jar
Normal file
Binary file not shown.
BIN
lib/testng-7.1.0.jar
Normal file
BIN
lib/testng-7.1.0.jar
Normal file
Binary file not shown.
|
|
@ -2,7 +2,9 @@ package movierental;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
public class CustomerTest {
|
public class CustomerTest {
|
||||||
|
|
||||||
|
|
@ -10,29 +12,22 @@ public class CustomerTest {
|
||||||
public void test() {
|
public void test() {
|
||||||
// Given
|
// Given
|
||||||
Customer customer = new Customer("Bob");
|
Customer customer = new Customer("Bob");
|
||||||
customer.addRental(new Rental(new Movie("Jaws", Movie.REGULAR), 2));
|
Movie mockMovie = mock(Movie.class);
|
||||||
customer.addRental(new Rental(new Movie("Golden Eye", Movie.REGULAR), 3));
|
|
||||||
customer.addRental(new Rental(new Movie("Short New", Movie.NEW_RELEASE), 1));
|
when(mockMovie.getTitle()).thenReturn("Mock Movie");
|
||||||
customer.addRental(new Rental(new Movie("Long New", Movie.NEW_RELEASE), 2));
|
when(mockMovie.getPriceCode()).thenReturn(Movie.REGULAR);
|
||||||
customer.addRental(new Rental(new Movie("Bambi", Movie.CHILDRENS), 3));
|
customer.addRental(new Rental(mockMovie, 2));
|
||||||
customer.addRental(new Rental(new Movie("Toy Story", Movie.CHILDRENS), 4));
|
|
||||||
|
|
||||||
// When
|
// When
|
||||||
String statement = customer.statement();
|
String statement = customer.statement();
|
||||||
|
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
String expected = "" +
|
String expected = "" +
|
||||||
"Rental Record for Bob\n" +
|
"Rental Record for Bob\n" +
|
||||||
"\tJaws\t2.0\n" +
|
"\tMock Movie\t2.0\n" +
|
||||||
"\tGolden Eye\t3.5\n" +
|
"Amount owed is 2.0\n" +
|
||||||
"\tShort New\t3.0\n" +
|
"You earned 1 frequent renter points";
|
||||||
"\tLong New\t6.0\n" +
|
|
||||||
"\tBambi\t1.5\n" +
|
|
||||||
"\tToy Story\t3.0\n" +
|
|
||||||
"Amount owed is 19.0\n" +
|
|
||||||
"You earned 7 frequent renter points";
|
|
||||||
|
|
||||||
assertEquals(expected, statement);
|
assertThat(statement).isEqualTo(expected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Reference in a new issue