Commit bd76e8a0 authored by Angelo Veltens's avatar Angelo Veltens

find ticket by code

parent 382da579
......@@ -19,6 +19,7 @@ public class RegisteredTickets {
}
public Ticket findBy(Code knownCode) {
throw new NotYetImplementedException();
TicketData data = repository.findByCode(knownCode.getValue());
return new Ticket(data.getTicketId());
}
}
......@@ -12,10 +12,18 @@ import java.util.UUID;
public
class TicketData {
private TicketData() {
}
public TicketData(String code, UUID ticketId) {
this.code = code;
this.ticketId = ticketId;
}
@Id
@GeneratedValue
private Long id;
private final String code;
private final UUID ticketId;
private String code;
private UUID ticketId;
}
......@@ -6,4 +6,5 @@ import org.springframework.stereotype.Repository;
@Repository
public interface TicketRepository extends CrudRepository<TicketData, Long> {
TicketData findByCode(String code);
}
......@@ -2,6 +2,7 @@ package de.codecentric.ticketscanner;
import de.codecentric.ticketscanner.persistence.TicketData;
import de.codecentric.ticketscanner.persistence.TicketRepository;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
......@@ -10,6 +11,8 @@ import org.mockito.junit.jupiter.MockitoExtension;
import java.util.UUID;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.verify;
@ExtendWith(MockitoExtension.class)
......@@ -18,12 +21,26 @@ class RegisteredTicketsSpec {
@Mock
TicketRepository repository;
private RegisteredTickets registeredTickets;;
@BeforeEach
void setUp() {
registeredTickets = new RegisteredTickets(repository);
}
@Test
@DisplayName("are stored in a repository")
void store_to_repository() {
UUID ticketId = UUID.randomUUID();
new RegisteredTickets(repository).store(new Code("123"), new Ticket(ticketId));
registeredTickets.store(new Code("123"), new Ticket(ticketId));
verify(repository).save(new TicketData("123", ticketId));
}
@Test
void find_by_code() {
UUID ticketId = UUID.randomUUID();
given(repository.findByCode("456")).willReturn(new TicketData("456", ticketId));
Ticket foundTicket = registeredTickets.findBy(new Code("456"));
assertThat(foundTicket).isEqualTo(new Ticket(ticketId));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment