import org.testng.Assert;
import org.testng.annotations.Test;
public class ClassWithThrowMethod
{
public String convertString(String argument)
{
if (!argument.startsWith("Foo"))
{
throwIllegalArgumentException(argument);
}
return argument + "ly";
}
public void throwIllegalArgumentException(String argument)
{
throw new IllegalArgumentException("Illegal argument: " + argument);
}
public class ClassWithThrowMethodTest
{
@Test
public void testConvertString_Foo()
{
Assert.assertEquals(new ClassWithThrowMethod().convertString("Foo"), "Fooly");
}
@Test(expectedExceptions = IllegalArgumentException.class)
public void testConvertString_Bar()
{
new ClassWithThrowMethod().convertString("Bar");
}
}
}
public class ClassWithThrowMethod
{
public String convertString(String argument)
{
if (!argument.startsWith("Foo"))
{
// explicit throw here so JaCoCo/EclEmma will count it as visited
throw getIllegalArgumentException(argument);
}
return argument + "ly";
}
// Changed this to a get method that simply returns the exception, but does not throw it
public IllegalArgumentException getIllegalArgumentException(String argument)
{
return new IllegalArgumentException("Illegal argument: " + argument);