added appendArray function

This commit is contained in:
Shekhar Gulati
2016-05-03 19:14:24 +05:30
parent 04aa5e0b36
commit 425f02bdc4
2 changed files with 20 additions and 0 deletions
+4
View File
@@ -16,6 +16,10 @@ public interface Strman {
* @return full string
*/
static String append(final String value, final String... appends) throws IllegalArgumentException {
return appendArray(value, appends);
}
static String appendArray(String value, String[] appends) {
if (value == null) {
throw new IllegalArgumentException("'value' should be not null.");
}
+16
View File
@@ -5,6 +5,7 @@ import org.junit.Test;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;
import static strman.Strman.append;
import static strman.Strman.appendArray;
public class StrmanTest {
@@ -19,4 +20,19 @@ public class StrmanTest {
public void appendShouldThrowIllegalArgumentExceptionWhenValueIsNull() throws Exception {
append(null);
}
@Test
public void shouldAppendStringArrayToEndOfValue() throws Exception {
assertThat(appendArray("f", new String[]{"o", "o", "b", "a", "r"}), equalTo("foobar"));
assertThat(appendArray("foobar", new String[]{}), equalTo("foobar"));
assertThat(appendArray("", new String[]{"foobar"}), equalTo("foobar"));
}
@Test(expected = IllegalArgumentException.class)
public void appendArrayShouldThrowIllegalArgumentExceptionWhenValueIsNull() throws Exception {
appendArray(null, new String[]{});
}
}