Commit b49d448b authored by Adrián Piaček's avatar Adrián Piaček
Browse files

Fixed MatchEntity tests

parent 4a8d802b
Pipeline #140474 passed with stage
in 1 minute and 6 seconds
......@@ -8,6 +8,7 @@ import org.hibernate.annotations.GenericGenerator;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.Objects;
import java.util.UUID;
/**
......@@ -16,7 +17,6 @@ import java.util.UUID;
@Getter
@Setter
@EqualsAndHashCode
@MappedSuperclass
public abstract class BaseEntity {
......@@ -35,4 +35,19 @@ public abstract class BaseEntity {
public BaseEntity(UUID id) {
this.id = id;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null) return false;
if (getClass() != o.getClass()) return false;
BaseEntity other = (BaseEntity) o;
return id != null && id.equals(other.getId());
}
@Override
public int hashCode() {
return Objects.hash(getId());
}
}
......@@ -5,6 +5,7 @@ import lombok.Setter;
import javax.persistence.*;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
/**
......
......@@ -2,6 +2,7 @@ package cz.muni.fi.pa165.entity;
import cz.muni.fi.pa165.entity.interfaces.Viewable;
import cz.muni.fi.pa165.enums.CountryEnum;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
......@@ -11,6 +12,7 @@ import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
/**
......@@ -91,7 +93,4 @@ public class TeamEntity extends BaseEntity implements Viewable {
public void removeCoachFromTheTeam(TeamCoachEntity oldCoach) {
this.coachList.remove(oldCoach);
}
}
......@@ -161,18 +161,17 @@ public class MatchEntityTest {
match = em1.find(MatchEntity.class, matchB.getId());
Assertions.assertEquals(match.getTeams(), new HashSet<>(List.of(teamC, teamD, teamE)));
// TODO - fix
// match = em1.find(MatchEntity.class, matchC.getId());
// Assertions.assertEquals(match.getTeams(), new HashSet<>(List.of(teamA, teamC, teamF)));
//
// team = em1.find(TeamEntity.class, teamB.getId());
// Assertions.assertEquals(team.getMatches(), new HashSet<>(List.of(matchA)));
//
// team = em1.find(TeamEntity.class, teamA.getId());
// Assertions.assertEquals(team.getMatches(), new HashSet<>(List.of(matchA, matchC)));
//
// team = em1.find(TeamEntity.class, teamC.getId());
// Assertions.assertEquals(team.getMatches(), new HashSet<>(List.of(matchB,matchC)));
match = em1.find(MatchEntity.class, matchC.getId());
Assertions.assertEquals(match.getTeams(), new HashSet<>(List.of(teamA, teamC, teamF)));
team = em1.find(TeamEntity.class, teamB.getId());
Assertions.assertEquals(team.getMatches(), new HashSet<>(List.of(matchA)));
team = em1.find(TeamEntity.class, teamA.getId());
Assertions.assertEquals(team.getMatches(), new HashSet<>(List.of(matchA, matchC)));
team = em1.find(TeamEntity.class, teamC.getId());
Assertions.assertEquals(team.getMatches(), new HashSet<>(List.of(matchB,matchC)));
em1.getTransaction().commit();
} finally {
if (em1 != null) em1.close();
......
Supports Markdown
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