Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.junit.runner.JUnitCore;
- import org.junit.runner.Result;
- import org.junit.runner.notification.Failure;
- public class TestRunnerStringMethods {
- public static void main(String[] args) {
- Result result = JUnitCore.runClasses(TestJunitMyIndexOf.class);
- for (Failure failure : result.getFailures()) {
- System.out.println(failure.toString());
- }
- System.out.println(result.wasSuccessful());
- }
- }
- String nullString = null;
- public static int myIndexOf(char[] str, int ch, int index) {
- if (str == null) {
- // output NullPointerException
- }
- if (str.length <= index || index < 0) {
- return -1;
- }
- for (int i = index; i < str.length; i++) {
- if (index == str[i]) {
- return i;
- }
- }
- // if not found
- return -1;
- }
- assertEquals(nullString.indexOf(3), StringMethods.myIndexOf(null, 'd',3));
- OUTPUT:
- testMyIndexOf2(TestingStringMethods.TestJunitMyIndexOf): null
- false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement