// This is actually already tested in FactoryTest
assertNotNull("Could not create a blob builder", builder1);
builder1.append("Hello");
builder1.append(" ");
builder1.append("World");
Blob blob1 = builder1.getAsBlob();
assertEquals(11, blob1.getLength());
BlobBuilder builder2 = factory.createBlobBuilder();
builder2.append(".");
Blob blob2 = builder2.getAsBlob();
assertEquals(1, blob2.getLength());
BlobBuilder builder3 = factory.createBlobBuilder();
Blob blob3 = builder3.getAsBlob();
assertEquals(0, blob3.getLength());
BlobBuilder builder4 = factory.createBlobBuilder();
builder4.append(blob1);
builder4.append(blob2);
builder4.append(blob3);
Blob blob4 = builder4.getAsBlob();
assertEquals(blob1.getLength() + blob2.getLength() + blob3.getLength(), blob4.getLength());
BlobBuilder builder6 = factory.createBlobBuilder();
builder6.append("\uCF8F"); // 3 bytes in utf8
builder6.append("\u00A2"); // 2 bytes in utf8
Blob blob6 = builder6.getAsBlob();
assertEquals(3 + 2, blob6.getLength());
// \uCF8F is 1100 1111 1000 1111 in UTF-16, which in UTF-8 is
// iiio 1100 io11 1110 io00 1111, where 'i' and 'o' are ones and zeroes
// introduced by the UTF-8 encoding, and '1' and '0' are the content.
// Converting these three bytes to hex gives EC BE 8F, or 236 190 143.
// Similarly, \u00A2 becomes iio0 0010 io10 0010, or C2 A2, or 194 162.
byte[] bytes6 = blob6.getBytes(0, 5);
assertEquals(5, bytes6.length);
assertEquals((byte) 236, bytes6[0]);
assertEquals((byte) 190, bytes6[1]);
assertEquals((byte) 143, bytes6[2]);
assertEquals((byte) 194, bytes6[3]);
assertEquals((byte) 162, bytes6[4]);
try {
blob6.getBytes(-1, 5);
fail("Offset must be a non-negative integer.");
} catch (JavaScriptException jse) { }
try {
blob6.getBytes(1, 999999);
fail("Length must be at most 1024.");
} catch (JavaScriptException jse) { }
try {
blob6.getBytes(1, 999);
fail("Read error during getBytes.");
} catch (JavaScriptException jse) { }
try {
blob6.getBytes(999, 1);
fail("Read error during getBytes.");
} catch (JavaScriptException jse) { }
byte[] bytes6a = blob6.slice(2).getBytes();
byte[] bytes6b = blob6.getBytes(2);
assertEquals(3, bytes6a.length);
assertEquals(3, bytes6b.length);
for (int i = 0; i < bytes6a.length; i++) {
assertEquals(bytes6a[i], bytes6b[i]);
}