SubString { public boolean contains(String source, String subStr){ char [] sub = subStr.toCharArray(); original = source.toCharArray(); int count = 0; int j = 0; for(int i = 0; i < original.length; i ++){ if(count == sub.length){ break; } if(j < sub.length ) { if(original[i] == sub[j]){ count++; j++; } else{ count = 0; j = 0; } } } return count == sub.length?true:false; }  boolean contains(String source, String subStr); static void main(String[] args); public char[] original; }
@Test public void setWrongSubstringShouldFalseSearch(){ SubString testContains = new SubString(); String origin = "fdfdfg"; String sub = "fdg"; boolean result = testContains.contains(origin,sub); boolean testResult = false; Assert.assertThat(result,is(testResult)); }
@Test public void setRigthSubstringShouldTrueSearch(){ SubString testContains = new SubString(); String origin = "asasdfgh"; String sub = "dfg"; boolean result = testContains.contains(origin,sub); boolean testResult = true; Assert.assertThat(result,is(testResult)); }