UpdateAccountBeanTest.java 2.33 KB
package org.legrog.web.account;

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.AccountProperty;
import org.legrog.entities.AccountRole;
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 Account Bean")
@ExtendWith(MockitoExtension.class)
@RunWith(JUnitPlatform.class)
public class UpdateAccountBeanTest {

    UpdateAccountBean updateUserBean;

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

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

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

        private List<DisplayNameMask> displayNameMasks;
        private List<AccountProperty> userProperties;
        private List<AccountRole> accountRoles;

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

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


}