From a1f17d271fe53b5f6f9cb0cc7a85a28004179cbb Mon Sep 17 00:00:00 2001 From: Filip Izydorczyk Date: Sat, 24 Oct 2020 17:51:16 +0200 Subject: [PATCH] WE HAVE THE GOD DMAN TEST --- .../java/com/plannaplan/entities/User.java | 1 - .../plannaplan/services/UserServiceTest.java | 32 +++++++++++++++++-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/buisnesslogic/src/main/java/com/plannaplan/entities/User.java b/buisnesslogic/src/main/java/com/plannaplan/entities/User.java index f21db21..d62384c 100755 --- a/buisnesslogic/src/main/java/com/plannaplan/entities/User.java +++ b/buisnesslogic/src/main/java/com/plannaplan/entities/User.java @@ -9,7 +9,6 @@ import javax.persistence.Id; import com.plannaplan.types.UserRoles; -//should setter be public? @Entity public class User { @Id diff --git a/buisnesslogic/src/test/java/com/plannaplan/services/UserServiceTest.java b/buisnesslogic/src/test/java/com/plannaplan/services/UserServiceTest.java index 15a7b59..256ec90 100755 --- a/buisnesslogic/src/test/java/com/plannaplan/services/UserServiceTest.java +++ b/buisnesslogic/src/test/java/com/plannaplan/services/UserServiceTest.java @@ -7,6 +7,8 @@ import org.springframework.test.context.junit4.SpringRunner; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.util.List; + import com.plannaplan.entities.User; import com.plannaplan.exceptions.UserNotFoundException; import com.plannaplan.types.UserRoles; @@ -55,16 +57,40 @@ public class UserServiceTest { @Test public void shouldFindStudents() { - assertTrue(false); + this.userService.save(new User("Nemo", "TheFish", "Nemo@shouldFindStudents.test", UserRoles.STUDENT)); + final List response = this.userService.searchForStudents("Nemo"); + assertTrue(response.size() >= 1); + assertTrue(containsName(response, "Nemo")); } @Test public void shouldReturnAllStudents() { - assertTrue(false); + final User veryWantedUser = new User("Xavier", "123", "Xavier@shouldReturnAllStudents.test", UserRoles.STUDENT); + final User littleLessWanted = new User("Ravier", "321", "Ravier@shouldReturnAllStudents.test", + UserRoles.STUDENT); + final User notWantadUser = new User("Fiona", "Raskolnikov", "Fiona@shouldReturnAllStudents.test", + UserRoles.DEANERY); + + this.userService.save(veryWantedUser); + this.userService.save(littleLessWanted); + this.userService.save(notWantadUser); + + final List response = this.userService.searchForStudents(""); + assertTrue(response.size() >= 2); + assertTrue(!containsName(response, notWantadUser.getName())); + assertTrue(containsName(response, littleLessWanted.getName())); + assertTrue(containsName(response, veryWantedUser.getName())); } @Test public void shouldntFindStudents() { - assertTrue(false); + this.userService.save(new User("Nadia", "Ladia", "Nadia@shouldntFindStudents.test", UserRoles.STUDENT)); + final List response = this.userService.searchForStudents( + "THISisIMPOIBLEQUEryThatShouldntReturnAnyPersonAtAllfnjiasdfjivlsdfnjgklsomerandomcharsjustinCaseXD"); + assertTrue(response.size() == 0); + } + + private boolean containsName(final List list, final String name) { + return list.stream().map(User::getName).filter(name::equals).findFirst().isPresent(); } }