Commit aee1b397 authored by Angelo Veltens's avatar Angelo Veltens

lookup ticket when scanning code

parent a3cf9c44
package de.codecentric.ticketscanner;
import org.hibernate.cfg.NotYetImplementedException;
import org.springframework.stereotype.Component;
@Component
public class RegisteredTickets {
public Ticket findBy(Code knownCode) {
throw new NotYetImplementedException();
}
}
package de.codecentric.ticketscanner;
import lombok.EqualsAndHashCode;
import lombok.Value;
import java.util.UUID;
@EqualsAndHashCode
@Value
public class Ticket {
private final UUID id;
public Ticket(UUID id) {
this.id = id;
}
UUID getId() {
return id;
}
}
......@@ -3,12 +3,16 @@ package de.codecentric.ticketscanner;
import org.hibernate.cfg.NotYetImplementedException;
import org.springframework.stereotype.Component;
import java.util.UUID;
@Component
public class TicketScanner {
private final CodeGenerator codeGenerator;
private final RegisteredTickets registeredTickets;
public TicketScanner(CodeGenerator codeGenerator) {
public TicketScanner(CodeGenerator codeGenerator, RegisteredTickets registeredTickets) {
this.codeGenerator = codeGenerator;
this.registeredTickets = registeredTickets;
}
public Code register(Ticket ticket) {
......@@ -16,7 +20,7 @@ public class TicketScanner {
}
public Ticket scan(Code code) {
throw new NotYetImplementedException();
return registeredTickets.findBy(code);
}
public CheckIn checkIn(Code code) {
......
......@@ -14,8 +14,9 @@ public class TicketScannerFeature {
@Test
public void successful_check_in_with_valid_ticket() {
// given
RegisteredTickets registeredTickets = new RegisteredTickets();
CodeGenerator codeGenerator = new CodeGenerator(new StaticCodeGenerationStrategy("WHATEVER"));
TicketScanner ticketScanner = new TicketScanner(codeGenerator);
TicketScanner ticketScanner = new TicketScanner(codeGenerator, registeredTickets);
Ticket registeredTicket = new Ticket(UUID.randomUUID());
// when
Code code = ticketScanner.register(registeredTicket);
......
......@@ -13,7 +13,6 @@ import java.util.UUID;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
@ExtendWith(MockitoExtension.class)
@DisplayName("given a ticket scanner")
class TicketScannerSpec {
......@@ -22,11 +21,14 @@ class TicketScannerSpec {
private TicketScanner ticketScanner;
@Mock
CodeGenerator codeGenerator;
private CodeGenerator codeGenerator;
@Mock
private RegisteredTickets registeredTickets;
@BeforeEach
void setUp() {
ticketScanner = new TicketScanner(codeGenerator);
ticketScanner = new TicketScanner(codeGenerator, registeredTickets);
}
@Nested
......@@ -52,4 +54,27 @@ class TicketScannerSpec {
}
}
@Nested
@DisplayName("when a code for a registered ticket is scanned")
class ScanCode {
private Ticket foundTicket;
private Ticket registeredTicket;
@BeforeEach
void setUp() {
registeredTicket = new Ticket(UUID.randomUUID());
Code knownCode = new Code("KNOWN");
given(registeredTickets.findBy(knownCode)).willReturn(registeredTicket);
foundTicket = ticketScanner.scan(knownCode);
}
@Test
@DisplayName("then the ticket is found")
void ticket_is_found() {
assertThat(foundTicket).isEqualTo(registeredTicket);
}
}
}
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