Source:
<code>public void logBasicTest() throws IOException { File tempFile = tempFile(); RandomAccessFile randomFile = new RandomAccessFile(tempFile.getParent() + File.separator + "log_current", "rw"); randomFile.setLength(5000); <START> File logFile = new File(tempFile.getParent(), "log_current"); <END> logFile.deleteOnExit(); ReadableMetricsRegistry registry = new MetricsRegistryMap(); StoreMetrics metrics = new StoreMetrics("test", registry); Log logTest = new Log(tempFile.getParent(), metrics, 5000); byte[] testbuf = new byte[1000]; new Random().nextBytes(testbuf); int written = logTest.appendFrom(ByteBuffer.wrap(testbuf)); Assert.assertEquals(written, 1000); Assert.assertEquals(logTest.sizeInBytes(), 1000); long writtenFromChannel = logTest.appendFrom(Channels.newChannel(new ByteBufferInputStream(ByteBuffer.wrap(testbuf))), 1000); Assert.assertEquals(writtenFromChannel, 1000); Assert.assertEquals(logTest.sizeInBytes(), 2000); written = logTest.appendFrom(ByteBuffer.wrap(testbuf)); Assert.assertEquals(written, 1000); Assert.assertEquals(logTest.sizeInBytes(), 3000); ByteBuffer result = ByteBuffer.allocate(3000); logTest.readInto(result, 0); byte[] expectedAns = new byte[3000]; System.arraycopy(testbuf, 0, expectedAns, 0, 1000); System.arraycopy(testbuf, 0, expectedAns, 1000, 1000); System.arraycopy(testbuf, 0, expectedAns, 2000, 1000); Assert.assertArrayEquals(result.array(), expectedAns); result.clear(); result.limit(1000); logTest.readInto(result, 0); Assert.assertEquals(result.limit(), 1000); result.limit(2000); logTest.readInto(result, 1000); Assert.assertEquals(result.limit(), 2000); result.limit(3000); logTest.readInto(result, 2000); Assert.assertEquals(result.limit(), 3000); Assert.assertArrayEquals(result.array(), expectedAns); logTest.flush(); Assert.assertEquals(randomFile.length(), 5000); Assert.assertEquals(logTest.sizeInBytes(), 3000); tempFile.delete(); }</code><technical_language>log_current argument Log instead of a constant? Or, name of file a public constant? I dislike test "internals" (i.e., name of file) of Log</technical_language>

Target:
public void logBasicTest() { try { File tempFile = tempFile(); RandomAccessFile randomFile = new RandomAccessFile(tempFile.getParent() + File.separator + "log_current", "rw"); randomFile.setLength(5000); File logFile = new File(tempFile.getParent(), "log_current"); logFile.deleteOnExit(); ReadableMetricsRegistry registry = new MetricsRegistryMap(); StoreMetrics metrics = new StoreMetrics("test", registry); Log logTest = new Log(tempFile.getParent(), metrics, 5000); byte[] testbuf = new byte[1000]; new Random().nextBytes(testbuf); int written = logTest.appendFrom(ByteBuffer.wrap(testbuf)); Assert.assertEquals(written, 1000); Assert.assertEquals(logTest.sizeInBytes(), 1000); long writtenFromChannel = logTest.appendFrom(Channels.newChannel(new ByteBufferInputStream(ByteBuffer.wrap(testbuf))), 1000); Assert.assertEquals(writtenFromChannel, 1000); Assert.assertEquals(logTest.sizeInBytes(), 2000); written = logTest.appendFrom(ByteBuffer.wrap(testbuf)); Assert.assertEquals(written, 1000); Assert.assertEquals(logTest.sizeInBytes(), 3000); ByteBuffer result = ByteBuffer.allocate(3000); logTest.readInto(result, 0); byte[] expectedAns = new byte[3000]; System.arraycopy(testbuf, 0, expectedAns, 0, 1000); System.arraycopy(testbuf, 0, expectedAns, 1000, 1000); System.arraycopy(testbuf, 0, expectedAns, 2000, 1000); Assert.assertArrayEquals(result.array(), expectedAns); result.clear(); result.limit(1000); logTest.readInto(result, 0); Assert.assertEquals(result.limit(), 1000); result.limit(2000); logTest.readInto(result, 1000); Assert.assertEquals(result.limit(), 2000); result.limit(3000); logTest.readInto(result, 2000); Assert.assertEquals(result.limit(), 3000); Assert.assertArrayEquals(result.array(), expectedAns); logTest.flush(); Assert.assertEquals(randomFile.length(), 5000); Assert.assertEquals(logTest.sizeInBytes(), 3000); tempFile.delete(); } catch (Exception e) { Assert.assertEquals(false, true); } }