// depending on the object in 'client' the strings in 'tests' should // probably be changed!! (Needs some thought if additional Splitters // are implemented. public void testGeneric1() { for (int i = 0; i < tests.length; i++) { store.clear(); client.split(store, new StringBuffer(tests[i][0]), 0); assertEquals(tests[i].length, store.getNumParts()); StringBuffer sb = new StringBuffer(); store.getPart(sb, 0); assertEquals(tests[i][0], sb.toString()); for (int j = 1; j < tests[i].length; j++) { sb.setLength(0); store.getPart(sb, j); assertEquals("loop with j=" + j, tests[i][j], sb.toString()); } } }
public void testBeforeSplit3() { StringBuffer sb = new StringBuffer(); Exception e = null; store.getPart(sb, 0); assertEquals("", sb.toString()); // try { // store.getPart(sb, 0); // } catch( ArrayIndexOutOfBoundsException _e ){ // e = _e; // } // assertTrue(e instanceof ArrayIndexOutOfBoundsException); }
public void testSubstring() { client.split(store, new StringBuffer(testAIn), 3); StringBuffer sb = new StringBuffer(); for (int i = 0; i < 2; i++) { int L = testAOut[i].length(); sb.setLength(0); store.getPart(sb, i); assertEquals("i=" + i, testAOut[i], sb.toString()); assertEquals("i=" + i, testAOut[i].length(), store.getPartLen(i)); sb.setLength(0); store.getPart(sb, i, 1, -1); assertEquals("i=" + i, testAOut[i].substring(1, L - 1), sb.toString()); sb.setLength(0); store.getPart(sb, i, -3, 0); assertEquals(testAOut[i].substring(L - 3, L), sb.toString()); sb.setLength(0); store.getPart(sb, i, 2, 2); assertEquals("", sb.toString()); sb.setLength(0); store.getPart(sb, i, 2, 3); assertEquals(testAOut[i].substring(2, 3), sb.toString()); // test left index too small sb.setLength(0); store.getPart(sb, i, -100, 0); assertEquals(testAOut[i], sb.toString()); // Exception e = null; // try { // store.getPart(sb, i, -100, 0); // System.out.println("*************"+sb); // } catch( Exception _e) { // e = _e; // } // assertTrue(e instanceof StringIndexOutOfBoundsException); // test left index much too large sb.setLength(0); store.getPart(sb, i, 10000, 0); assertEquals("", sb.toString()); // e = null; // try { // store.getPart(sb, i, 10000, 0); // } catch( Exception _e) { // e = _e; // } // assertTrue(e instanceof StringIndexOutOfBoundsException); // test right index too small sb.setLength(0); store.getPart(sb, i, 0, -10000); assertEquals("", sb.toString()); // e = null; // try { // store.getPart(sb, i, 0, -10000); // } catch( Exception _e) { // e = _e; // } // assertTrue(e instanceof StringIndexOutOfBoundsException); // test right index far too large sb.setLength(0); store.getPart(sb, i, 0, 10000); assertEquals(testAOut[i], sb.toString()); // e = null; // try { // store.getPart(sb, i, 0, 10000); // } catch( Exception _e) { // e = _e; // } // assertTrue(e instanceof StringIndexOutOfBoundsException); // out of range part should return empty string sb.setLength(0); store.getPart(sb, 299, 0, 10000); assertEquals("", sb.toString()); // e = null; // try { // store.getPart(sb, 1000, 0, 1); // } catch( Exception _e) { // e = _e; // } // assertTrue(e instanceof ArrayIndexOutOfBoundsException); // yet another one, this time in getPartLen assertEquals(0, store.getPartLen(1000)); // e = null; // try { // store.getPartLen(1000); // } catch( Exception _e) { // e = _e; // } // assertTrue(e instanceof ArrayIndexOutOfBoundsException); } }