test/java/lang/StringBuffer/Exceptions.java

Print this page




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


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