Commit 382da579 authored by Angelo Veltens's avatar Angelo Veltens

persist registered ticket

parent 509ca272
package de.codecentric.ticketscanner;
import org.aspectj.weaver.ast.Not;
import de.codecentric.ticketscanner.persistence.TicketData;
import de.codecentric.ticketscanner.persistence.TicketRepository;
import org.hibernate.cfg.NotYetImplementedException;
import org.springframework.stereotype.Component;
@Component
public class RegisteredTickets {
public Ticket findBy(Code knownCode) {
throw new NotYetImplementedException();
private final TicketRepository repository;
public RegisteredTickets(TicketRepository repository) {
this.repository = repository;
}
public void store(Code generatedCode, Ticket ticketToRegister) {
repository.save(new TicketData(generatedCode.getValue(), ticketToRegister.getId()));
}
public Ticket findBy(Code knownCode) {
throw new NotYetImplementedException();
}
}
package de.codecentric.ticketscanner.persistence;
import lombok.Data;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import java.util.UUID;
@Data
@Entity
public
class TicketData {
@Id
@GeneratedValue
private Long id;
private final String code;
private final UUID ticketId;
}
package de.codecentric.ticketscanner.persistence;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface TicketRepository extends CrudRepository<TicketData, Long> {
}
package de.codecentric.ticketscanner;
import de.codecentric.ticketscanner.persistence.TicketData;
import de.codecentric.ticketscanner.persistence.TicketRepository;
import org.junit.jupiter.api.DisplayName;
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.mockito.Mockito.verify;
@ExtendWith(MockitoExtension.class)
@DisplayName("the registered tickets")
class RegisteredTicketsSpec {
@Mock
TicketRepository 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));
verify(repository).save(new TicketData("123", ticketId));
}
}
package de.codecentric.ticketscanner;
import org.junit.Test;
import de.codecentric.ticketscanner.persistence.TicketRepository;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.UUID;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
@RunWith(MockitoJUnitRunner.class)
public class TicketScannerFeature {
@SpringBootTest
class TicketScannerFeature {
@Autowired
TicketRepository repository;
@Test
public void successful_check_in_with_valid_ticket() {
void successful_check_in_with_valid_ticket() {
// given
RegisteredTickets registeredTickets = new RegisteredTickets();
RegisteredTickets registeredTickets = new RegisteredTickets(repository);
CodeGenerator codeGenerator = new CodeGenerator(new StaticCodeGenerationStrategy("WHATEVER"));
TicketScanner ticketScanner = new TicketScanner(codeGenerator, registeredTickets);
Ticket registeredTicket = new Ticket(UUID.randomUUID());
......
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