Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.junit.Assert;
- import org.junit.Test;
- import javax.transaction.Transactional;
- import java.util.List;
- /**
- * All these tests assume that a parallel EMPTY db for testing purposes exists.
- *
- * NOTE: This is not unit testing, but integration testing. Unit tests are supposed to be
- * light and fast and TEST your code, logic. They are not supposed to test 3rd party libraries.
- * For example we assume and trust that Hibernate framework will do it's work, therefore we don't test if it works.
- *
- * It's the same as if we mock an object to return "true" and we assert if it returns "true".
- */
- @Transactional
- public class UserServiceTest
- {
- private UserService userService = new UserService();
- @Test
- void addingUserShouldWorkCorrectly()
- {
- userService.addUser("Pesho", "username", "neheshiranaparola", RoleType.NONE);
- Assert.assertNotNull(userService.getUserByUsername("username", false));
- }
- @Test
- void gettingAllUsersTest()
- {
- userService.addUser("test", "test", "test", RoleType.NONE);
- List<User> users = userService.getUsers();
- Assert.assertFalse(users.isEmpty());
- }
- @Test
- void gettingByUsernameShouldReturnCorrectData()
- {
- User actualUser = userService.getUserByUsername("test", false);
- Assert.assertEquals("test", actualUser.getUsername());
- }
- @Test
- void updateShouldReturnCorrectUserValues()
- {
- userService.updateUser(1, "Ivan", "username", "neheshiranaparola", RoleType.NONE)
- User actualUser = userService.getUserByID(6);
- Assert.assertEquals("Ivan", actualUser.getName());
- Assert.assertEquals("username", actualUser.getUsername());
- }
- @Test
- void deletingUserShouldWorkCorrectly()
- {
- userService.deleteUser(1);
- Assert.assertNull(userService.getUserByID(1));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement