From c9614a46fdaea999dc71c1a89c69c5b97511ba21 Mon Sep 17 00:00:00 2001 From: "tobi.jiri" Date: Fri, 27 Oct 2017 23:19:02 +0200 Subject: [PATCH 1/2] sportEvent test --- .idea/workspace.xml | 328 ++++++++++-------- .../cz/fi/muni/pa165/entity/SportEvent.java | 24 +- .../muni/pa165/dao/SportEventDaoImplTest.java | 69 ++++ 3 files changed, 271 insertions(+), 150 deletions(-) create mode 100644 persistence/src/test/java/cz/fi/muni/pa165/dao/SportEventDaoImplTest.java diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 439b075..1e4b2ca 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,11 +1,10 @@ - + + - - - + @@ -97,16 +96,6 @@ - - - - - - - - - - @@ -130,10 +119,11 @@ - - + + + @@ -172,8 +162,8 @@ - - + + @@ -213,11 +203,43 @@ - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -261,7 +283,7 @@ @@ -273,7 +295,6 @@ @@ -510,18 +532,18 @@ - - - + + + + - - - - + + + @@ -536,8 +558,8 @@ - - + + - + - + + + + + + + + + - + - - - - - - - - - - - - - + + + + + - - - - - + + + + + @@ -855,7 +877,7 @@ - + 1507991497543 @@ -920,43 +942,50 @@ - - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - @@ -1012,7 +1041,8 @@ - @@ -1024,12 +1054,11 @@ - @@ -1197,20 +1226,6 @@ - - - - - - - - - - - - - - @@ -1245,16 +1260,6 @@ - - - - - - - - - - @@ -1291,14 +1296,6 @@ - - - - - - - - @@ -1341,12 +1338,57 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/persistence/src/main/java/cz/fi/muni/pa165/entity/SportEvent.java b/persistence/src/main/java/cz/fi/muni/pa165/entity/SportEvent.java index 40178e6..9260b40 100644 --- a/persistence/src/main/java/cz/fi/muni/pa165/entity/SportEvent.java +++ b/persistence/src/main/java/cz/fi/muni/pa165/entity/SportEvent.java @@ -13,7 +13,7 @@ @Entity @Table(name = "SPORT_EVENT_TABLE") -public class SportEvent extends BaseEntity{ +public class SportEvent extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @@ -30,7 +30,7 @@ public class SportEvent extends BaseEntity{ @Column(nullable = false) private Date date; - @OneToMany(mappedBy="sportsMen") + @OneToMany(mappedBy = "sportsMen") private Set competitions = new HashSet<>(); @Override @@ -76,14 +76,24 @@ public void addCompetition(Competition competition) { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || !(o instanceof Competition)) return false; + if (this == o) { + return true; + } + if (o == null || !(o instanceof Competition)) { + return false; + } SportEvent that = (SportEvent) o; - if (!getName().equals(that.getName())) return false; - if (!getPlace().equals(that.getPlace())) return false; - if (!getDate().equals(that.getDate())) return false; + if (!getName().equals(that.getName())) { + return false; + } + if (!getPlace().equals(that.getPlace())) { + return false; + } + if (!getDate().equals(that.getDate())) { + return false; + } return getCompetitions().equals(that.getCompetitions()); } diff --git a/persistence/src/test/java/cz/fi/muni/pa165/dao/SportEventDaoImplTest.java b/persistence/src/test/java/cz/fi/muni/pa165/dao/SportEventDaoImplTest.java new file mode 100644 index 0000000..87d8d17 --- /dev/null +++ b/persistence/src/test/java/cz/fi/muni/pa165/dao/SportEventDaoImplTest.java @@ -0,0 +1,69 @@ +package cz.fi.muni.pa165.dao; + +import cz.fi.muni.pa165.entity.SportEvent; +import org.springframework.beans.factory.annotation.Autowired; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; +import java.util.Date; +import java.util.List; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; + +public class SportEventDaoImplTest extends BaseDaoImplTest { + + @Autowired + SportEventDao sportEventDao; + + private SportEvent sportEvent1; + private SportEvent sportEvent2; + + @BeforeMethod + public void createEvents() { + sportEvent1 = new SportEvent(); + sportEvent1.setName("OH"); + sportEvent1.setPlace("Monako"); + sportEvent1.setDate(new Date()); + + sportEvent2 = new SportEvent(); + sportEvent2.setName("MS"); + sportEvent2.setPlace("USA"); + sportEvent2.setDate(new Date()); + + sportEventDao.create(sportEvent1); + sportEventDao.create(sportEvent2); + + } + + @Test + public void findAll() { + List all = sportEventDao.findAll(); + + assertThat(all.size() == 2); + assertThat(all.get(0).getName()).isEqualTo("OH"); + assertThat(all.get(1).getName()).isEqualTo("MS"); + + } + + @Test + public void delete() { + sportEventDao.delete(sportEvent2); + + List all = sportEventDao.findAll(); + assertThat(all.size() == 1); + assertThat(all.get(0).getName()).isEqualTo("OH"); + + sportEventDao.delete(sportEvent1); + all = sportEventDao.findAll(); + assertThat(all.size() == 0); + } + + @Test + public void fail(){ + SportEvent sportEvent = new SportEvent(); + // hashcode returns NullPointerException + assertThatThrownBy(() -> sportEventDao.create(sportEvent)) + .isInstanceOf(NullPointerException.class); + } + +} \ No newline at end of file From 0265c9dda7e775341e72e39811850b197b8b9c01 Mon Sep 17 00:00:00 2001 From: "tobi.jiri" Date: Fri, 27 Oct 2017 23:28:18 +0200 Subject: [PATCH 2/2] workspace --- .idea/workspace.xml | 121 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 107 insertions(+), 14 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 1e4b2ca..3d2df70 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,10 +1,15 @@ +<<<<<<< Updated upstream +======= + + +>>>>>>> Stashed changes @@ -38,7 +43,7 @@ - + @@ -99,7 +104,7 @@ - + @@ -152,7 +157,7 @@ - + @@ -162,8 +167,13 @@ +<<<<<<< Updated upstream +======= + + +>>>>>>> Stashed changes @@ -172,7 +182,7 @@ - + @@ -182,7 +192,7 @@ - + @@ -206,13 +216,19 @@ +<<<<<<< Updated upstream +======= + + +>>>>>>> Stashed changes +<<<<<<< Updated upstream @@ -240,6 +256,13 @@ +======= + + + + + +>>>>>>> Stashed changes @@ -276,6 +299,8 @@ ma persist persi + pers + persista @@ -293,6 +318,7 @@ +<<<<<<< Updated upstream +======= + @@ -400,7 +429,8 @@ - + + @@ -408,6 +438,11 @@ + + + + + @@ -509,9 +544,8 @@