devinsy-utils/test/fr/devinsy/util/StringListTest.java

235 lines
3.9 KiB
Java

package fr.devinsy.util;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
/**
*
* @author Christian P. Momon
*/
public class StringListTest
{
static protected org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(StringListTest.class);
/**
*
*/
@Before
public void before()
{
BasicConfigurator.configure();
Logger.getRootLogger().setLevel(Level.ERROR);
}
/**
*
*/
@Test
public void testCharAt01()
{
//
logger.debug("===== test starting...");
//
StringList source = new StringList();
source.append("abcdefghijklm");
//
char target = source.charAt(0);
Assert.assertEquals(target, 'a');
//
target = source.charAt(4);
Assert.assertEquals(target, 'e');
//
target = source.charAt(11);
Assert.assertEquals(target, 'l');
//
logger.debug("===== test done.");
}
/**
*
*/
@Test
public void testCharAt02()
{
//
logger.debug("===== test starting...");
//
StringList source = new StringList();
source.append("abc");
source.append("def");
source.append("ghi");
source.append("jkl");
source.append("mno");
//
char target = source.charAt(0);
Assert.assertEquals('a', target);
//
target = source.charAt(4);
Assert.assertEquals('e', target);
//
target = source.charAt(11);
Assert.assertEquals('l', target);
//
logger.debug("===== test done.");
}
/**
*
*/
@Test(expected = IndexOutOfBoundsException.class)
public void testCharAtException01()
{
//
logger.debug("===== test starting...");
//
StringList source = new StringList();
source.append("abcdefghijklm");
//
char target = source.charAt(-2);
Assert.assertEquals('a', target);
//
logger.debug("===== test done.");
}
/**
*
*/
@Test(expected = IndexOutOfBoundsException.class)
public void testCharAtException02()
{
//
logger.debug("===== test starting...");
//
StringList source = new StringList();
source.append("abcdefghijklm");
//
char target = source.charAt(100);
Assert.assertEquals('a', target);
//
logger.debug("===== test done.");
}
/**
*
*/
@Test(expected = IndexOutOfBoundsException.class)
public void testCharAtException03()
{
//
logger.debug("===== test starting...");
//
StringList source = new StringList();
source.append("abcdefghijklm");
//
char target = source.charAt(source.length());
Assert.assertEquals('a', target);
//
logger.debug("===== test done.");
}
/**
*
*/
@Test
public void testSubstring01()
{
//
logger.debug("===== test starting...");
//
StringList source = new StringList();
source.append("hamburger");
//
StringList target = source.substring(4, 8);
Assert.assertEquals("urge", target.toString());
//
logger.debug("===== test done.");
}
/**
*
*/
@Test
public void testSubstring02()
{
//
logger.debug("===== test starting...");
//
StringList source = new StringList();
source.append("ham").append("bur").append("ger");
//
StringList target = source.substring(4, 8);
Assert.assertEquals("urge", target.toString());
//
logger.debug("===== test done.");
}
/**
*/
@Test
public void testSubstring03()
{
//
logger.debug("===== test starting...");
//
StringList source = new StringList();
source.append("smiles");
//
StringList target = source.substring(1, 5);
Assert.assertEquals("mile", target.toString());
//
logger.debug("===== test done.");
}
/**
*/
@Test
public void testSubstring04()
{
//
logger.debug("===== test starting...");
//
StringList source = new StringList();
source.append("sm").append("il").append("es");
//
StringList target = source.substring(1, 5);
Assert.assertEquals("mile", target.toString());
//
logger.debug("===== test done.");
}
}