Add unit tests for org.apache.jorphan.util.JOrphanUtils (#472)

These tests were written using Diffblue Cover
This commit is contained in:
John Bergqvist 2019-07-10 18:02:04 +01:00 committed by Philippe M
parent 02b9d8aabb
commit 05d39754aa
1 changed files with 45 additions and 0 deletions

View File

@ -255,6 +255,12 @@ public class TestJorphanUtils {
assertEquals("abc",JOrphanUtils.trim("abc ;", " ;")); assertEquals("abc",JOrphanUtils.trim("abc ;", " ;"));
} }
@Test
public void testGetByteArraySlice() throws Exception {
Assert.assertArrayEquals(new byte[] {1, 2},
JOrphanUtils.getByteArraySlice(new byte[]{0, 1, 2, 3}, 1, 2));
}
@Test @Test
public void testbaToHexString(){ public void testbaToHexString(){
assertEquals("",JOrphanUtils.baToHexString(new byte[]{})); assertEquals("",JOrphanUtils.baToHexString(new byte[]{}));
@ -262,6 +268,13 @@ public class TestJorphanUtils {
assertEquals("0f107f8081ff",JOrphanUtils.baToHexString(new byte[]{15,16,127,-128,-127,-1})); assertEquals("0f107f8081ff",JOrphanUtils.baToHexString(new byte[]{15,16,127,-128,-127,-1}));
} }
@Test
public void testBaToHexStringSeparator(){
assertEquals("", JOrphanUtils.baToHexString(new byte[]{}, '-'));
assertEquals("00", JOrphanUtils.baToHexString(new byte[]{0}, '-'));
assertEquals("0f-10-7f-80-81-ff", JOrphanUtils.baToHexString(new byte[]{15,16,127,-128,-127,-1}, '-'));
}
@Test @Test
public void testbaToByte() throws Exception{ public void testbaToByte() throws Exception{
assertEqualsArray(new byte[]{},JOrphanUtils.baToHexBytes(new byte[]{})); assertEqualsArray(new byte[]{},JOrphanUtils.baToHexBytes(new byte[]{}));
@ -277,6 +290,13 @@ public class TestJorphanUtils {
} }
} }
@Test
public void testNullifyIfEmptyTrimmed() {
Assert.assertNull(JOrphanUtils.nullifyIfEmptyTrimmed(null));
Assert.assertNull(JOrphanUtils.nullifyIfEmptyTrimmed("\u0001"));
assertEquals("1234", JOrphanUtils.nullifyIfEmptyTrimmed("1234"));
}
@Test @Test
public void testIsBlank() { public void testIsBlank() {
assertTrue(JOrphanUtils.isBlank("")); assertTrue(JOrphanUtils.isBlank(""));
@ -295,6 +315,24 @@ public class TestJorphanUtils {
assertEquals("baulpismuth", JOrphanUtils.rightAlign(in, 6).toString()); assertEquals("baulpismuth", JOrphanUtils.rightAlign(in, 6).toString());
in = new StringBuilder("A"); in = new StringBuilder("A");
assertEquals(" A", JOrphanUtils.rightAlign(in, 8).toString()); assertEquals(" A", JOrphanUtils.rightAlign(in, 8).toString());
assertEquals(" foo",
JOrphanUtils.rightAlign(new StringBuilder("foo"), 39).toString());
}
@Test
public void testLeftAlign() {
assertEquals("foo ",
JOrphanUtils.leftAlign(new StringBuilder("foo"), 5).toString());
assertEquals("foo",
JOrphanUtils.leftAlign(new StringBuilder("foo"), 2).toString());
assertEquals("foo ",
JOrphanUtils.leftAlign(new StringBuilder("foo"), 39).toString());
}
@Test
public void testBooleanToSTRING() {
assertEquals("TRUE", JOrphanUtils.booleanToSTRING(true));
assertEquals("FALSE", JOrphanUtils.booleanToSTRING(false));
} }
@Test @Test
@ -357,4 +395,11 @@ public class TestJorphanUtils {
public void testReplaceValueWithNullSetterThatGetsCalled() { public void testReplaceValueWithNullSetterThatGetsCalled() {
JOrphanUtils.replaceValue("\\d+", "${port}", true, "80", null); JOrphanUtils.replaceValue("\\d+", "${port}", true, "80", null);
} }
@Test
public void testUnsplit() {
assertEquals("", JOrphanUtils.unsplit(new Object[] {null, null}, 0));
assertEquals("11", JOrphanUtils.unsplit(new Object[] {null, 1}, 1));
assertEquals("-26738698", JOrphanUtils.unsplit(new Object[] {-26_738_698}, 1));
}
} }