Trim message bodies at display time.

This commit is contained in:
Greyson Parrelli
2020-11-12 12:18:20 -05:00
committed by GitHub
parent 3b2a5f1ce3
commit 554aa1ddf0
3 changed files with 88 additions and 1 deletions

View File

@@ -0,0 +1,59 @@
package org.thoughtcrime.securesms.util;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.util.Arrays;
import java.util.Collection;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
@RunWith(Parameterized.class)
public final class StringUtilTest_trim {
private final CharSequence input;
private final CharSequence expected;
private final boolean changed;
@Parameterized.Parameters
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][]{
{ "", "", false },
{ " ", "", true },
{ " ", "", true },
{ "\n", "", true},
{ "\n\n\n", "", true },
{ "A", "A", false },
{ "A ", "A", true },
{ " A", "A", true },
{ " A ", "A", true },
{ "\nA\n", "A", true },
{ "A\n\n", "A", true },
{ "A\n\nB", "A\n\nB", false },
{ "A\n\nB ", "A\n\nB", true },
{ "A B", "A B", false },
});
}
public StringUtilTest_trim(CharSequence input, CharSequence expected, boolean changed) {
this.input = input;
this.expected = expected;
this.changed = changed;
}
@Test
public void trim() {
CharSequence output = StringUtil.trim(input);
assertEquals(expected, output);
if (changed) {
assertNotSame(output, input);
} else {
assertSame(output, input);
}
}
}