package movierental;

import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.when;

public class CustomerTest {

    @Test
    public void testSingleRegularMovie() {
        // Given
        Customer customer = new Customer("Bob");
        Movie mockMovie = Mockito.mock(Movie.class);

        when(mockMovie.getTitle()).thenReturn("Mock Movie");
        when(mockMovie.getPriceCode()).thenReturn(Movie.REGULAR);
        when(mockMovie.calculatePrice(2)).thenReturn(2.0);
        customer.addRental(new Rental(mockMovie, 2));

        // When
        String statement = customer.statement();

        // Then
        String expected = "" +
                "Rental Record for Bob\n" +
                "\tMock Movie\t2.0\n" +
                "Amount owed is 2.0\n" +
                "You earned 1 frequent renter points";

        assertEquals(expected, statement);
    }

    @Test
    public void testSingleNewReleaseMovie() {
        // Given
        Customer customer = new Customer("Bob");
        Movie mockMovie = Mockito.mock(Movie.class);

        when(mockMovie.getTitle()).thenReturn("Mock Movie");
        when(mockMovie.getPriceCode()).thenReturn(Movie.NEW_RELEASE);
        when(mockMovie.calculatePrice(3)).thenReturn(9.0);
        customer.addRental(new Rental(mockMovie, 3));

        // When
        String statement = customer.statement();

        // Then
        String expected = "" +
                "Rental Record for Bob\n" +
                "\tMock Movie\t9.0\n" +
                "Amount owed is 9.0\n" +
                "You earned 2 frequent renter points";

        assertEquals(expected, statement);
    }

    @Test
    public void testSingleChildrenMovie() {
        // Given
        Customer customer = new Customer("Bob");
        Movie mockMovie = Mockito.mock(Movie.class);

        when(mockMovie.getTitle()).thenReturn("Mock Movie");
        when(mockMovie.getPriceCode()).thenReturn(Movie.CHILDRENS);
        when(mockMovie.calculatePrice(4)).thenReturn(3.0);
        customer.addRental(new Rental(mockMovie, 4));

        // When
        String statement = customer.statement();

        // Then
        String expected = "" +
                "Rental Record for Bob\n" +
                "\tMock Movie\t3.0\n" +
                "Amount owed is 3.0\n" +
                "You earned 1 frequent renter points";

        assertEquals(expected, statement);
    }
}