<commit_before>/*
 * Copyright 1999-2101 Alibaba Group.
 *  
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *  
 *      http://www.apache.org/licenses/LICENSE-2.0
 *  
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.alibaba.dubbo.common.utils;

import static org.junit.Assert.assertThat;
import static org.junit.matchers.JUnitMatchers.containsString;

import java.util.Arrays;
import java.util.List;
import java.util.Properties;

import org.junit.Assert;
import org.junit.Test;

import com.alibaba.dubbo.common.serialize.Serialization;
import com.alibaba.dubbo.common.serialize.support.dubbo.DubboSerialization;

/**
 * @author tony.chenl
 * @author ding.lid
 */
public class ConfigUtilTest {

    /**
     * 测试点1：用户配置参数在最后 测试点2：用户配置参数如果带-，会删除同名的默认参数 测试点3：default开头的默认参数会被删除
     */
    @Test
    public void testMergeValues() {
        List<String> merged = ConfigUtils.mergeValues(Serialization.class, "aaa,bbb,default.cunstom",
                                                      Arrays.asList(new String[]{"dubbo","default.hessian2","json"}));
        Assert.assertEquals("[dubbo, json, aaa, bbb, default.cunstom]",merged.toString());
    }
    
    /**
     * 测试点1：用户配置-default，会删除所有默认参数
     */
    @Test
    public void testMergeValuesDeleteDefault() {
        List<String> merged = ConfigUtils.mergeValues(DubboSerialization.class, "-default",
                                                      Arrays.asList("ddd,default.eee,ccc"));
        Assert.assertEquals("[]", merged.toString());
    }
    
    @Test
    public void test_loadProperties_noFile() throws Exception {
        Properties p = ConfigUtils.loadProperties("notExisted", true);
        Properties expected = new Properties();
        Assert.assertEquals(expected, p);

        p = ConfigUtils.loadProperties("notExisted", false);
        Assert.assertEquals(expected, p);
    }
    
    @Test
    public void test_loadProperties_oneFile() throws Exception {
        Properties p = ConfigUtils.loadProperties("properties.load", false);
        
        Properties expected = new Properties();
        expected.put("a", "12");
        expected.put("b", "34");
        expected.put("c", "56");
        
        Assert.assertEquals(expected, p);
    }
    
    @Test
    public void test_loadProperties_oneFile_allowMulti() throws Exception {
        Properties p = ConfigUtils.loadProperties("properties.load", true);
        
        Properties expected = new Properties();
        expected.put("a", "12");
        expected.put("b", "34");
        expected.put("c", "56");
        
        Assert.assertEquals(expected, p);
    }
    
    @Test
    public void test_loadProperties_oneFile_notRootPath() throws Exception {
        Properties p = ConfigUtils.loadProperties("META-INF/services/com.alibaba.dubbo.common.threadpool.ThreadPool", false);
        
        Properties expected = new Properties();
        expected.put("com.alibaba.dubbo.common.threadpool.support.fixed.FixedThreadPool", "");
        expected.put("com.alibaba.dubbo.common.threadpool.support.cached.CachedThreadPool", "");
        
        Assert.assertEquals(expected, p);
    }
    
    @Test
    public void test_loadProperties_multiFile_notRootPath_Exception() throws Exception {
        try {
            ConfigUtils.loadProperties("META-INF/services/com.alibaba.dubbo.common.status.StatusChecker", false);
        } catch (IllegalStateException expected) {
            assertThat(expected.getMessage(), containsString("only 1 META-INF/services/com.alibaba.dubbo.common.status.StatusChecker file is expected, but 2 dubbo.properties files found on class path:"));
        }
    }
    
    @Test
    public void test_loadProperties_multiFile_notRootPath() throws Exception {
        
        Properties p = ConfigUtils.loadProperties("META-INF/services/com.alibaba.dubbo.common.status.StatusChecker", true);
        
        Properties expected = new Properties();
        expected.put("com.alibaba.dubbo.common.status.support.MemoryStatusChecker", "");
        expected.put("com.alibaba.dubbo.common.status.support.LoadStatusChecker", "");
        expected.put("aa", "12");
        
        Assert.assertEquals(expected, p);
    }
    
}<commit_msg>ut修改<commit_after>/*
 * Copyright 1999-2101 Alibaba Group.
 *  
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *  
 *      http://www.apache.org/licenses/LICENSE-2.0
 *  
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.alibaba.dubbo.common.utils;

import static org.junit.Assert.assertThat;
import static org.junit.matchers.JUnitMatchers.containsString;

import java.util.Arrays;
import java.util.List;
import java.util.Properties;

import org.junit.Assert;
import org.junit.Test;

import com.alibaba.dubbo.common.serialize.Serialization;
import com.alibaba.dubbo.common.serialize.support.dubbo.DubboSerialization;

/**
 * @author tony.chenl
 * @author ding.lid
 */
