I am trying to write a junit test for a method that depads a word. I am having the problem that the method is returning symbols instead of the depadded word.
My test method is
@Test
public void testReadString() throws IOException
{
String testString = "******test";
InputStream stream = new ByteArrayInputStream(testString.getBytes(StandardCharsets.UTF_8));
DataInputStream dis = new DataInputStream(stream);
String word = readString(dis, 10);
assertEquals("test", word);
}
The methods it is testing are
public static String readString(DataInputStream dis, int size) throws IOException
{
byte[] makeBytes = new byte[size * 2];// 2 bytes per char
dis.read(makeBytes); // read size characters (including padding)
return depad(makeBytes);
}
public static String depad(byte[] read)
{
//word = word.replace("*", "");
StringBuilder word = new StringBuilder();
for (int i = 0; i < read.length; i += 2)
{
char c = (char) (((read[i] & 0x00FF) << 8) + (read[i + 1] & 0x00FF));
if (c != '*')
{
word.append(c);
}
}
return word.toString();
}
The error I am getting when i run the test is test failed expected [test] but was [⨪⨪⨪瑥獴]