Bael 7060 (#15247)
* BAEL-7060: Converting String to ByteBuffer * BAEL-7060: Converting String to ByteBuffer (format code)
This commit is contained in:
parent
d0d42269f0
commit
111dcccb92
|
@ -1,12 +1,12 @@
|
||||||
package com.baeldung.bytebuffertostring;
|
package com.baeldung.bytebuffertostring;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import org.junit.Test;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
public class ByteArrayToStringUnitTest {
|
public class ByteArrayToStringUnitTest {
|
||||||
private static Charset charset = StandardCharsets.UTF_8;
|
private static Charset charset = StandardCharsets.UTF_8;
|
||||||
|
@ -41,4 +41,13 @@ public class ByteArrayToStringUnitTest {
|
||||||
assertEquals(content, newContent);
|
assertEquals(content, newContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void convertStringToByteBuffer_thenOk() {
|
||||||
|
byte[] expectedBytes = content.getBytes(Charset.forName(charset.toString()));
|
||||||
|
ByteBuffer byteBuffer = ByteBuffer.wrap(expectedBytes);
|
||||||
|
|
||||||
|
// Test the conversion from string to ByteBuffer
|
||||||
|
assertEquals(expectedBytes, byteBuffer.array());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue