You could use a parameterized test:
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
import java.util.Collection;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public class MyParameterizedClassTest {
private stringString promptNameOrg;
public MyParameterizedClassTest(stringString testParameter, stringString expectedParameter) {
this.promptNameOrg = testParameter;
this.expected = expectedParameter;
}
// creates the test data
@Parameters
public static Collection<Object[]> data() {
Object[][] data = new Object[][] { { "20129142\\1234", "1234" }, { "80808080\\159;20129142\\1234", "1234" } };
return Arrays.asList(data);
}
@Test
public void extractSimplePromptNameFindsLastPartOfString() {
String simplePromptName = extractSimplePromptName(this.promptNameOrg);
Assert.assertEquals(this.expected, simplePromptName);
}
// extractSimplePromptName omitted
}
There can only be one @Test
in such a class, though.
More info can be found here.