TrimInsideOfBraceFilter implements TrimFilter { static int countPreviousContinuedBackslash(String str, int currentNotBackslashCharIndex, int count) { Assertion.on("currentNotBackslashCharIndex").mustBeGreaterThanOrEqual(currentNotBackslashCharIndex, 0); Assertion.on("count").mustBeGreaterThanOrEqual(count, 0); Character previous = null; if (currentNotBackslashCharIndex > 0) { int previousIndex = currentNotBackslashCharIndex - 1; previous = str.charAt(previousIndex); if (previous == '\\') { return countPreviousContinuedBackslash(str, previousIndex, count + 1); } else { return count; } } return count; }  @Override String trimAll(String src);  }
@Test public void countPreviousContinuedBackslash_A$String$int$int() throws Exception { String str = null; int currentNotBackslashCharIndex = 0; int count = 0; int actual = TrimInsideOfBraceFilter.countPreviousContinuedBackslash(str, currentNotBackslashCharIndex, count); int expected = 0; assertEquals(expected, actual); }
@Test public void countPreviousContinuedBackslash_A$String$int$int_intIsMinus1() throws Exception { String str = null; int currentNotBackslashCharIndex = -1; int count = -1; try { TrimInsideOfBraceFilter.countPreviousContinuedBackslash(str, currentNotBackslashCharIndex, count); fail(); } catch (JUnitHelperCoreException e) { } }
@Test public void countPreviousContinuedBackslash_A$String$int$int_intIs0() throws Exception { String str = null; int currentNotBackslashCharIndex = 0; int count = 0; int actual = TrimInsideOfBraceFilter.countPreviousContinuedBackslash(str, currentNotBackslashCharIndex, count); int expected = 0; assertThat(actual, is(equalTo(expected))); }
@Test public void countPreviousContinuedBackslash_A$String$int$int_intIs1() throws Exception { String str = "test"; int currentNotBackslashCharIndex = 1; int count = 1; int actual = TrimInsideOfBraceFilter.countPreviousContinuedBackslash(str, currentNotBackslashCharIndex, count); int expected = 1; assertThat(actual, is(equalTo(expected))); }
@Test public void countPreviousContinuedBackslash_A$String$int$int_intIs2() throws Exception { String str = "test"; int currentNotBackslashCharIndex = 2; int count = 2; int actual = TrimInsideOfBraceFilter.countPreviousContinuedBackslash(str, currentNotBackslashCharIndex, count); int expected = 2; assertThat(actual, is(equalTo(expected))); }
@Test public void countPreviousContinuedBackslash_A$String$int$int_StringIsNull() throws Exception { String str = "test"; int currentNotBackslashCharIndex = 0; int count = 0; int actual = TrimInsideOfBraceFilter.countPreviousContinuedBackslash(str, currentNotBackslashCharIndex, count); int expected = 0; assertThat(actual, is(equalTo(expected))); }
@Test public void countPreviousContinuedBackslash_A$String$int$int_StringIsEmpty() throws Exception { String str = ""; int currentNotBackslashCharIndex = 0; int count = 0; int actual = TrimInsideOfBraceFilter.countPreviousContinuedBackslash(str, currentNotBackslashCharIndex, count); int expected = 0; assertThat(actual, is(equalTo(expected))); }
@Test public void countPreviousContinuedBackslash_A$String$int$int_intIsMinValue() throws Exception { String str = ""; int currentNotBackslashCharIndex = Integer.MIN_VALUE; int count = Integer.MIN_VALUE; try { TrimInsideOfBraceFilter.countPreviousContinuedBackslash(str, currentNotBackslashCharIndex, count); fail(); } catch (JUnitHelperCoreException e) { } }
@Test public void countPreviousContinuedBackslash_A$String$int$int_intIsMaxValue() throws Exception { String str = ""; int currentNotBackslashCharIndex = Integer.MAX_VALUE; int count = Integer.MAX_VALUE; try { TrimInsideOfBraceFilter.countPreviousContinuedBackslash(str, currentNotBackslashCharIndex, count); fail(); } catch (StringIndexOutOfBoundsException e) { } }
@Test public void countPreviousContinuedBackslash_A$String$int$int_intIsRandom() throws Exception { String str = "abcdefghijklmnopqrstuvwxyz"; int currentNotBackslashCharIndex = new Random().nextInt(10); int count = new Random().nextInt(10); int actual = TrimInsideOfBraceFilter.countPreviousContinuedBackslash(str, currentNotBackslashCharIndex, count); assertThat(actual, is(greaterThanOrEqualTo(0))); assertThat(actual, is(lessThanOrEqualTo(Integer.MAX_VALUE))); }