public void testTruncateJ() throws Exception { byte[] buf = {1, 2, 3, 4, 5, 6, 7, 8}; SerialBlob serialBlob1 = new SerialBlob(buf); MockSerialBlob mockBlob = new MockSerialBlob(); mockBlob.buf = new byte[] {1, 2, 3, 4, 5, 6, 7, 8}; SerialBlob serialBlob2 = new SerialBlob(mockBlob); SerialBlob[] serialBlobs = {serialBlob1, serialBlob2}; for (SerialBlob serialBlob : serialBlobs) { serialBlob.truncate(3); assertEquals(3L, serialBlob.length()); byte[] truncatedBytes = serialBlob.getBytes(1, 3); assertTrue(Arrays.equals(new byte[] {1, 2, 3}, truncatedBytes)); try { serialBlob.truncate(-1); fail("should throw SerialException"); } catch (SerialException e) { // expected } // Non bug difference from RI, Harmony-2937 assertEquals(3L, serialBlob.length()); try { serialBlob.truncate(10); fail("should throw SerialException"); } catch (SerialException e) { // expected } } }
public void testConstructorLBlob() throws Exception { boolean isAbnormal = false; MockSerialBlob mockBlob = new MockSerialBlob(isAbnormal); SerialBlob serialBlob = new SerialBlob(mockBlob); // SerialBlob constructor initiliases with the data of given blob, // therefore, blob.getBytes is invoked. assertTrue(mockBlob.isGetBytesInvoked); assertEquals(1, serialBlob.length()); isAbnormal = true; mockBlob = new MockSerialBlob(isAbnormal); try { new SerialBlob(mockBlob); fail("should throw SQLException"); } catch (SQLException e) { // expected } try { new SerialBlob((Blob) null); fail("should throw SQLException"); } catch (SQLException e) { // expected } }
public void testConstructor$B() throws Exception { byte[] buf = new byte[8]; SerialBlob serialBlob = new SerialBlob(buf); assertEquals(8, serialBlob.length()); try { new SerialBlob((byte[]) null); fail("should throw NullPointerException"); } catch (NullPointerException e) { // expected } }