MyStringUtils test

package com.spider.util;

import java.util.LinkedHashMap;

import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import junit.framework.Assert;

public class StringUtilsTest {
    private static final Logger logger=LoggerFactory.getLogger(StringUtilsTest.class);
    @Test
    public void FormatTest()
    {
        String actual=StringUtils.Format("dddddddddddd   {0}", "111");
        String expected="dddddddddddd   111";
        logger.debug(actual);
        Assert.assertEquals(expected, actual);
       
        actual=StringUtils.Format("dddddddddddd   {0}\"{1}\"", "111","22");
        expected="dddddddddddd   111\"22\"";
        Assert.assertEquals(expected, actual);
       
       
    }
    @Test
    public void HashMap2JSONStringTest()
    {
        LinkedHashMap<String, String> ht=new LinkedHashMap<String, String>();
        ht.put("ip","127.0.0.1");
        ht.put("hostname", "haha");
        ht.put("version", "20120318");
        String str=StringUtils.HashMap2JSONString(ht);
        System.out.println(str);
    }

}

原文地址:https://www.cnblogs.com/lexus/p/2406122.html