I have the following method written that gets a substring from a string with the start and end index. For indexed that will go out of bounds, how do I write a test case in Junit? For example, if the string is banana and the method is run as getSubstring(3,12), the method will throw a out of bounds error. How do I write a test case that will pass when this error is shown?
public String getSubstring(int start, int end){
sub = MyString.str.substring(start, end);
return sub;
}
@Test
public void testgetSubstring() {
MyString test = new MyString();
String result = test.getSubstring(3,12);
}