Moved format byte to string function

This commit is contained in:
Ziver Koc 2016-04-26 14:24:16 +02:00
parent ea206cc5b5
commit e28c84efb3
5 changed files with 80 additions and 76 deletions

View file

@ -74,4 +74,29 @@ public class ByteUtilTest {
assertArrayEquals(new byte[]{0x22,0x11}, ByteUtil.getReverseByteOrder(new byte[]{0x11,0x22}));
assertArrayEquals(new byte[]{0x44,0x33,0x22,0x11}, ByteUtil.getReverseByteOrder(new byte[]{0x11,0x22,0x33,0x44}));
}
@Test
public void toFormattedStringTest(){
byte[] data = new byte[1];
assertEquals("000 00 '. '",
ByteUtil.toFormattedString(data));
data[0] = 65;
assertEquals("000 41 'A '",
ByteUtil.toFormattedString(data));
byte[] data2 = new byte[8];
data2[4] = 65;
assertEquals("000 00 00 00 00 41 00 00 00 '....A...'",
ByteUtil.toFormattedString(data2));
byte[] data3 = new byte[32];
data3[4] = 65;
assertEquals("000 00 00 00 00 41 00 00 00 '....A...'\n"+
"008 00 00 00 00 00 00 00 00 '........'\n"+
"016 00 00 00 00 00 00 00 00 '........'\n"+
"024 00 00 00 00 00 00 00 00 '........'",
ByteUtil.toFormattedString(data3));
}
}

View file

@ -25,7 +25,6 @@
package zutil;
import org.junit.Test;
import zutil.StringUtil;
import java.util.Arrays;
@ -71,30 +70,6 @@ public class StringUtilTest {
assertEquals( "aa", StringUtil.trimQuotes("\"aa\"") );
}
@Test
public void formatBytesToStringTest(){
byte[] data = new byte[1];
assertEquals("000 00 '. '",
StringUtil.formatBytesToString(data));
data[0] = 65;
assertEquals("000 41 'A '",
StringUtil.formatBytesToString(data));
byte[] data2 = new byte[8];
data2[4] = 65;
assertEquals("000 00 00 00 00 41 00 00 00 '....A...'",
StringUtil.formatBytesToString(data2));
byte[] data3 = new byte[32];
data3[4] = 65;
assertEquals("000 00 00 00 00 41 00 00 00 '....A...'\n"+
"008 00 00 00 00 00 00 00 00 '........'\n"+
"016 00 00 00 00 00 00 00 00 '........'\n"+
"024 00 00 00 00 00 00 00 00 '........'",
StringUtil.formatBytesToString(data3));
}
@Test
public void joinTest(){
assertEquals("", StringUtil.join(Arrays.asList(), ","));