Commit ef9a18a9 authored by Angelo Veltens's avatar Angelo Veltens

generate code when registering ticket

parent 86569ded
package de.codecentric.ticketscanner;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.util.UUID;
@EqualsAndHashCode
@ToString
public class Code {
private String id;
......
package de.codecentric.ticketscanner;
import org.hibernate.cfg.NotYetImplementedException;
import org.springframework.stereotype.Component;
@Component
public class CodeGenerator {
public Code generateFor(Ticket ticket) {
throw new NotYetImplementedException();
}
}
......@@ -5,8 +5,14 @@ import org.springframework.stereotype.Component;
@Component
public class TicketScanner {
private final CodeGenerator codeGenerator;
public TicketScanner(CodeGenerator codeGenerator) {
this.codeGenerator = codeGenerator;
}
public Code register(Ticket ticket) {
throw new NotYetImplementedException();
return codeGenerator.generateFor(ticket);
}
public Ticket scan(Code code) {
......
......@@ -14,7 +14,8 @@ public class TicketScannerFeature {
@Test
public void successful_check_in_with_valid_ticket() {
// given
TicketScanner ticketScanner = new TicketScanner();
CodeGenerator codeGenerator = new CodeGenerator();
TicketScanner ticketScanner = new TicketScanner(codeGenerator);
Ticket registeredTicket = new Ticket(UUID.randomUUID());
// when
Code code = ticketScanner.register(registeredTicket);
......
package de.codecentric.ticketscanner;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
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 {
private static final String CODE = "XYZ123";
private TicketScanner ticketScanner;
@Mock
CodeGenerator codeGenerator;
@BeforeEach
void setUp() {
ticketScanner = new TicketScanner(codeGenerator);
}
@Nested
@DisplayName("when it registers a new ticket")
class RegisterTicket {
private Code ticketCode;
private Code generatedCode;
@BeforeEach
void setUp() {
Ticket registeredTicket = new Ticket(UUID.randomUUID());
generatedCode = new Code(CODE, registeredTicket);
given(codeGenerator.generateFor(registeredTicket)).willReturn(generatedCode);
ticketCode = ticketScanner.register(registeredTicket);
}
@Test
@DisplayName("then it generates a new code")
void creates_a_new_code_for_ticket() {
assertThat(ticketCode).isEqualTo(generatedCode);
}
}
}
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