So im trying to test my service layer and i have mocked my repository, what i want to do is
@ExtendWith(MockitoExtension.class)
public class TicketServiceTest {
@Mock
private TicketRepository ticketRepository;
@InjectMocks
private TicketService ticketService;
@Test
public void test_buy_ticket_successfully() {
Ticket ticket = new Ticket(1, false, false, "");
List<Ticket> availableTickets = Arrays.asList(ticket);
Mockito.when(ticketRepository.findAllUnboughtAndUnpickedTickets()).thenReturn(availableTickets);
Mockito.when(ticketRepo.findById(any(Integer.class)).thenReturn(Optional.of(any(Ticket.class));
Ticket boughtTicket = ticketService.buyTicket("123");
assertNotNull(boughtTicket);
assertEquals(1, boughtTicket.getId());
Mockito.verify(ticketRepository).findAllUnboughtAndUnpickedTickets();
}
Error i get is :
Type mismatch: cannot convert from Matcher<Integer> to Integer
All i want to do is use any matchers in the input and output, but this does not work as my repoistory is as follows:
public interface TickRep extends JpaRepository<Ticket, Integer>
Im using spring boot, junit 5.
Any ideas?