@Test public void shouldReplaceSpacesWithTheStatementCharWithMoreThanOneSpace() { char[] input = new char[13]; input[0] = 'p'; input[1] = 'e'; input[2] = ' '; input[3] = 'd'; input[4] = 'r'; input[5] = 'o'; input[6] = ' '; input[7] = 'g'; input[8] = 's'; replaceSpaces.replace(input); assertArrayEquals( new char[] { 'p', 'e', '%', '2', '0', 'd', 'r', 'o', '%', '2', '0', 'g', 's' }, input); }
public void replace(char[] input) { validateInput(input); char[] result = new char[input.length]; for (int i = 0, j = 0; i < input.length && j < input.length; i++, j++) { if (input[i] == ' ') { result[j++] = '%'; result[j++] = '2'; result[j] = '0'; } else { result[j] = input[i]; } } copyArray(result, input); }
ReplaceSpaces { public void replace(char[] input) { validateInput(input); char[] result = new char[input.length]; for (int i = 0, j = 0; i < input.length && j < input.length; i++, j++) { if (input[i] == ' ') { result[j++] = '%'; result[j++] = '2'; result[j] = '0'; } else { result[j] = input[i]; } } copyArray(result, input); } }
ReplaceSpaces { public void replace(char[] input) { validateInput(input); char[] result = new char[input.length]; for (int i = 0, j = 0; i < input.length && j < input.length; i++, j++) { if (input[i] == ' ') { result[j++] = '%'; result[j++] = '2'; result[j] = '0'; } else { result[j] = input[i]; } } copyArray(result, input); }  }
ReplaceSpaces { public void replace(char[] input) { validateInput(input); char[] result = new char[input.length]; for (int i = 0, j = 0; i < input.length && j < input.length; i++, j++) { if (input[i] == ' ') { result[j++] = '%'; result[j++] = '2'; result[j] = '0'; } else { result[j] = input[i]; } } copyArray(result, input); }  void replace(char[] input); void replace2(char[] input); }
ReplaceSpaces { public void replace(char[] input) { validateInput(input); char[] result = new char[input.length]; for (int i = 0, j = 0; i < input.length && j < input.length; i++, j++) { if (input[i] == ' ') { result[j++] = '%'; result[j++] = '2'; result[j] = '0'; } else { result[j] = input[i]; } } copyArray(result, input); }  void replace(char[] input); void replace2(char[] input);  }