Search in sources :

Example 6 with UserRepository

use of com.management.repositories.UserRepository in project Internet-Software-Architectures by zivko11.

the class UserManagerTest method ReadUser_ReturnsUser.

@Test
public void ReadUser_ReturnsUser() {
    // Arrange
    Mockery mock = new Mockery();
    userRepository = mock.mock(UserRepository.class);
    final User user = new User();
    user.setUserId(1);
    user.setUserActive(true);
    user.setUserName("Pero");
    user.setUserSurname("Peric");
    user.setUserAdmin('O');
    user.setUserCity("Novi Sad");
    user.setUserCreationDate(new Date());
    user.setUserEmail("pero@gmail.com");
    user.setUserPassword("123");
    user.setUserRank(0);
    user.setUserPhone(123456);
    user.setUserStateid("381");
    mock.checking(new Expectations() {

        {
            oneOf(userRepository).findOne(1);
            will(returnValue(user));
        }
    });
    UserManager manager = new UserManager(userRepository);
    // Act
    UserDTO dto = manager.Read(1);
    // Assert
    Assert.assertNotNull(dto);
    Assert.assertEquals(dto.getUserCity(), user.getUserCity());
    Assert.assertEquals(dto.getUserAdmin(), user.getUserAdmin());
    Assert.assertEquals(dto.getUserRank(), user.getUserRank());
    Assert.assertEquals(dto.getUserCity(), user.getUserCity());
    Assert.assertEquals(dto.getUserEmail(), user.getUserEmail());
    Assert.assertEquals(dto.getUserName(), user.getUserName());
    Assert.assertEquals(dto.getUserPassword(), user.getUserPassword());
    Assert.assertEquals(dto.getUserSurname(), user.getUserSurname());
    Assert.assertEquals(dto.getUserAdmin(), user.getUserAdmin());
    Assert.assertEquals(dto.getUserCreationDate(), user.getUserCreationDate());
    Assert.assertEquals(dto.getUserPhone(), user.getUserPhone());
    Assert.assertEquals(dto.getUserStateid(), user.getUserStateid());
    mock.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) UserRepository(com.management.repositories.UserRepository) User(com.management.entities.User) UserDTO(com.management.dto.UserDTO) Mockery(org.jmock.Mockery) Date(java.util.Date) Test(org.junit.Test)

Aggregations

UserRepository (com.management.repositories.UserRepository)6 Expectations (org.jmock.Expectations)6 Mockery (org.jmock.Mockery)6 Test (org.junit.Test)6 UserDTO (com.management.dto.UserDTO)5 User (com.management.entities.User)4 Date (java.util.Date)4 UserManager (com.management.managers.UserManager)3 ArrayList (java.util.ArrayList)2 List (java.util.List)1