Add tests for missed branches in StringUtils (closes #135)
Side effect: close pull requests which have been merged, but have not been closed due to missing commit comments (close #115, close #120, close #128, close #130).
This commit is contained in:
parent
8acb1d2b42
commit
2b52dedd56
|
@ -360,6 +360,9 @@ public class StringUtilsTest {
|
||||||
assertNull(StringUtils.join((char[]) null, ','));
|
assertNull(StringUtils.join((char[]) null, ','));
|
||||||
assertEquals("1;2", StringUtils.join(CHAR_PRIM_LIST, SEPARATOR_CHAR));
|
assertEquals("1;2", StringUtils.join(CHAR_PRIM_LIST, SEPARATOR_CHAR));
|
||||||
assertEquals("2", StringUtils.join(CHAR_PRIM_LIST, SEPARATOR_CHAR, 1, 2));
|
assertEquals("2", StringUtils.join(CHAR_PRIM_LIST, SEPARATOR_CHAR, 1, 2));
|
||||||
|
assertNull(StringUtils.join((char[]) null, SEPARATOR_CHAR, 0, 1));
|
||||||
|
assertEquals(StringUtils.EMPTY, StringUtils.join(CHAR_PRIM_LIST, SEPARATOR_CHAR, 0, 0));
|
||||||
|
assertEquals(StringUtils.EMPTY, StringUtils.join(CHAR_PRIM_LIST, SEPARATOR_CHAR, 1, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -367,6 +370,9 @@ public class StringUtilsTest {
|
||||||
assertNull(StringUtils.join((byte[]) null, ','));
|
assertNull(StringUtils.join((byte[]) null, ','));
|
||||||
assertEquals("1;2", StringUtils.join(BYTE_PRIM_LIST, SEPARATOR_CHAR));
|
assertEquals("1;2", StringUtils.join(BYTE_PRIM_LIST, SEPARATOR_CHAR));
|
||||||
assertEquals("2", StringUtils.join(BYTE_PRIM_LIST, SEPARATOR_CHAR, 1, 2));
|
assertEquals("2", StringUtils.join(BYTE_PRIM_LIST, SEPARATOR_CHAR, 1, 2));
|
||||||
|
assertNull(StringUtils.join((byte[]) null, SEPARATOR_CHAR, 0, 1));
|
||||||
|
assertEquals(StringUtils.EMPTY, StringUtils.join(BYTE_PRIM_LIST, SEPARATOR_CHAR, 0, 0));
|
||||||
|
assertEquals(StringUtils.EMPTY, StringUtils.join(BYTE_PRIM_LIST, SEPARATOR_CHAR, 1, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -374,6 +380,9 @@ public class StringUtilsTest {
|
||||||
assertNull(StringUtils.join((int[]) null, ','));
|
assertNull(StringUtils.join((int[]) null, ','));
|
||||||
assertEquals("1;2", StringUtils.join(INT_PRIM_LIST, SEPARATOR_CHAR));
|
assertEquals("1;2", StringUtils.join(INT_PRIM_LIST, SEPARATOR_CHAR));
|
||||||
assertEquals("2", StringUtils.join(INT_PRIM_LIST, SEPARATOR_CHAR, 1, 2));
|
assertEquals("2", StringUtils.join(INT_PRIM_LIST, SEPARATOR_CHAR, 1, 2));
|
||||||
|
assertNull(StringUtils.join((int[]) null, SEPARATOR_CHAR, 0, 1));
|
||||||
|
assertEquals(StringUtils.EMPTY, StringUtils.join(INT_PRIM_LIST, SEPARATOR_CHAR, 0, 0));
|
||||||
|
assertEquals(StringUtils.EMPTY, StringUtils.join(INT_PRIM_LIST, SEPARATOR_CHAR, 1, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -381,6 +390,9 @@ public class StringUtilsTest {
|
||||||
assertNull(StringUtils.join((long[]) null, ','));
|
assertNull(StringUtils.join((long[]) null, ','));
|
||||||
assertEquals("1;2", StringUtils.join(LONG_PRIM_LIST, SEPARATOR_CHAR));
|
assertEquals("1;2", StringUtils.join(LONG_PRIM_LIST, SEPARATOR_CHAR));
|
||||||
assertEquals("2", StringUtils.join(LONG_PRIM_LIST, SEPARATOR_CHAR, 1, 2));
|
assertEquals("2", StringUtils.join(LONG_PRIM_LIST, SEPARATOR_CHAR, 1, 2));
|
||||||
|
assertNull(StringUtils.join((long[]) null, SEPARATOR_CHAR, 0, 1));
|
||||||
|
assertEquals(StringUtils.EMPTY, StringUtils.join(LONG_PRIM_LIST, SEPARATOR_CHAR, 0, 0));
|
||||||
|
assertEquals(StringUtils.EMPTY, StringUtils.join(LONG_PRIM_LIST, SEPARATOR_CHAR, 1, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -388,6 +400,9 @@ public class StringUtilsTest {
|
||||||
assertNull(StringUtils.join((float[]) null, ','));
|
assertNull(StringUtils.join((float[]) null, ','));
|
||||||
assertEquals("1.0;2.0", StringUtils.join(FLOAT_PRIM_LIST, SEPARATOR_CHAR));
|
assertEquals("1.0;2.0", StringUtils.join(FLOAT_PRIM_LIST, SEPARATOR_CHAR));
|
||||||
assertEquals("2.0", StringUtils.join(FLOAT_PRIM_LIST, SEPARATOR_CHAR, 1, 2));
|
assertEquals("2.0", StringUtils.join(FLOAT_PRIM_LIST, SEPARATOR_CHAR, 1, 2));
|
||||||
|
assertNull(StringUtils.join((float[]) null, SEPARATOR_CHAR, 0, 1));
|
||||||
|
assertEquals(StringUtils.EMPTY, StringUtils.join(FLOAT_PRIM_LIST, SEPARATOR_CHAR, 0, 0));
|
||||||
|
assertEquals(StringUtils.EMPTY, StringUtils.join(FLOAT_PRIM_LIST, SEPARATOR_CHAR, 1, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -395,6 +410,9 @@ public class StringUtilsTest {
|
||||||
assertNull(StringUtils.join((double[]) null, ','));
|
assertNull(StringUtils.join((double[]) null, ','));
|
||||||
assertEquals("1.0;2.0", StringUtils.join(DOUBLE_PRIM_LIST, SEPARATOR_CHAR));
|
assertEquals("1.0;2.0", StringUtils.join(DOUBLE_PRIM_LIST, SEPARATOR_CHAR));
|
||||||
assertEquals("2.0", StringUtils.join(DOUBLE_PRIM_LIST, SEPARATOR_CHAR, 1, 2));
|
assertEquals("2.0", StringUtils.join(DOUBLE_PRIM_LIST, SEPARATOR_CHAR, 1, 2));
|
||||||
|
assertNull(StringUtils.join((double[]) null, SEPARATOR_CHAR, 0, 1));
|
||||||
|
assertEquals(StringUtils.EMPTY, StringUtils.join(DOUBLE_PRIM_LIST, SEPARATOR_CHAR, 0, 0));
|
||||||
|
assertEquals(StringUtils.EMPTY, StringUtils.join(DOUBLE_PRIM_LIST, SEPARATOR_CHAR, 1, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -402,6 +420,9 @@ public class StringUtilsTest {
|
||||||
assertNull(StringUtils.join((short[]) null, ','));
|
assertNull(StringUtils.join((short[]) null, ','));
|
||||||
assertEquals("1;2", StringUtils.join(SHORT_PRIM_LIST, SEPARATOR_CHAR));
|
assertEquals("1;2", StringUtils.join(SHORT_PRIM_LIST, SEPARATOR_CHAR));
|
||||||
assertEquals("2", StringUtils.join(SHORT_PRIM_LIST, SEPARATOR_CHAR, 1, 2));
|
assertEquals("2", StringUtils.join(SHORT_PRIM_LIST, SEPARATOR_CHAR, 1, 2));
|
||||||
|
assertNull(StringUtils.join((short[]) null, SEPARATOR_CHAR, 0, 1));
|
||||||
|
assertEquals(StringUtils.EMPTY, StringUtils.join(SHORT_PRIM_LIST, SEPARATOR_CHAR, 0, 0));
|
||||||
|
assertEquals(StringUtils.EMPTY, StringUtils.join(SHORT_PRIM_LIST, SEPARATOR_CHAR, 1, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1362,6 +1383,13 @@ public class StringUtilsTest {
|
||||||
// Test null safety inside arrays - LANG-552
|
// Test null safety inside arrays - LANG-552
|
||||||
assertEquals(StringUtils.replaceEach("aba", new String[]{"a"}, new String[]{null}), "aba");
|
assertEquals(StringUtils.replaceEach("aba", new String[]{"a"}, new String[]{null}), "aba");
|
||||||
assertEquals(StringUtils.replaceEach("aba", new String[]{"a", "b"}, new String[]{"c", null}), "cbc");
|
assertEquals(StringUtils.replaceEach("aba", new String[]{"a", "b"}, new String[]{"c", null}), "cbc");
|
||||||
|
|
||||||
|
try {
|
||||||
|
StringUtils.replaceEach("abba", new String[]{"a"}, new String[]{"b", "a"});
|
||||||
|
fail("StringUtils.replaceEach(String, String[], String[]) expecting IllegalArgumentException");
|
||||||
|
} catch (final IllegalArgumentException ex) {
|
||||||
|
// expected
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue