|
|
|
|
|
|
|
|
|
|
|
import org.junit.Before; |
|
|
|
|
|
import org.junit.Test; |
|
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.*; |
|
|
|
|
|
|
|
|
|
|
|
public class CustomerTest { |
|
|
|
|
|
|
|
|
|
|
|
Customer customer; |
|
|
|
|
|
|
|
|
|
|
|
@Before |
|
|
|
|
|
public void setUp() throws Exception { |
|
|
|
|
|
customer = new Customer("customer A"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
public void test_statement_no_rentals() { |
|
|
|
|
|
String expected_text = "Rental Record for customer A\n" + |
|
|
|
|
|
"Amount owed is 0.0\n" + |
|
|
|
|
|
"You earned 0 frequent renter points"; |
|
|
|
|
|
String invoice_text = customer.statement(); |
|
|
|
|
|
assertEquals(expected_text, invoice_text); |
|
|
|
|
|
|
|
|
|
|
|
System.out.println("test_statement_no_rentals"); |
|
|
|
|
|
System.out.println(invoice_text); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
public void test_statement_one_regular_two_days() { |
|
|
|
|
|
String expected_text = "Rental Record for customer A\n" + |
|
|
|
|
|
"\tregular_movie\t days rented: 2 = 2.0\n" + |
|
|
|
|
|
"Amount owed is 2.0\n" + |
|
|
|
|
|
"You earned 1 frequent renter points"; |
|
|
|
|
|
Movie regular_movie = new Movie ("regular_movie", Movie.REGULAR ); |
|
|
|
|
|
Rental rental = new Rental(regular_movie, 2); |
|
|
|
|
|
customer.addRental(rental); |
|
|
|
|
|
|
|
|
|
|
|
String invoice_text = customer.statement(); |
|
|
|
|
|
assertEquals(expected_text, invoice_text); |
|
|
|
|
|
|
|
|
|
|
|
System.out.println("test_statement_no_rentals"); |
|
|
|
|
|
System.out.println(invoice_text); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
public void test_statement_one_regular_three_days() { |
|
|
|
|
|
String expected_text = "Rental Record for customer A\n" + |
|
|
|
|
|
"\tregular_movie\t days rented: 3 = 3.5\n" + |
|
|
|
|
|
"Amount owed is 3.5\n" + |
|
|
|
|
|
"You earned 1 frequent renter points"; |
|
|
|
|
|
Movie regular_movie = new Movie ("regular_movie", Movie.REGULAR ); |
|
|
|
|
|
Rental rental = new Rental(regular_movie, 3); |
|
|
|
|
|
customer.addRental(rental); |
|
|
|
|
|
|
|
|
|
|
|
String invoice_text = customer.statement(); |
|
|
|
|
|
assertEquals(expected_text, invoice_text); |
|
|
|
|
|
|
|
|
|
|
|
System.out.println("test_statement_no_rentals"); |
|
|
|
|
|
System.out.println(invoice_text); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
public void test_statement_one_childrens_two_days() { |
|
|
|
|
|
String expected_text = "Rental Record for customer A\n" + |
|
|
|
|
|
"\tchildrens_movie\t days rented: 2 = 1.5\n" + |
|
|
|
|
|
"Amount owed is 1.5\n" + |
|
|
|
|
|
"You earned 1 frequent renter points"; |
|
|
|
|
|
Movie childrens_movie = new Movie ("childrens_movie", Movie.CHILDRENS ); |
|
|
|
|
|
Rental rental = new Rental(childrens_movie, 2); |
|
|
|
|
|
customer.addRental(rental); |
|
|
|
|
|
|
|
|
|
|
|
String invoice_text = customer.statement(); |
|
|
|
|
|
assertEquals(expected_text, invoice_text); |
|
|
|
|
|
|
|
|
|
|
|
System.out.println("test_statement_no_rentals"); |
|
|
|
|
|
System.out.println(invoice_text); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
public void test_statement_one_new_release_two_days() { |
|
|
|
|
|
String expected_text = "Rental Record for customer A\n" + |
|
|
|
|
|
"\tnew_release_movie\t days rented: 2 = 6.0\n" + |
|
|
|
|
|
"Amount owed is 6.0\n" + |
|
|
|
|
|
"You earned 2 frequent renter points"; |
|
|
|
|
|
Movie new_release_movie = new Movie ("new_release_movie", Movie.NEW_RELEASE ); |
|
|
|
|
|
Rental rental = new Rental(new_release_movie, 2); |
|
|
|
|
|
customer.addRental(rental); |
|
|
|
|
|
|
|
|
|
|
|
String invoice_text = customer.statement(); |
|
|
|
|
|
assertEquals(expected_text, invoice_text); |
|
|
|
|
|
|
|
|
|
|
|
System.out.println("test_statement_no_rentals"); |
|
|
|
|
|
System.out.println(invoice_text); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
public void test_statement_with_all_kinds_of_movies_one_and_four_days() { |
|
|
|
|
|
String expected_text = "Rental Record for customer A\n" + |
|
|
|
|
|
"\tregular_movie_1\t days rented: 1 = 2.0\n" + |
|
|
|
|
|
"\tregular_movie_2\t days rented: 4 = 5.0\n" + |
|
|
|
|
|
"\tchildrens_movie_1\t days rented: 1 = 1.5\n" + |
|
|
|
|
|
"\tchildrens_movie_2\t days rented: 4 = 3.0\n" + |
|
|
|
|
|
"\tnew_release_movie_1\t days rented: 1 = 3.0\n" + |
|
|
|
|
|
"\tnew_release_movie_2\t days rented: 4 = 12.0\n" + |
|
|
|
|
|
"Amount owed is 26.5\n" + |
|
|
|
|
|
"You earned 7 frequent renter points"; |
|
|
|
|
|
|
|
|
|
|
|
Movie regular_movie_1 = new Movie ("regular_movie_1", Movie.REGULAR ); |
|
|
|
|
|
Rental rental_1 = new Rental(regular_movie_1, 1); |
|
|
|
|
|
customer.addRental(rental_1); |
|
|
|
|
|
|
|
|
|
|
|
Movie regular_movie_2 = new Movie ("regular_movie_2", Movie.REGULAR ); |
|
|
|
|
|
Rental rental_2 = new Rental(regular_movie_2, 4); |
|
|
|
|
|
customer.addRental(rental_2); |
|
|
|
|
|
|
|
|
|
|
|
Movie childrens_movie_1 = new Movie ("childrens_movie_1", Movie.CHILDRENS ); |
|
|
|
|
|
Rental rental_3 = new Rental(childrens_movie_1, 1); |
|
|
|
|
|
customer.addRental(rental_3); |
|
|
|
|
|
|
|
|
|
|
|
Movie childrens_movie_2 = new Movie ("childrens_movie_2", Movie.CHILDRENS ); |
|
|
|
|
|
Rental rental_4 = new Rental(childrens_movie_2, 4); |
|
|
|
|
|
customer.addRental(rental_4); |
|
|
|
|
|
|
|
|
|
|
|
Movie new_release_movie_1 = new Movie ("new_release_movie_1", Movie.NEW_RELEASE ); |
|
|
|
|
|
Rental rental_5 = new Rental(new_release_movie_1, 1); |
|
|
|
|
|
customer.addRental(rental_5); |
|
|
|
|
|
|
|
|
|
|
|
Movie new_release_movie_2 = new Movie ("new_release_movie_2", Movie.NEW_RELEASE ); |
|
|
|
|
|
Rental rental_6 = new Rental(new_release_movie_2, 4); |
|
|
|
|
|
customer.addRental(rental_6); |
|
|
|
|
|
|
|
|
|
|
|
String invoice_text = customer.statement(); |
|
|
|
|
|
assertEquals(expected_text, invoice_text); |
|
|
|
|
|
|
|
|
|
|
|
System.out.println("test_statement_no_rentals"); |
|
|
|
|
|
System.out.println(invoice_text); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
} |