package se.jaitco.queueticketapi.controller;

import org.junit.Before;
import org.junit.Test;
import org.mockito.*;
import se.jaitco.queueticketapi.model.Ticket;
import se.jaitco.queueticketapi.model.TicketStatus;
import se.jaitco.queueticketapi.service.TicketService;

import java.util.Optional;

public class TicketControllerTest {

    @InjectMocks
    private final TicketController classUnderTest = new TicketController();

    @Mock
    private TicketService ticketService;

    @Before
    public void setup() {
        MockitoAnnotations.initMocks(this);
    }

    @Test
    public void testNewTicket() {
        classUnderTest.newTicket();

        Mockito.verify(ticketService, Mockito.times(1)).newTicket();
    }

    @Test
    public void testResetTickets() {
        classUnderTest.resetTickets();

        Mockito.verify(ticketService, Mockito.times(1)).resetTickets();
    }

    @Test
    public void testNextTicket() {
        classUnderTest.nextTicket();

        Mockito.verify(ticketService, Mockito.times(1)).nextTicket();
    }

    @Test
    public void testCurrentTicket() {
        Mockito.when(ticketService.currentTicket()).thenReturn(Optional.of(new Ticket()));
        classUnderTest.currentTicket();

        Mockito.verify(ticketService, Mockito.times(1)).currentTicket();
    }

    @Test(expected = TicketController.NotFoundException.class)
    public void testCurrentTicketNotFound() {
        Mockito.when(ticketService.currentTicket()).thenReturn(Optional.empty());
        classUnderTest.currentTicket();
    }

    @Test
    public void testTicketStatus() {
        Mockito.when(ticketService.ticketStatus(Matchers.anyLong()))
                .thenReturn(Optional.of(TicketStatus.builder().build()));

        final long ticketNumber = 10L;
        classUnderTest.ticketStatus(ticketNumber);

        Mockito.verify(ticketService, Mockito.times(1)).ticketStatus(ticketNumber);
    }

    @Test(expected = TicketController.NotFoundException.class)
    public void testTicketStatusNotFound() {
        Mockito.when(ticketService.ticketStatus(Matchers.anyLong())).thenReturn(Optional.empty());
        classUnderTest.ticketStatus(10L);
    }

    @Test
    public void testDropTicket() {
        final long ticketNumber = 10L;
        classUnderTest.dropTicket(ticketNumber);

        Mockito.verify(ticketService, Mockito.times(1)).dropTicket(ticketNumber);
    }

    @Test
    public void testSize() {
        classUnderTest.size();

        Mockito.verify(ticketService, Mockito.times(1)).size();
    }

}
@@ -39,16 +39,41 @@
 oller;%0A%0A
+import org.junit.Assert;%0A
 import o
@@ -316,16 +316,112 @@
 ional;%0A%0A
+import static org.hamcrest.CoreMatchers.is;%0Aimport static org.hamcrest.CoreMatchers.nullValue;%0A%0A
 public c
@@ -1440,61 +1440,8 @@
 Test
-(expected = TicketController.NotFoundException.class)
 %0A   
@@ -1564,32 +1564,48 @@
 mpty());%0A       
+ Ticket ticket =
  classUnderTest.
@@ -1612,32 +1612,85 @@
 currentTicket();
+%0A%0A        Assert.assertThat(ticket, is(nullValue()));
 %0A    %7D%0A%0A    @Tes

return null current