Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.89 KB | None | 0 0
  1. import org.junit.Assert;
  2. import org.junit.Test;
  3.  
  4. import javax.transaction.Transactional;
  5. import java.util.List;
  6.  
  7. /**
  8.  * All these tests assume that a parallel EMPTY db for testing purposes exists.
  9.  *
  10.  * NOTE: This is not unit testing, but integration testing. Unit tests are supposed to be
  11.  * light and fast and TEST your code, logic. They are not supposed to test 3rd party libraries.
  12.  * For example we assume and trust that Hibernate framework will do it's work, therefore we don't test if it works.
  13.  *
  14.  * It's the same as if we mock an object to return "true" and we assert if it returns "true".
  15.  */
  16.  
  17. @Transactional
  18. public class UserServiceTest
  19. {
  20.     private UserService userService = new UserService();
  21.  
  22.     @Test
  23.     void addingUserShouldWorkCorrectly()
  24.     {
  25.         userService.addUser("Pesho", "username", "neheshiranaparola", RoleType.NONE);
  26.  
  27.         Assert.assertNotNull(userService.getUserByUsername("username", false));
  28.     }
  29.  
  30.     @Test
  31.     void gettingAllUsersTest()
  32.     {
  33.         userService.addUser("test", "test", "test", RoleType.NONE);
  34.  
  35.         List<User> users = userService.getUsers();
  36.  
  37.         Assert.assertFalse(users.isEmpty());
  38.     }
  39.  
  40.     @Test
  41.     void gettingByUsernameShouldReturnCorrectData()
  42.     {
  43.         User actualUser = userService.getUserByUsername("test", false);
  44.  
  45.         Assert.assertEquals("test", actualUser.getUsername());
  46.     }
  47.  
  48.     @Test
  49.     void updateShouldReturnCorrectUserValues()
  50.     {
  51.         userService.updateUser(1, "Ivan", "username", "neheshiranaparola", RoleType.NONE)
  52.         User actualUser = userService.getUserByID(6);
  53.  
  54.         Assert.assertEquals("Ivan", actualUser.getName());
  55.         Assert.assertEquals("username", actualUser.getUsername());
  56.     }
  57.  
  58.     @Test
  59.     void deletingUserShouldWorkCorrectly()
  60.     {
  61.         userService.deleteUser(1);
  62.  
  63.         Assert.assertNull(userService.getUserByID(1));
  64.     }
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement