UpdatePersonBeanTest.java 2.25 KB
package org.legrog.web.user;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
import org.legrog.entities.DisplayNameMask;
import org.legrog.test.MockitoExtension;
import org.legrog.web.xyz.SharedService;
import org.mockito.Mock;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;

/**
 * Created by jai on 15/11/16.
 */
@DisplayName("Update Person Bean")
@ExtendWith(MockitoExtension.class)
@RunWith(JUnitPlatform.class)
public class UpdatePersonBeanTest {

    UpdateUserBean updateUserBean;

    @BeforeEach
    public void setUp(@Mock UserService userService, @Mock SharedService sharedService) throws Exception {
        updateUserBean = new UpdateUserBean(userService, sharedService) ;
    }

    @Test
    @DisplayName("depends on Shared Service and Person Service")
    public void testDependencies() {
        assertThat(updateUserBean).isNotNull();
    }

    @Nested
    @DisplayName("post construct method")
    class init {

        private List<DisplayNameMask> displayNameMasks;
        private List<org.legrog.entities.UserProperty> userProperties;
        private List<org.legrog.entities.UserRole> userRoles;

        @BeforeEach
        public void setUp(@Mock SharedService sharedService) {
            when(sharedService.getAllDisplayNameMasks()).thenReturn(displayNameMasks);
            when(sharedService.getAvailableUserProperties()).thenReturn(userProperties);
            when(sharedService.getAvailableUserRoles()).thenReturn(userRoles);
        }

        @Test
        @DisplayName("should set lists of available masks, user roles, and user properties from shared service")
        public void testList(@Mock SharedService sharedService) {
            updateUserBean.init();
            assertThat(updateUserBean.getAllDisplayNameMasks()).isEqualTo(displayNameMasks);
            assertThat(updateUserBean.getAvailableUserProperties()).isEqualTo(userProperties);
            assertThat(updateUserBean.getAvailableUserRoles()).isEqualTo(userRoles);
        }
    }


}