Blame view

src/test/java/org/legrog/web/account/UpdateAccountBeanTest.java 2.33 KB
1
package org.legrog.web.account;
2 3 4 5 6 7 8 9

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;
10 11
import org.legrog.entities.AccountProperty;
import org.legrog.entities.AccountRole;
12 13 14 15 16 17 18 19 20 21 22 23 24
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.
 */
25
@DisplayName("Update Account Bean")
26 27
@ExtendWith(MockitoExtension.class)
@RunWith(JUnitPlatform.class)
28
public class UpdateAccountBeanTest {
29

30
    UpdateAccountBean updateUserBean;
31 32

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

    @Test
38
    @DisplayName("depends on Shared Service and Account Service")
39 40 41 42 43 44 45 46 47
    public void testDependencies() {
        assertThat(updateUserBean).isNotNull();
    }

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

        private List<DisplayNameMask> displayNameMasks;
48 49
        private List<AccountProperty> userProperties;
        private List<AccountRole> accountRoles;
50 51 52 53 54

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

        @Test
59
        @DisplayName("should set lists of available masks, account roles, and account properties from shared service")
60 61 62 63
        public void testList(@Mock SharedService sharedService) {
            updateUserBean.init();
            assertThat(updateUserBean.getAllDisplayNameMasks()).isEqualTo(displayNameMasks);
            assertThat(updateUserBean.getAvailableUserProperties()).isEqualTo(userProperties);
64
            assertThat(updateUserBean.getAvailableAccountRoles()).isEqualTo(accountRoles);
65 66 67 68 69
        }
    }


}