Compare commits

..

2 commits

Author SHA1 Message Date
9137e7e133 Refactor du test, mocker le film
All checks were successful
Gradle Test / test (push) Successful in 54s
2025-02-04 10:51:36 +01:00
c2ae3f8f2e Changements de style de code 2025-02-04 10:35:05 +01:00
19 changed files with 22 additions and 17 deletions

View file

@ -10,6 +10,8 @@ repositories {
dependencies {
testImplementation(platform('org.junit:junit-bom:5.10.0'))
testImplementation('org.junit.jupiter:junit-jupiter')
testImplementation group: 'org.assertj', name: 'assertj-core', version: '3.24.2'
testImplementation "org.mockito:mockito-core:3.+"
}
test {

BIN
lib/aopalliance-1.0.jar Normal file

Binary file not shown.

Binary file not shown.

BIN
lib/guava-19.0.jar Normal file

Binary file not shown.

BIN
lib/guice-4.1.0-no_aop.jar Normal file

Binary file not shown.

BIN
lib/javax.inject-1.jar Normal file

Binary file not shown.

BIN
lib/jcommander-1.72.jar Normal file

Binary file not shown.

BIN
lib/junit-jupiter-5.8.1.jar Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
lib/opentest4j-1.2.0.jar Normal file

Binary file not shown.

BIN
lib/snakeyaml-1.21.jar Normal file

Binary file not shown.

BIN
lib/testng-7.1.0.jar Normal file

Binary file not shown.

View file

@ -48,8 +48,9 @@ public class Customer {
// add frequent renter points
frequentRenterPoints++;
// add bonus for a two day new release rental
if ((each.getMovie().getPriceCode() == Movie.NEW_RELEASE) && each.getDaysRented() > 1)
if ((each.getMovie().getPriceCode() == Movie.NEW_RELEASE) && each.getDaysRented() > 1) {
frequentRenterPoints++;
}
// show figures for this rental
result += "\t" + each.getMovie().getTitle() + "\t" + String.valueOf(thisAmount) + "\n";

View file

@ -21,6 +21,7 @@ public class Movie {
public void setPriceCode(int arg) {
_priceCode = arg;
}
public String getTitle() {
return _title;
}

View file

@ -2,31 +2,32 @@ package movierental;
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 {
@Test
public void test() {
// Given
Customer customer = new Customer("Bob");
customer.addRental(new Rental(new Movie("Jaws", Movie.REGULAR), 2));
customer.addRental(new Rental(new Movie("Golden Eye", Movie.REGULAR), 3));
customer.addRental(new Rental(new Movie("Short New", Movie.NEW_RELEASE), 1));
customer.addRental(new Rental(new Movie("Long New", Movie.NEW_RELEASE), 2));
customer.addRental(new Rental(new Movie("Bambi", Movie.CHILDRENS), 3));
customer.addRental(new Rental(new Movie("Toy Story", Movie.CHILDRENS), 4));
Movie mockMovie = mock(Movie.class);
when(mockMovie.getTitle()).thenReturn("Mock Movie");
when(mockMovie.getPriceCode()).thenReturn(Movie.REGULAR);
customer.addRental(new Rental(mockMovie, 2));
// When
String statement = customer.statement();
// Then
String expected = "" +
"Rental Record for Bob\n" +
"\tJaws\t2.0\n" +
"\tGolden Eye\t3.5\n" +
"\tShort New\t3.0\n" +
"\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";
"\tMock Movie\t2.0\n" +
"Amount owed is 2.0\n" +
"You earned 1 frequent renter points";
assertEquals(expected, customer.statement());
assertThat(statement).isEqualTo(expected);
}
}