package com.cf.imes.module.system.enums.oauth2;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;

/**
 * {@link OAuth2GrantTypeEnum} 的单元测试
 */
class OAuth2GrantTypeEnumTest {

    @Test
    void testEnumValues() {
        // 测试枚举值是否正确
        assertEquals("password", OAuth2GrantTypeEnum.PASSWORD.getGrantType());
        assertEquals("authorization_code", OAuth2GrantTypeEnum.AUTHORIZATION_CODE.getGrantType());
        assertEquals("implicit", OAuth2GrantTypeEnum.IMPLICIT.getGrantType());
        assertEquals("client_credentials", OAuth2GrantTypeEnum.CLIENT_CREDENTIALS.getGrantType());
        assertEquals("refresh_token", OAuth2GrantTypeEnum.REFRESH_TOKEN.getGrantType());
    }

    @Test
    void testGetByGranType() {
        // 测试 getByGranType 方法
        assertEquals(OAuth2GrantTypeEnum.PASSWORD, OAuth2GrantTypeEnum.getByGranType("password"));
        assertEquals(OAuth2GrantTypeEnum.AUTHORIZATION_CODE, OAuth2GrantTypeEnum.getByGranType("authorization_code"));
        assertEquals(OAuth2GrantTypeEnum.IMPLICIT, OAuth2GrantTypeEnum.getByGranType("implicit"));
        assertEquals(OAuth2GrantTypeEnum.CLIENT_CREDENTIALS, OAuth2GrantTypeEnum.getByGranType("client_credentials"));
        assertEquals(OAuth2GrantTypeEnum.REFRESH_TOKEN, OAuth2GrantTypeEnum.getByGranType("refresh_token"));
        assertNull(OAuth2GrantTypeEnum.getByGranType("non_existent_type")); // 不存在的类型
        assertNull(OAuth2GrantTypeEnum.getByGranType(null)); // null值
    }
}