Methods Summary |
---|
private void | assertContents(byte[] expected)
MoreAsserts.assertEquals(expected, Streams.readFully(new FileInputStream(file)));
|
private void | assertOpen()
assertFalse("expected open", bridge.isClosed());
|
private void | closeAndAssertClosed()
client.close();
// Wait a beat for things to settle down
SystemClock.sleep(200);
assertTrue("expected closed", bridge.isClosed());
|
protected void | setUp()
super.setUp();
file = getContext().getFileStreamPath("meow.dat");
file.delete();
fileOs = new FileOutputStream(file);
bridge = new FileBridge();
bridge.setTargetFile(fileOs.getFD());
bridge.start();
client = new FileBridgeOutputStream(bridge.getClientSocket());
|
protected void | tearDown()
fileOs.close();
file.delete();
|
public void | testEmptyWrite()
assertOpen();
client.write(new byte[0]);
closeAndAssertClosed();
assertContents(new byte[0]);
|
public void | testGiantWrite()
final byte[] test = new byte[263401];
new Random().nextBytes(test);
assertOpen();
client.write(test);
closeAndAssertClosed();
assertContents(test);
|
public void | testNoWriteNoSync()
assertOpen();
closeAndAssertClosed();
|
public void | testNoWriteSync()
assertOpen();
client.flush();
closeAndAssertClosed();
|
public void | testRandomWrite()
final Random r = new Random();
final ByteArrayOutputStream result = new ByteArrayOutputStream();
for (int i = 0; i < 512; i++) {
final byte[] test = new byte[r.nextInt(24169)];
r.nextBytes(test);
result.write(test);
client.write(test);
client.flush();
}
closeAndAssertClosed();
assertContents(result.toByteArray());
|
public void | testWriteAfterClose()
assertOpen();
client.write("meow".getBytes(StandardCharsets.UTF_8));
closeAndAssertClosed();
try {
client.write("cake".getBytes(StandardCharsets.UTF_8));
fail("wrote after close!");
} catch (IOException expected) {
}
assertContents("meow".getBytes(StandardCharsets.UTF_8));
|
public void | testWriteNoSync()
assertOpen();
client.write("meow".getBytes(StandardCharsets.UTF_8));
closeAndAssertClosed();
assertContents("meow".getBytes(StandardCharsets.UTF_8));
|
public void | testWriteSync()
assertOpen();
client.write("cake".getBytes(StandardCharsets.UTF_8));
client.flush();
closeAndAssertClosed();
assertContents("cake".getBytes(StandardCharsets.UTF_8));
|
public void | testWriteSyncWrite()
assertOpen();
client.write("meow".getBytes(StandardCharsets.UTF_8));
client.flush();
client.write("cake".getBytes(StandardCharsets.UTF_8));
closeAndAssertClosed();
assertContents("meowcake".getBytes(StandardCharsets.UTF_8));
|