/***********************************************************************************************************
 * Name         : ConfigUtilsTest
 * Purpose      : Test class for ConfigUtils
 **********************************************************************************************************/
@isTest
private class ConfigUtilsTest {
    /************************************************************************************
     * Method: getConfigString
     * APEX method tested : ConfigUtils.getConfigString
     * Description : Verifies that a String config is retrieved
     *************************************************************************************/
    @isTest
    static void getConfigString() {
        Config__c config = new Config__c(Name = 'Key', Value__c = 'Some Value');
        insert config;

        Test.startTest();
        String result = ConfigUtils.getConfigString('Key');
        Test.stopTest();

        System.assertEquals('Some Value', result);
    }

    /************************************************************************************
     * Method: getConfigIntValid
     * APEX method tested : ConfigUtils.getConfigInt
     * Description : Verifies that an Int config is retrieved
     *************************************************************************************/
    @isTest
    static void getConfigIntValid() {
        Config__c config = new Config__c(Name = 'Key', Value__c = '99');
        insert config;

        Test.startTest();
        Integer result = ConfigUtils.getConfigInt('Key');
        Test.stopTest();

        System.assertEquals(99, result);
    }

    /************************************************************************************
     * Method: getConfigBooleanValid
     * APEX method tested : ConfigUtils.getConfigBoolean
     * Description : Verifies that a Boolean config is retrieved
     *************************************************************************************/
    @isTest
    static void getConfigBooleanValid() {
        Config__c config = new Config__c(Name = 'Key', Value__c = 'true');
        insert config;

        Test.startTest();
        Boolean result = ConfigUtils.getConfigBoolean('Key');
        Test.stopTest();

        System.assertEquals(true, result);
    }

    /************************************************************************************
     * Method: getConfigBooleanInvalid
     * APEX method tested : ConfigUtils.getConfigBoolean
     * Description : Verifies that false is returned whenever the value cannot be retrieved
     *************************************************************************************/
    @isTest
    static void getConfigBooleanInvalid() {
        Test.startTest();
        Boolean result = ConfigUtils.getConfigBoolean('Key');
        Test.stopTest();

        System.assertEquals(false, result);
    }

    /************************************************************************************
     * Method: getConfigIntInvalid
     * APEX method tested : ConfigUtils.getConfigInt
     * Description : Verifies that an exception is thrown when the config does not have an Int value
     *************************************************************************************/
    @isTest
    static void getConfigIntInvalid() {
        Config__c config = new Config__c(Name = 'Key', Value__c = 'ABC');
        insert config;

        Test.startTest();
        try {
            Integer result = ConfigUtils.getConfigInt('Key');
            System.assert(true == false);
        } catch (Exception ex) {
            System.assertEquals('System.TypeException', ex.getTypeName());
        }
        Test.stopTest();
    }

    /************************************************************************************
     * Method: getConfigMultipleStrings
     * APEX method tested : ConfigUtils.getConfigMultipleStrings
     * Description : Verifies that an Int config is retrieved
     *************************************************************************************/
    @isTest
    static void getConfigMultipleStrings() {
        Config__c config = new Config__c(Name = 'Key', Value__c = 'A;B;C');
        insert config;

        Test.startTest();
        List<String> result = ConfigUtils.getConfigMultipleStrings('Key');
        Test.stopTest();

        System.assertEquals(3, result.size());
        System.assertEquals('A', result[0]);
        System.assertEquals('B', result[1]);
        System.assertEquals('C', result[2]);
    }
}
