77 public void run() { 78 new StringBuilder(1); 79 }}); 80 tryCatch(" -1", new NegativeArraySizeException(), new Runnable() { 81 public void run() { 82 new StringBuilder(-1); 83 }}); 84 85 System.out.println("StringBuilder(String str)"); 86 tryCatch(" null", new NullPointerException(), new Runnable() { 87 public void run() { 88 new StringBuilder(null); 89 }}); 90 tryCatch(" foo", null, new Runnable() { 91 public void run() { 92 new StringBuilder("foo"); 93 }}); 94 95 System.out.println("StringBuilder.replace(int start, int end, String str)"); 96 tryCatch(" -1, 2, \" \"", 97 new StringIndexOutOfBoundsException(-1), 98 new Runnable() { 99 public void run() { 100 StringBuilder sb = new StringBuilder("hilbert"); 101 sb.replace(-1, 2, " "); 102 }}); 103 tryCatch(" 7, 8, \" \"", 104 new StringIndexOutOfBoundsException("start > length()"), 105 new Runnable() { 106 public void run() { 107 StringBuilder sb = new StringBuilder("banach"); 108 sb.replace(7, 8, " "); 109 }}); 110 tryCatch(" 2, 1, \" \"", 111 new StringIndexOutOfBoundsException("start > end"), 112 new Runnable() { 113 public void run() { 114 StringBuilder sb = new StringBuilder("riemann"); 115 sb.replace(2, 1, " "); 116 }}); 117 118 if (!ok) 119 throw new RuntimeException("Some tests FAILED"); 120 else 121 System.out.println("All tests PASSED"); 122 } 123 } | 77 public void run() { 78 new StringBuilder(1); 79 }}); 80 tryCatch(" -1", new NegativeArraySizeException(), new Runnable() { 81 public void run() { 82 new StringBuilder(-1); 83 }}); 84 85 System.out.println("StringBuilder(String str)"); 86 tryCatch(" null", new NullPointerException(), new Runnable() { 87 public void run() { 88 new StringBuilder(null); 89 }}); 90 tryCatch(" foo", null, new Runnable() { 91 public void run() { 92 new StringBuilder("foo"); 93 }}); 94 95 System.out.println("StringBuilder.replace(int start, int end, String str)"); 96 tryCatch(" -1, 2, \" \"", 97 new StringIndexOutOfBoundsException("start -1, end 2, length 7"), 98 new Runnable() { 99 public void run() { 100 StringBuilder sb = new StringBuilder("hilbert"); 101 sb.replace(-1, 2, " "); 102 }}); 103 tryCatch(" 7, 8, \" \"", 104 new StringIndexOutOfBoundsException("start 7, end 6, length 6"), 105 new Runnable() { 106 public void run() { 107 StringBuilder sb = new StringBuilder("banach"); 108 sb.replace(7, 8, " "); 109 }}); 110 tryCatch(" 2, 1, \" \"", 111 new StringIndexOutOfBoundsException("start 2, end 1, length 7"), 112 new Runnable() { 113 public void run() { 114 StringBuilder sb = new StringBuilder("riemann"); 115 sb.replace(2, 1, " "); 116 }}); 117 118 if (!ok) 119 throw new RuntimeException("Some tests FAILED"); 120 else 121 System.out.println("All tests PASSED"); 122 } 123 } |