TextValueCleaner { public String cleanVal(@Nullable String value) { String cleanValue = value; if (cleanValue != null) { if (cleanValue.contains(TAB)) { cleanValue = cleanValue.replace(TAB, SPACE); } if (cleanValue.contains(COMA)) { cleanValue = cleanValue.replace(COMA, SPACE); } if (cleanValue.contains(NEWLINE)) { cleanValue = cleanValue.replace(NEWLINE, SPACE); } } return cleanValue; } @Inject  TextValueCleaner(); String cleanVal(@Nullable String value); String sanitizeValue(@Nullable String value);  }
@Test public void cleanValueShouldReplaceTabBySpace() { TextValueCleaner textValueCleaner = new TextValueCleaner(); String cleanedValue = textValueCleaner .cleanVal(TextValueCleaner.TAB + "abc" + TextValueCleaner.TAB); assertEquals(" abc ", cleanedValue); }
@Test public void cleanValueShouldReplaceComaBySpace() { TextValueCleaner textValueCleaner = new TextValueCleaner(); String cleanedValue = textValueCleaner .cleanVal(TextValueCleaner.COMA + "abc" + TextValueCleaner.COMA); assertEquals(" abc ", cleanedValue); }
@Test public void cleanValueShouldReplaceNewlineBySpace() { TextValueCleaner textValueCleaner = new TextValueCleaner(); String cleanedValue = textValueCleaner .cleanVal(TextValueCleaner.NEWLINE + "abc" + TextValueCleaner.NEWLINE); assertEquals(" abc ", cleanedValue); }
@Test public void cleanValueShouldReturnNullIfNullString() { TextValueCleaner textValueCleaner = new TextValueCleaner(); String cleanedValue = textValueCleaner.cleanVal(null); assertNull(cleanedValue); }
@Test public void cleanValueShouldReturnSameIfNothingToReplace() { TextValueCleaner textValueCleaner = new TextValueCleaner(); String cleanedValue = textValueCleaner.cleanVal("abc"); assertEquals("abc", cleanedValue); }