String[] result=null;
StringTokenizer st=null;
if (str!=null&&delim!=null||str!=""&&delim!=""){
st=new StringTokenizer(str,delim);}
int length=st.countTokens();
result= new String[length];
for (int i=0;i<length;i++){
result=st.nextToken();
}
return result;
}
下面是自动生成的junit:
import jtest.JT;
/**
* StringUtilTest is a unit test class for class StringUtil.
* @see StringUtil
* @author Parasoft Jtest 7.5
*/
public class StringUtilTest extends PackageTestCase {
/**
* Constructs a test case for the test specified by the name argument.
* @param name the name of the test case
* @author Parasoft Jtest 7.5
*/
public StringUtilTest(String name) {
super(name);
/*
* This constructor should not be modified. Any initialization code
* should be placed in the setUp() method instead.
*/
}
/**
* Test for method: static split(java.lang.String,java.lang.String)
* @throws Throwable Tests may throw any Throwable
* @see StringUtil#split(java.lang.String,java.lang.String)
* @author Parasoft Jtest 7.5
*/
public void testSplit1() throws Throwable {
// jtest_tested_method
String[] RETVAL = StringUtil.split((String) null, (String) null);
// NullPointerException thrown, originator is arg 1 to <Method StringUtil.split(Ljava/lang/String;Ljava/lang/String;)[Ljava/lang/String;>
// at java.util.StringTokenizer.<init>
// at java.util.StringTokenizer.<init>
// at StringUtil.split(StringUtil.java:4)
// Verified by seabreeze
}
/**
* Test for method: static split(java.lang.String,java.lang.String)
* @throws Throwable Tests may throw any Throwable
* @see StringUtil#split(java.lang.String,java.lang.String)
* @author Parasoft Jtest 7.5
*/
public void testSplit2() throws Throwable {
Throwable x0 = null;
try {
// jtest_tested_method
String[] RETVAL = StringUtil.split("", (String) null);
assertNotNull(RETVAL); // Verified by seabreeze
assertEquals(0, RETVAL.length); // Verified by seabreeze
// No exception thrown
// Verified by seabreeze
/**
* Test for method: static split(java.lang.String,java.lang.String)
* @throws Throwable Tests may throw any Throwable
* @see StringUtil#split(java.lang.String,java.lang.String)
* @author Parasoft Jtest 7.5
*/
public void testSplit3() throws Throwable {
// jtest_tested_method
String[] RETVAL = StringUtil.split("0", "");
assertNotNull(RETVAL); // Verified by seabreeze
assertEquals(1, RETVAL.length); // Verified by seabreeze
assertEquals("0", RETVAL[0]); // Verified by seabreeze
// No exception thrown
// jtest_unverified
}
/**
* Test for method: static split(java.lang.String,java.lang.String)
* @throws Throwable Tests may throw any Throwable
* @see StringUtil#split(java.lang.String,java.lang.String)
* @author Parasoft Jtest 7.5
*/
public void testSplit4() throws Throwable {
// jtest_tested_method
String[] RETVAL = StringUtil.split("0", (String) null);
// NullPointerException thrown
// at java.util.StringTokenizer.skipDelimiters(StringTokenizer.java:186)
// at java.util.StringTokenizer.countTokens(StringTokenizer.java:332)
// at StringUtil.split(StringUtil.java:14)
// jtest_unverified
}
/**
* Test for method: static split(java.lang.String,java.lang.String)
* @throws Throwable Tests may throw any Throwable
* @see StringUtil#split(java.lang.String,java.lang.String)
* @author Parasoft Jtest 7.5
*/
public void testSplit6() throws Throwable {
// jtest_tested_method
String[] RETVAL = StringUtil.split("", "");
assertNotNull(RETVAL); // Verified by seabreeze
assertEquals(0, RETVAL.length); // Verified by seabreeze
// No exception thrown
// jtest_unverified
}
/**
* Used to set up the test. This method is called by JUnit before each of
* the tests are executed.
* @see junit.framework.TestCase#setUp()
* @author Parasoft Jtest 7.5
*/
public void setUp() throws Exception {
super.setUp();
/*
* Add any necessary initialization code here (e.g., open a socket).
* Call Repository.putTemporary() to provide initialized instances of
* objects to be used when testing.
*/
// jtest.Repository.putTemporary("name", object);
_stubs_iteration = new jtest.StubIterationCounter();
}
/**
* Used to clean up after the test. This method is called by JUnit after
* each of the tests have been completed.
* @see junit.framework.TestCase#tearDown()
* @author Parasoft Jtest 7.5
*/
public void tearDown() throws Exception {
super.tearDown();
/*
* Add any necessary cleanup code here (e.g., close a socket).
*/
}
/**
* Utility main method. Runs the test cases defined in this test class.
*
* Usage: java StringUtilTest
* @param args command line arguments are not needed
* @author Parasoft Jtest 7.5
*/
public static void main(String[] args) {
// junit.textui.TestRunner will print the test results to stdout.
junit.textui.TestRunner.run(suite());
}
/**
* Create a test suite for running the tests in this class.
* IndependentTestSuite will run each test case in a separate classloader.
* @return a test suite to run all of the tests in this class
* @author Parasoft Jtest 7.5
*/
public static junit.framework.Test suite() {
return new jtest.IndependentTestSuite(
// this class
StringUtilTest.class,
// fully qualified name of the tested class
"StringUtil",
// timeout for each test in milliseconds
60000);
}
/**
* Get the class object of the class which will be tested.
* @return the class which will be tested
* @author Parasoft Jtest 7.5
*/
public Class getTestedClass() {
return StringUtil.class;
}
/**
* Used to keep track of how many times a stubbed method has been called.
* @author Parasoft Jtest 7.5
*/
private jtest.StubIterationCounter _stubs_iteration;
}
// JTEST_CURRENT_ID=-1144487551.