Ejemplo n.º 1
0
  private void doTestSetStreamEndOfStream(ByteArray target, byte[] base, int offset)
      throws IOException {
    // Create mock, set up expected calls, and transition to
    // verification mode.
    MockInputStream stream = new MockInputStream();
    stream.read(base, offset, 1, -1, null);
    stream.activate();

    // Test.
    assertEquals("Failed to signal end of stream.", -1, target.set(0, 1, stream));

    // Make sure all expected calls were performed.
    stream.verify();
  }
Ejemplo n.º 2
0
  @Test
  public void testSetStreamWhen1LengthSlice() throws IOException {
    // Create mock, set up expected calls, and transition to
    // verification mode.
    byte[] base = new byte[] {0, 0};
    MockInputStream stream = new MockInputStream();
    stream.read(base, 1, 1, 1, null); // Will set base[1]=1.
    stream.activate();

    // Test.
    ByteArray target = new ByteArray(base, 1, 1);
    doTestSetStreamBoundaryCases(target);
    doTestSetStreamEndOfStream(target, base, 1);
    assertEquals("Should return the bytes written.", 1, target.set(0, 1, stream));
    verifySetStream(base, 1, 0, target, 1);

    // Make sure all expected calls were performed.
    stream.verify();
  }