diff --git a/src/main/java/cat/udl/eps/softarch/fll/domain/CompetitionTable.java b/src/main/java/cat/udl/eps/softarch/fll/domain/CompetitionTable.java index 4ae036c9..c088f39d 100644 --- a/src/main/java/cat/udl/eps/softarch/fll/domain/CompetitionTable.java +++ b/src/main/java/cat/udl/eps/softarch/fll/domain/CompetitionTable.java @@ -9,37 +9,34 @@ import jakarta.persistence.OneToMany; import jakarta.persistence.Table; import jakarta.validation.constraints.Size; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; @Entity @Table(name = "competition_tables") +@Getter +@Setter +@NoArgsConstructor +@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true) public class CompetitionTable extends UriEntity { @Id + @EqualsAndHashCode.Include private String id; - @OneToMany(mappedBy = "competitionTable", cascade = CascadeType.ALL) + @OneToMany(mappedBy = "competitionTable", cascade = {CascadeType.PERSIST, CascadeType.MERGE}) @JsonManagedReference("table-matches") + @Setter(lombok.AccessLevel.NONE) private List matches = new ArrayList<>(); @OneToMany(mappedBy = "supervisesTable") @Size(max = 3, message = "A table can have a maximum of 3 referees") @JsonManagedReference("table-referees") + @Setter(lombok.AccessLevel.NONE) private List referees = new ArrayList<>(); - - @Override - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public List getMatches() { - return matches; - } - public void setMatches(List matches) { new ArrayList<>(this.matches).forEach(this::removeMatch); if (matches != null) { @@ -47,50 +44,70 @@ public void setMatches(List matches) { } } - public List getReferees() { - return referees; - } + public void addMatch(Match match) { + if (match == null) { + return; + } - public void setReferees(List referees) { - new ArrayList<>(this.referees).forEach(this::removeReferee); - if (referees != null) { - referees.forEach(this::addReferee); + if (this.matches.stream().anyMatch(m -> m == match)) { + return; } - } - public void addMatch(Match match) { CompetitionTable previousTable = match.getCompetitionTable(); if (previousTable != null && previousTable != this) { - previousTable.removeMatch(match); - } - if (!matches.contains(match)) { - matches.add(match); + previousTable.getMatches().removeIf(m -> m == match); } + + this.matches.add(match); match.setCompetitionTable(this); } public void removeMatch(Match match) { - matches.remove(match); - match.setCompetitionTable(null); + if (match == null) { + return; + } + + if (this.matches.removeIf(m -> m == match)) { + match.setCompetitionTable(null); + } + } + + public void setReferees(List referees) { + new ArrayList<>(this.referees).forEach(this::removeReferee); + if (referees != null) { + referees.forEach(this::addReferee); + } } public void addReferee(Referee referee) { - CompetitionTable previousTable = referee.getSupervisesTable(); - if (previousTable != null && previousTable != this) { - previousTable.removeReferee(referee); + if (referee == null) { + return; } - if (referees.contains(referee)) { + + if (this.referees.stream().anyMatch(r -> r == referee)) { return; } - if (referees.size() >= 3) { + + if (this.referees.size() >= 3) { throw new IllegalStateException("A table can have a maximum of 3 referees"); } - referees.add(referee); + + CompetitionTable previousTable = referee.getSupervisesTable(); + if (previousTable != null && previousTable != this) { + previousTable.getReferees().removeIf(r -> r == referee); + } + + this.referees.add(referee); referee.setSupervisesTable(this); } public void removeReferee(Referee referee) { - referees.remove(referee); - referee.setSupervisesTable(null); + if (referee == null) { + return; + } + + if (this.referees.removeIf(r -> r == referee)) { + referee.setSupervisesTable(null); + } } } diff --git a/src/main/java/cat/udl/eps/softarch/fll/domain/Match.java b/src/main/java/cat/udl/eps/softarch/fll/domain/Match.java index 1dc26d08..184eb28a 100644 --- a/src/main/java/cat/udl/eps/softarch/fll/domain/Match.java +++ b/src/main/java/cat/udl/eps/softarch/fll/domain/Match.java @@ -13,28 +13,33 @@ import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Setter; +import lombok.NoArgsConstructor; @Entity @Table(name = "matches") +@Getter +@Setter +@NoArgsConstructor +@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true) public class Match extends UriEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + @EqualsAndHashCode.Include private Long id; private LocalTime startTime; - private LocalTime endTime; - @JsonBackReference("round-matches") - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "round_id") - private Round round; + @Enumerated(EnumType.STRING) + private MatchState state = MatchState.SCHEDULED; - @JsonBackReference("table-matches") @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "table_id") - private CompetitionTable competitionTable; + @JoinColumn(name = "referee_id") + private Referee referee; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "team_a_id") @@ -47,84 +52,12 @@ public class Match extends UriEntity { private Team teamB; @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "referee_id") - private Referee referee; - - @Enumerated(EnumType.STRING) - private MatchState state = MatchState.SCHEDULED; - - public Match() {} - - @Override - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public LocalTime getStartTime() { - return startTime; - } - - public void setStartTime(LocalTime startTime) { - this.startTime = startTime; - } - - public LocalTime getEndTime() { - return endTime; - } - - public void setEndTime(LocalTime endTime) { - this.endTime = endTime; - } - - public Round getRound() { - return round; - } - - public void setRound(Round round) { - this.round = round; - } - - public CompetitionTable getCompetitionTable() { - return competitionTable; - } - - public void setCompetitionTable(CompetitionTable competitionTable) { - this.competitionTable = competitionTable; - } - - public Team getTeamA() { - return teamA; - } - - public void setTeamA(Team teamA) { - this.teamA = teamA; - } - - public Team getTeamB() { - return teamB; - } - - public void setTeamB(Team teamB) { - this.teamB = teamB; - } - - public Referee getReferee() { - return referee; - } - - public void setReferee(Referee referee) { - this.referee = referee; - } - - public MatchState getState() { - return state; - } + @JoinColumn(name = "round_id") + @JsonBackReference("round-matches") + private Round round; - public void setState(MatchState state) { - this.state = state; - } + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "table_id") + @JsonBackReference("table-matches") + private CompetitionTable competitionTable; } diff --git a/src/main/java/cat/udl/eps/softarch/fll/domain/Referee.java b/src/main/java/cat/udl/eps/softarch/fll/domain/Referee.java index edf591ff..de9cf127 100644 --- a/src/main/java/cat/udl/eps/softarch/fll/domain/Referee.java +++ b/src/main/java/cat/udl/eps/softarch/fll/domain/Referee.java @@ -6,10 +6,18 @@ import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; @Entity @Table(name = "referees") +@Getter +@Setter +@NoArgsConstructor +@EqualsAndHashCode(callSuper = true, onlyExplicitlyIncluded = true) public class Referee extends Volunteer { private boolean expert; @@ -18,21 +26,4 @@ public class Referee extends Volunteer { @JoinColumn(name = "supervises_table_id") @JsonBackReference("table-referees") private CompetitionTable supervisesTable; - - - public boolean isExpert() { - return expert; - } - - public void setExpert(boolean expert) { - this.expert = expert; - } - - public CompetitionTable getSupervisesTable() { - return supervisesTable; - } - - public void setSupervisesTable(CompetitionTable supervisesTable) { - this.supervisesTable = supervisesTable; - } } diff --git a/src/main/java/cat/udl/eps/softarch/fll/domain/Round.java b/src/main/java/cat/udl/eps/softarch/fll/domain/Round.java index f2f8793c..00b77d97 100644 --- a/src/main/java/cat/udl/eps/softarch/fll/domain/Round.java +++ b/src/main/java/cat/udl/eps/softarch/fll/domain/Round.java @@ -11,13 +11,22 @@ import jakarta.persistence.Id; import jakarta.persistence.OneToMany; import jakarta.persistence.Table; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Setter; +import lombok.NoArgsConstructor; @Entity @Table(name = "rounds") +@Getter +@Setter +@NoArgsConstructor +@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true) public class Round extends UriEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + @EqualsAndHashCode.Include private Long id; @Column(unique = true) @@ -25,45 +34,45 @@ public class Round extends UriEntity { @OneToMany(mappedBy = "round", cascade = CascadeType.ALL, orphanRemoval = true) @JsonManagedReference("round-matches") + @Setter(lombok.AccessLevel.NONE) private List matches = new ArrayList<>(); - public Round() {} - - @Override - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } + public void setMatches(List matches) { + if (matches == this.matches) { + return; + } - public int getNumber() { - return number; + List incoming = (matches == null) ? List.of() : new ArrayList<>(matches); + new ArrayList<>(this.matches).forEach(this::removeMatch); + incoming.forEach(this::addMatch); } - public void setNumber(int number) { - this.number = number; - } + public void addMatch(Match match) { + if (match == null) { + return; + } - public List getMatches() { - return matches; - } + if (this.matches.stream().anyMatch(m -> m == match)) { + return; + } - public void setMatches(List matches) { - this.matches.clear(); - if (matches != null) { - matches.forEach(this::addMatch); + Round previousRound = match.getRound(); + if (previousRound != null && previousRound != this) { + previousRound.getMatches().removeIf(m -> m == match); } - } - public void addMatch(Match match) { - matches.add(match); + this.matches.add(match); match.setRound(this); } public void removeMatch(Match match) { - matches.remove(match); - match.setRound(null); + if (match == null) { + return; + + } + + if (this.matches.removeIf(m -> m == match)) { + match.setRound(null); + } } } diff --git a/src/test/java/cat/udl/eps/softarch/fll/steps/CompetitionTableStepsDefs.java b/src/test/java/cat/udl/eps/softarch/fll/steps/CompetitionTableStepsDefs.java new file mode 100644 index 00000000..988f90a5 --- /dev/null +++ b/src/test/java/cat/udl/eps/softarch/fll/steps/CompetitionTableStepsDefs.java @@ -0,0 +1,71 @@ +package cat.udl.eps.softarch.fll.steps; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import cat.udl.eps.softarch.fll.domain.CompetitionTable; +import cat.udl.eps.softarch.fll.domain.Referee; +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; + +public class CompetitionTableStepsDefs { + + private CompetitionTable table; + private Referee namedReferee; + private Exception thrownException; + + @Given("a new Competition Table with id {string}") + public void a_new_competition_table_with_id(String tableId) { + table = new CompetitionTable(); + table.setId(tableId); + } + + @When("I add a referee named {string} to the table") + public void i_add_a_referee_named_to_the_table(String name) { + namedReferee = new Referee(); + table.addReferee(namedReferee); + } + + @Then("the table should have {int} referee") + public void the_table_should_have_referee(Integer expectedCount) { + assertEquals(expectedCount, table.getReferees().size(), + "The table does not have the expected number of referees"); + } + + @Then("the referee {string} should be supervising {string}") + public void the_referee_should_be_supervising(String refereeName, String expectedTableId) { + assertNotNull(namedReferee.getSupervisesTable(), "The referee is not assigned to any table"); + assertEquals(expectedTableId, namedReferee.getSupervisesTable().getId(), + "The referee is assigned to the wrong table"); + } + + @Given("the table already has {int} referees") + public void the_table_already_has_referees(Integer count) { + for (int i = 0; i < count; i++) { + table.addReferee(new Referee()); + } + } + + @When("I try to add another referee to the table") + public void i_try_to_add_another_referee_to_the_table() { + Referee extraReferee = new Referee(); + + try { + table.addReferee(extraReferee); + } catch (Exception e) { + thrownException = e; + } + } + + @Then("the validation should prevent adding a 4th referee") + public void the_validation_should_prevent_adding_a_4th_referee() { + assertNotNull(thrownException, "An exception should have been thrown when adding the 4th referee"); + + assertTrue(thrownException instanceof IllegalStateException, + "The exception should be an IllegalStateException"); + assertEquals("A table can have a maximum of 3 referees", thrownException.getMessage()); + + assertEquals(3, table.getReferees().size(), "The table should strictly contain 3 referees"); + } +} diff --git a/src/test/java/cat/udl/eps/softarch/fll/steps/MatchStepsDefs.java b/src/test/java/cat/udl/eps/softarch/fll/steps/MatchStepsDefs.java new file mode 100644 index 00000000..d5b71b24 --- /dev/null +++ b/src/test/java/cat/udl/eps/softarch/fll/steps/MatchStepsDefs.java @@ -0,0 +1,66 @@ +package cat.udl.eps.softarch.fll.steps; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import cat.udl.eps.softarch.fll.domain.CompetitionTable; +import cat.udl.eps.softarch.fll.domain.Match; +import cat.udl.eps.softarch.fll.domain.Round; +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; +import java.time.Duration; +import java.time.LocalTime; + + +public class MatchStepsDefs { + + private Round round; + private CompetitionTable table; + private Match match; + + @Given("a Round exists") + public void a_round_exists() { + round = new Round(); + round.setNumber(1); + } + + @Given("a Competition Table exists") + public void a_competition_table_exists() { + table = new CompetitionTable(); + table.setId("Table-1"); + } + + @When("I create a new match starting at {string} and ending at {string}") + public void i_create_a_new_match_starting_at_and_ending_at(String startTimeStr, String endTimeStr) { + match = new Match(); + + match.setStartTime(LocalTime.parse(startTimeStr)); + match.setEndTime(LocalTime.parse(endTimeStr)); + + round.addMatch(match); + table.addMatch(match); + } + + @Then("the match should be linked to the round and the table") + public void the_match_should_be_linked_to_the_round_and_the_table() { + + assertNotNull(match.getRound(), "The match round should not be null"); + assertEquals(round, match.getRound(), "The match should be linked to the correct round"); + + assertNotNull(match.getCompetitionTable(), "The match table should not be null"); + assertEquals(table, match.getCompetitionTable(), "The match should be linked to the correct table"); + + assertEquals(1, round.getMatches().size(), "The round should contain the match"); + assertEquals(1, table.getMatches().size(), "The table should contain the match"); + } + + @Then("the match duration should be {string} minutes") + public void the_match_duration_should_be_minutes(String expectedMinutesStr) { + long expectedMinutes = Long.parseLong(expectedMinutesStr); + + Duration duration = Duration.between(match.getStartTime(), match.getEndTime()); + long actualMinutes = duration.toMinutes(); + + assertEquals(expectedMinutes, actualMinutes, "The match duration should match the expected minutes"); + } +} diff --git a/src/test/java/cat/udl/eps/softarch/fll/steps/RefereeStepsDefs.java b/src/test/java/cat/udl/eps/softarch/fll/steps/RefereeStepsDefs.java new file mode 100644 index 00000000..0f462565 --- /dev/null +++ b/src/test/java/cat/udl/eps/softarch/fll/steps/RefereeStepsDefs.java @@ -0,0 +1,61 @@ +package cat.udl.eps.softarch.fll.steps; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import cat.udl.eps.softarch.fll.domain.CompetitionTable; +import cat.udl.eps.softarch.fll.domain.Referee; +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; + + +public class RefereeStepsDefs { + + private Referee referee; + private CompetitionTable table; + + @Given("a new referee") + public void a_new_referee() { + referee = new Referee(); + } + + @When("I set the referee as an expert") + public void i_set_the_referee_as_an_expert() { + referee.setExpert(true); + } + + @Then("the referee should be recognized as an expert") + public void the_referee_should_be_recognized_as_an_expert() { + assertTrue(referee.isExpert(), "The referee should be marked as an expert"); + } + + @Given("a competition table exists with ID {string}") + public void a_competition_table_exists_with_id(String tableId) { + table = new CompetitionTable(); + table.setId(tableId); + } + + @When("I assign the referee to supervise {string}") + public void i_assign_the_referee_to_supervise(String tableId) { + assertEquals(tableId, table.getId(), "Table ID mismatch in context"); + + table.addReferee(referee); + } + + @Then("the referee should reference {string} as their assigned table") + public void the_referee_should_reference_as_their_assigned_table(String expectedTableId) { + assertNotNull(referee.getSupervisesTable(), "The referee should have an assigned table"); + assertEquals(expectedTableId, referee.getSupervisesTable().getId(), "The assigned table ID is incorrect"); + } + + @Then("the table {string} should list the referee in its staff") + public void the_table_should_list_the_referee_in_its_staff(String expectedTableId) { + assertEquals(expectedTableId, table.getId(), "Table ID mismatch in context"); + + assertEquals(1, table.getReferees().size(), "The table should have exactly 1 referee assigned"); + + boolean containsReferee = table.getReferees().stream().anyMatch(r -> r == referee); + assertTrue(containsReferee, "The table's staff list should contain this exact referee instance"); + } +} diff --git a/src/test/java/cat/udl/eps/softarch/fll/steps/RoundStepsDefs.java b/src/test/java/cat/udl/eps/softarch/fll/steps/RoundStepsDefs.java new file mode 100644 index 00000000..92af6501 --- /dev/null +++ b/src/test/java/cat/udl/eps/softarch/fll/steps/RoundStepsDefs.java @@ -0,0 +1,70 @@ +package cat.udl.eps.softarch.fll.steps; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import cat.udl.eps.softarch.fll.domain.Match; +import cat.udl.eps.softarch.fll.domain.Round; +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; + +public class RoundStepsDefs { + + private Round round; + private Match removedMatch; + + @Given("a new Round with number {int}") + public void a_new_round_with_number(Integer number) { + round = new Round(); + round.setNumber(number); + } + + @When("I add {int} new matches to this round") + public void i_add_new_matches_to_this_round(Integer count) { + for (int i = 0; i < count; i++) { + Match match = new Match(); + round.addMatch(match); + } + } + + @Given("the round has {int} matches") + public void the_round_has_matches(Integer count) { + i_add_new_matches_to_this_round(count); + } + + @When("I remove one match from the round") + public void i_remove_one_match_from_the_round() { + if (!round.getMatches().isEmpty()) { + removedMatch = round.getMatches().get(0); + + round.removeMatch(removedMatch); + } + } + + @Then("the round should contain {int} matches") + public void the_round_should_contain_matches(Integer expectedCount) { + assertEquals(expectedCount, round.getMatches().size(), "The number of matches in the round is incorrect"); + } + + @Then("the round should contain {int} match") + public void the_round_should_contain_match(Integer expectedCount) { + the_round_should_contain_matches(expectedCount); + } + + @Then("each match should reference the round with number {int}") + public void each_match_should_reference_the_round_with_number(Integer expectedNumber) { + for (Match match : round.getMatches()) { + assertNotNull(match.getRound(), "The match should have a round reference"); + assertEquals(expectedNumber, match.getRound().getNumber(), + "The match is referencing the wrong round number"); + } + } + + @Then("the removed match should no longer reference the round") + public void the_removed_match_should_no_longer_reference_the_round() { + assertNotNull(removedMatch, "A match should have been removed during the 'When' step"); + assertNull(removedMatch.getRound(), + "The removed match should have its round reference set to null (Bidirectional consistency)"); + } +} diff --git a/src/test/java/cat/udl/eps/softarch/fll/steps/TestCompetitionTable.java b/src/test/java/cat/udl/eps/softarch/fll/steps/TestCompetitionTable.java deleted file mode 100644 index b9e927fd..00000000 --- a/src/test/java/cat/udl/eps/softarch/fll/steps/TestCompetitionTable.java +++ /dev/null @@ -1,70 +0,0 @@ -package cat.udl.eps.softarch.fll.steps; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; -import cat.udl.eps.softarch.fll.domain.CompetitionTable; -import cat.udl.eps.softarch.fll.domain.Referee; -import io.cucumber.java.en.Given; -import io.cucumber.java.en.Then; -import io.cucumber.java.en.When; - -public class TestCompetitionTable { - - private CompetitionTable table; - private Referee referee; - private Exception exceptionCaptured; - - @Given("a new Competition Table with id {string}") - public void a_new_competition_table_with_id(String id) { - table = new CompetitionTable(); - table.setId(id); - } - - @When("I add a referee named {string} to the table") - public void i_add_a_referee_named(String name) { - referee = new Referee(); - referee.setName(name); - table.addReferee(referee); - } - - @When("I try to add another referee to the table") - public void i_try_to_add_another_referee_to_the_table() { - exceptionCaptured = assertThrows(IllegalStateException.class, () -> { - table.addReferee(new Referee()); - }); - } - - @Then("the table should have {int} referee") - public void the_table_should_have_referee(Integer count) { - assertEquals(count, table.getReferees().size()); - } - - @Then("the referee {string} should be supervising {string}") - public void the_referee_should_be_supervising(String refName, String tableId) { - assertNotNull(referee.getSupervisesTable()); - assertEquals(tableId, referee.getSupervisesTable().getId()); - } - - @Given("the table already has {int} referees") - public void the_table_already_has_referees(Integer count) { - for (long i = 0; i < count; i++) { - Referee ref = new Referee(); - ref.setId(i); - table.addReferee(ref); - } - } - - @Then("the validation should prevent adding a 4th referee") - public void the_validation_should_prevent_adding_a_4th_referee() { - exceptionCaptured = assertThrows(IllegalStateException.class, () -> { - Referee newReferee = new Referee(); - newReferee.setId(999L); - table.addReferee(newReferee); - }); - - assertNotNull(exceptionCaptured); - assertEquals("A table can have a maximum of 3 referees", exceptionCaptured.getMessage()); - assertEquals(3, table.getReferees().size()); - } -} diff --git a/src/test/java/cat/udl/eps/softarch/fll/steps/TestMatch.java b/src/test/java/cat/udl/eps/softarch/fll/steps/TestMatch.java deleted file mode 100644 index 5fab0ac5..00000000 --- a/src/test/java/cat/udl/eps/softarch/fll/steps/TestMatch.java +++ /dev/null @@ -1,53 +0,0 @@ -package cat.udl.eps.softarch.fll.steps; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import java.time.Duration; -import java.time.LocalTime; -import cat.udl.eps.softarch.fll.domain.CompetitionTable; -import cat.udl.eps.softarch.fll.domain.Match; -import cat.udl.eps.softarch.fll.domain.Round; -import io.cucumber.java.en.Given; -import io.cucumber.java.en.Then; -import io.cucumber.java.en.When; - - -public class TestMatch { - - private Round round; - private CompetitionTable table; - private Match match; - - @Given("a Round exists") - public void a_round_exists() { - round = new Round(); // Assuming a default constructor exists - } - - @Given("a Competition Table exists") - public void a_competition_table_exists() { - table = new CompetitionTable(); // Assuming a default constructor exists - } - - @When("I create a new match starting at {string} and ending at {string}") - public void i_create_a_new_match(String start, String end) { - match = new Match(); - match.setStartTime(LocalTime.parse(start)); - match.setEndTime(LocalTime.parse(end)); - match.setRound(round); - match.setCompetitionTable(table); - } - - @Then("the match should be linked to the round and the table") - public void the_match_should_be_linked() { - assertNotNull(match.getRound()); - assertNotNull(match.getCompetitionTable()); - assertEquals(round, match.getRound()); - assertEquals(table, match.getCompetitionTable()); - } - - @Then("the match duration should be {string} minutes") - public void the_match_duration_should_be(String minutes) { - long duration = Duration.between(match.getStartTime(), match.getEndTime()).toMinutes(); - assertEquals(Long.parseLong(minutes), duration); - } -} diff --git a/src/test/java/cat/udl/eps/softarch/fll/steps/TestReferee.java b/src/test/java/cat/udl/eps/softarch/fll/steps/TestReferee.java deleted file mode 100644 index 1f8ca6cf..00000000 --- a/src/test/java/cat/udl/eps/softarch/fll/steps/TestReferee.java +++ /dev/null @@ -1,60 +0,0 @@ -package cat.udl.eps.softarch.fll.steps; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; -import cat.udl.eps.softarch.fll.domain.CompetitionTable; -import cat.udl.eps.softarch.fll.domain.Referee; -import io.cucumber.java.en.Given; -import io.cucumber.java.en.Then; -import io.cucumber.java.en.When; - -public class TestReferee { - - private Referee referee; - private CompetitionTable table; - - @Given("a new referee") - public void a_new_referee() { - // Usamos el constructor Referee() que está en tu clase - this.referee = new Referee(); - } - - @Given("a competition table exists with ID {string}") - public void a_competition_table_exists(String id) { - this.table = new CompetitionTable(); - this.table.setId(id); - } - - @When("I set the referee as an expert") - public void i_set_the_referee_as_an_expert() { - // Probamos setExpert(boolean expert) - this.referee.setExpert(true); - } - - @When("I assign the referee to supervise {string}") - public void i_assign_the_referee_to_supervise(String id) { - // Probamos setSupervisesTable(CompetitionTable table) - // Usamos addReferee de la mesa para mantener la bidireccionalidad - this.table.addReferee(this.referee); - } - - @Then("the referee should be recognized as an expert") - public void the_referee_should_be_recognized_as_an_expert() { - // Probamos isExpert() - assertTrue(this.referee.isExpert()); - } - - @Then("the referee should reference {string} as their assigned table") - public void the_referee_should_reference_table(String id) { - // Probamos getSupervisesTable() - assertNotNull(this.referee.getSupervisesTable()); - assertEquals(id, this.referee.getSupervisesTable().getId()); - } - - @Then("the table {string} should list the referee in its staff") - public void the_table_should_list_referee(String id) { - // Verificamos que la relación inversa también funciona - assertTrue(this.table.getReferees().contains(this.referee)); - } -} diff --git a/src/test/java/cat/udl/eps/softarch/fll/steps/TestRound.java b/src/test/java/cat/udl/eps/softarch/fll/steps/TestRound.java deleted file mode 100644 index f2cd4b41..00000000 --- a/src/test/java/cat/udl/eps/softarch/fll/steps/TestRound.java +++ /dev/null @@ -1,65 +0,0 @@ -package cat.udl.eps.softarch.fll.steps; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import cat.udl.eps.softarch.fll.domain.Match; -import cat.udl.eps.softarch.fll.domain.Round; -import io.cucumber.java.en.Given; -import io.cucumber.java.en.Then; -import io.cucumber.java.en.When; - -public class TestRound { - - private Round round; - private Match lastRemovedMatch; - - @Given("a new Round with number {int}") - public void a_new_round_with_number(Integer number) { - round = new Round(); - round.setNumber(number); - } - - @When("I add {int} new matches to this round") - public void i_add_new_matches(Integer count) { - for (int i = 0; i < count; i++) { - round.addMatch(new Match()); - } - } - - @Then("the round should contain {int} matches") - public void the_round_should_contain_matches(Integer count) { - assertEquals(count, round.getMatches().size()); - } - - @Then("each match should reference the round with number {int}") - public void each_match_should_reference_the_round(Integer number) { - for (Match m : round.getMatches()) { - assertNotNull(m.getRound()); - assertEquals(number, m.getRound().getNumber()); - } - } - - @Given("the round has {int} matches") - public void the_round_has_matches(Integer count) { - for (int i = 0; i < count; i++) { - round.addMatch(new Match()); - } - } - - @When("I remove one match from the round") - public void i_remove_one_match() { - lastRemovedMatch = round.getMatches().get(0); - round.removeMatch(lastRemovedMatch); - } - - @Then("the round should contain {int} match") - public void the_round_should_contain_single_match(Integer count) { - assertEquals(count, round.getMatches().size()); - } - - @Then("the removed match should no longer reference the round") - public void the_removed_match_no_longer_references() { - assertNull(lastRemovedMatch.getRound()); - } -}