BAEL-5370
Test could fail if ran in a different order: givenCompositeId_whenSearchingByIdObject_thenFound
This commit is contained in:
parent
681aeb3142
commit
8a75af488b
|
@ -13,6 +13,12 @@ public class Ticket {
|
||||||
public Ticket() {
|
public Ticket() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Ticket(TicketId id, String event) {
|
||||||
|
super();
|
||||||
|
this.id = id;
|
||||||
|
this.event = event;
|
||||||
|
}
|
||||||
|
|
||||||
public TicketId getId() {
|
public TicketId getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ import static org.junit.Assert.assertThrows;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -27,28 +26,26 @@ public class CustomerServiceIntegrationTest {
|
||||||
@Autowired
|
@Autowired
|
||||||
private CustomerService service;
|
private CustomerService service;
|
||||||
|
|
||||||
private static Ticket ticket;
|
|
||||||
private static TicketId ticketId;
|
|
||||||
|
|
||||||
@BeforeClass
|
|
||||||
public static void setup() {
|
|
||||||
ticket = new Ticket();
|
|
||||||
ticket.setEvent("Event A");
|
|
||||||
|
|
||||||
ticketId = new TicketId();
|
|
||||||
ticketId.setDate("2020-01-01");
|
|
||||||
ticketId.setVenue("Venue A");
|
|
||||||
ticket.setId(ticketId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenCompositeId_whenObjectSaved_thenIdMatches() {
|
public void givenCompositeId_whenObjectSaved_thenIdMatches() {
|
||||||
|
TicketId ticketId = new TicketId();
|
||||||
|
ticketId.setDate("2020-01-01");
|
||||||
|
ticketId.setVenue("Venue A");
|
||||||
|
|
||||||
|
Ticket ticket = new Ticket(ticketId, "Event A");
|
||||||
Ticket savedTicket = service.insert(ticket);
|
Ticket savedTicket = service.insert(ticket);
|
||||||
|
|
||||||
assertEquals(savedTicket.getId(), ticket.getId());
|
assertEquals(savedTicket.getId(), ticket.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenCompositeId_whenSearchingByIdObject_thenFound() {
|
public void givenCompositeId_whenSearchingByIdObject_thenFound() {
|
||||||
|
TicketId ticketId = new TicketId();
|
||||||
|
ticketId.setDate("2020-01-01");
|
||||||
|
ticketId.setVenue("Venue B");
|
||||||
|
|
||||||
|
service.insert(new Ticket(ticketId, "Event B"));
|
||||||
|
|
||||||
Optional<Ticket> optionalTicket = service.find(ticketId);
|
Optional<Ticket> optionalTicket = service.find(ticketId);
|
||||||
|
|
||||||
assertThat(optionalTicket.isPresent());
|
assertThat(optionalTicket.isPresent());
|
||||||
|
@ -73,13 +70,11 @@ public class CustomerServiceIntegrationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenCompositeId_whenDupeInsert_thenExceptionIsThrown() {
|
public void givenCompositeId_whenDupeInsert_thenExceptionIsThrown() {
|
||||||
Ticket ticket = new Ticket();
|
|
||||||
ticket.setEvent("C");
|
|
||||||
|
|
||||||
TicketId ticketId = new TicketId();
|
TicketId ticketId = new TicketId();
|
||||||
ticketId.setDate("2020-01-01");
|
ticketId.setDate("2020-01-01");
|
||||||
ticketId.setVenue("V");
|
ticketId.setVenue("V");
|
||||||
ticket.setId(ticketId);
|
|
||||||
|
Ticket ticket = new Ticket(ticketId, "Event C");
|
||||||
|
|
||||||
assertThrows(DuplicateKeyException.class, () -> {
|
assertThrows(DuplicateKeyException.class, () -> {
|
||||||
service.insert(ticket);
|
service.insert(ticket);
|
||||||
|
@ -93,17 +88,12 @@ public class CustomerServiceIntegrationTest {
|
||||||
ticketId.setDate("2020-01-01");
|
ticketId.setDate("2020-01-01");
|
||||||
ticketId.setVenue("Venue");
|
ticketId.setVenue("Venue");
|
||||||
|
|
||||||
Ticket ticketA = new Ticket();
|
Ticket ticketA = new Ticket(ticketId, "A");
|
||||||
ticketA.setEvent("A");
|
|
||||||
ticketA.setId(ticketId);
|
|
||||||
|
|
||||||
service.save(ticketA);
|
service.save(ticketA);
|
||||||
|
|
||||||
Ticket ticketB = new Ticket();
|
Ticket ticketB = new Ticket(ticketId, "B");
|
||||||
ticketB.setEvent("B");
|
|
||||||
ticketB.setId(ticketId);
|
|
||||||
|
|
||||||
Ticket savedTicket = service.save(ticketB);
|
Ticket savedTicket = service.save(ticketB);
|
||||||
|
|
||||||
assertEquals(savedTicket.getEvent(), ticketB.getEvent());
|
assertEquals(savedTicket.getEvent(), ticketB.getEvent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue