WE HAVE THE GOD DMAN TEST

This commit is contained in:
Filip Izydorczyk 2020-10-24 17:51:16 +02:00
parent 6384f3d9b9
commit a1f17d271f
2 changed files with 29 additions and 4 deletions

View File

@ -9,7 +9,6 @@ import javax.persistence.Id;
import com.plannaplan.types.UserRoles;
//should setter be public?
@Entity
public class User {
@Id

View File

@ -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<User> 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<User> 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<User> response = this.userService.searchForStudents(
"THISisIMPOIBLEQUEryThatShouldntReturnAnyPersonAtAllfnjiasdfjivlsdfnjgklsomerandomcharsjustinCaseXD");
assertTrue(response.size() == 0);
}
private boolean containsName(final List<User> list, final String name) {
return list.stream().map(User::getName).filter(name::equals).findFirst().isPresent();
}
}