Compare commits
No commits in common. "9137e7e13370f0e9ee4f0f27c90d13ac9483243f" and "56bdaee2a259c9239f8200fc5d61462bee0a0c37" have entirely different histories.
9137e7e133
...
56bdaee2a2
19 changed files with 17 additions and 22 deletions
|
|
@ -10,8 +10,6 @@ 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 {
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -48,9 +48,8 @@ public class Customer {
|
||||||
// add frequent renter points
|
// add frequent renter points
|
||||||
frequentRenterPoints++;
|
frequentRenterPoints++;
|
||||||
// add bonus for a two day new release rental
|
// 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++;
|
frequentRenterPoints++;
|
||||||
}
|
|
||||||
|
|
||||||
// show figures for this rental
|
// show figures for this rental
|
||||||
result += "\t" + each.getMovie().getTitle() + "\t" + String.valueOf(thisAmount) + "\n";
|
result += "\t" + each.getMovie().getTitle() + "\t" + String.valueOf(thisAmount) + "\n";
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@ public class Movie {
|
||||||
public void setPriceCode(int arg) {
|
public void setPriceCode(int arg) {
|
||||||
_priceCode = arg;
|
_priceCode = arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
return _title;
|
return _title;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,32 +2,31 @@ package movierental;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
|
|
||||||
public class CustomerTest {
|
public class CustomerTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() {
|
public void test() {
|
||||||
// Given
|
|
||||||
Customer customer = new Customer("Bob");
|
Customer customer = new Customer("Bob");
|
||||||
Movie mockMovie = mock(Movie.class);
|
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));
|
||||||
|
|
||||||
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 = "" +
|
String expected = "" +
|
||||||
"Rental Record for Bob\n" +
|
"Rental Record for Bob\n" +
|
||||||
"\tMock Movie\t2.0\n" +
|
"\tJaws\t2.0\n" +
|
||||||
"Amount owed is 2.0\n" +
|
"\tGolden Eye\t3.5\n" +
|
||||||
"You earned 1 frequent renter points";
|
"\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";
|
||||||
|
|
||||||
assertThat(statement).isEqualTo(expected);
|
assertEquals(expected, customer.statement());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Reference in a new issue