public class ConfigUtilTest {

    /**
     * 测试点1：用户配置参数在最后 测试点2：用户配置参数如果带-，会删除同名的默认参数 测试点3：default开头的默认参数会被删除
     */
    @Test
    public void testMergeValues() {
        List<String> merged = ConfigUtils.mergeValues(Serialization.class, "aaa,bbb,default.cunstom",
                                                      Arrays.asList(new String[]{"dubbo","default.hessian2","json"}));
        Assert.assertEquals("[dubbo, json, aaa, bbb, default.cunstom]",merged.toString());
    }
    
    /**
     * 测试点1：用户配置-default，会删除所有默认参数
     */
    @Test
    public void testMergeValuesDeleteDefault() {
        List<String> merged = ConfigUtils.mergeValues(DubboSerialization.class, "-default",
                                                      Arrays.asList("ddd,default.eee,ccc"));
        Assert.assertEquals("[]", merged.toString());
    }
    
    @Test
    public void test_loadProperties_noFile() throws Exception {
        Properties p = ConfigUtils.loadProperties("notExisted", true);
        Properties expected = new Properties();
        Assert.assertEquals(expected, p);

        p = ConfigUtils.loadProperties("notExisted", false);
        Assert.assertEquals(expected, p);
    }
    
    @Test
    public void test_loadProperties_oneFile() throws Exception {
        Properties p = ConfigUtils.loadProperties("properties.load", false);
        
        Properties expected = new Properties();
        expected.put("a", "12");
        expected.put("b", "34");
        expected.put("c", "56");
        
        Assert.assertEquals(expected, p);
    }
    
    @Test
    public void test_loadProperties_oneFile_allowMulti() throws Exception {
        Properties p = ConfigUtils.loadProperties("properties.load", true);
        
        Properties expected = new Properties();
        expected.put("a", "12");
        expected.put("b", "34");
        expected.put("c", "56");
        
        Assert.assertEquals(expected, p);
    }
    
    @Test
    public void test_loadProperties_oneFile_notRootPath() throws Exception {
        Properties p = ConfigUtils.loadProperties("META-INF/services/com.alibaba.dubbo.common.threadpool.ThreadPool", false);
        
        Properties expected = new Properties();
        expected.put("com.alibaba.dubbo.common.threadpool.support.fixed.FixedThreadPool", "");
        expected.put("com.alibaba.dubbo.common.threadpool.support.cached.CachedThreadPool", "");
        
        Assert.assertEquals(expected, p);
    }
    
    @Test
    public void test_loadProperties_multiFile_notRootPath_Exception() throws Exception {
        try {
            ConfigUtils.loadProperties("META-INF/services/com.alibaba.dubbo.common.status.StatusChecker", false);
            Assert.fail();
        } catch (IllegalStateException expected) {
            assertThat(expected.getMessage(), containsString("only 1 META-INF/services/com.alibaba.dubbo.common.status.StatusChecker file is expected, but 2 dubbo.properties files found on class path:"));
        }
    }
    
    @Test
    public void test_loadProperties_multiFile_notRootPath() throws Exception {
        
        Properties p = ConfigUtils.loadProperties("META-INF/services/com.alibaba.dubbo.common.status.StatusChecker", true);
        
        Properties expected = new Properties();
        expected.put("com.alibaba.dubbo.common.status.support.MemoryStatusChecker", "");
        expected.put("com.alibaba.dubbo.common.status.support.LoadStatusChecker", "");
        expected.put("aa", "12");
        
        Assert.assertEquals(expected, p);
    }
    
}
{'fraction_non_alphanumeric': 0.11415623651273198, 'fraction_numerical': 0.007121277514026759, 'mean_word_length': 2.883116883116883, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7394455', 'n_tokens_mistral': 2695, 'n_tokens_neox': 2688, 'n_words': 545}