Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
robertdijk authored and JoepdeJong committed Sep 24, 2024
1 parent 21e56e8 commit 3eee600
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@
import ch.wisv.events.core.service.event.EventService;
import ch.wisv.events.core.service.order.OrderValidationService;
import ch.wisv.events.core.service.order.OrderValidationServiceImpl;
import ch.wisv.events.core.service.product.ProductService;
import ch.wisv.events.core.service.ticket.TicketService;
import ch.wisv.events.core.util.VatRate;
import com.google.common.collect.ImmutableList;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -43,6 +46,10 @@ public class OrderValidationServiceImplTest extends ServiceTest {
@Mock
private TicketService ticketService;

/** ProductService. */
@Mock
private ProductService productService;

/** EventService. */
@Mock
private EventService eventService;
Expand All @@ -56,7 +63,7 @@ public class OrderValidationServiceImplTest extends ServiceTest {

@Before
public void setUp() {
orderValidationService = new OrderValidationServiceImpl(orderRepository, ticketService, eventService);
orderValidationService = new OrderValidationServiceImpl(orderRepository, ticketService, productService, eventService);

product = mock(Product.class);
when(product.getVatRate()).thenReturn(VatRate.VAT_HIGH);
Expand Down Expand Up @@ -229,8 +236,9 @@ public void assertOrderIsValidForCustomerExceedSold() throws Exception {
Order prevOrder = mock(Order.class);

when(product.getMaxSoldPerCustomer()).thenReturn(1);
when(productService.getRelatedProducts(product)).thenReturn(ImmutableList.of(product));
when(orderRepository.findAllByOwnerAndStatus(customer, OrderStatus.RESERVATION)).thenReturn(ImmutableList.of(prevOrder));
when(ticketService.getAllByProductAndCustomer(product, customer)).thenReturn(ImmutableList.of(mock(Ticket.class)));
when(ticketService.getAllByProductsAndCustomer(List.of(product), customer)).thenReturn(ImmutableList.of(mock(Ticket.class)));

thrown.expect(OrderExceedCustomerLimitException.class);
thrown.expectMessage("Customer limit exceeded (max 0 tickets allowed).");
Expand All @@ -249,8 +257,9 @@ public void assertOrderIsValidForCustomerExceedReservation() throws Exception {
when(prevOrder.getOrderProducts()).thenReturn(ImmutableList.of(prevOrderProduct));

when(product.getMaxSoldPerCustomer()).thenReturn(1);
when(productService.getRelatedProducts(product)).thenReturn(ImmutableList.of(product));
when(orderRepository.findAllByOwnerAndStatus(customer, OrderStatus.RESERVATION)).thenReturn(ImmutableList.of(prevOrder));
when(ticketService.getAllByProductAndCustomer(product, customer)).thenReturn(ImmutableList.of());
when(ticketService.getAllByProductsAndCustomer(List.of(product), customer)).thenReturn(ImmutableList.of());

thrown.expect(OrderExceedCustomerLimitException.class);
thrown.expectMessage("Customer limit exceeded (max 0 tickets allowed).");
Expand Down

0 comments on commit 3eee600

Please sign in to comment.