changes as per review comments
This commit is contained in:
parent
d9540eff75
commit
fece0dc4b8
@ -12,7 +12,6 @@ import java.nio.ByteBuffer;
|
||||
import java.nio.MappedByteBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.nio.channels.FileLock;
|
||||
import java.nio.channels.OverlappingFileLockException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.junit.Test;
|
||||
@ -37,7 +36,9 @@ public class FileChannelUnitTest {
|
||||
buff.clear();
|
||||
}
|
||||
|
||||
assertEquals("Hello world", new String(out.toByteArray(), StandardCharsets.UTF_8));
|
||||
String fileContent = new String(out.toByteArray(), StandardCharsets.UTF_8);
|
||||
|
||||
assertEquals("Hello world", fileContent);
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,9 +59,9 @@ public class FileChannelUnitTest {
|
||||
out.write(buff.array(), 0, buff.position());
|
||||
buff.clear();
|
||||
}
|
||||
String fileContent = new String(out.toByteArray(), StandardCharsets.UTF_8);
|
||||
|
||||
assertEquals("Hello world", new String(out.toByteArray(), StandardCharsets.UTF_8));
|
||||
|
||||
assertEquals("Hello world", fileContent);
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,9 +78,7 @@ public class FileChannelUnitTest {
|
||||
byte[] data = new byte[buff.remaining()];
|
||||
buff.get(data);
|
||||
assertEquals("world", new String(data, StandardCharsets.UTF_8));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -90,11 +89,9 @@ public class FileChannelUnitTest {
|
||||
FileChannel channel = writer.getChannel();) {
|
||||
ByteBuffer buff = ByteBuffer.wrap("Hello world".getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
if (buff.hasRemaining()) {
|
||||
channel.write(buff);
|
||||
}
|
||||
|
||||
// verify
|
||||
// now we verify whether the file was written correctly
|
||||
RandomAccessFile reader = new RandomAccessFile(file, "r");
|
||||
assertEquals("Hello world", reader.readLine());
|
||||
reader.close();
|
||||
@ -108,11 +105,7 @@ public class FileChannelUnitTest {
|
||||
FileLock fileLock = channel.tryLock(6, 5, Boolean.FALSE);) {
|
||||
|
||||
assertNotNull(fileLock);
|
||||
|
||||
} catch (OverlappingFileLockException | IOException ex) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -133,11 +126,11 @@ public class FileChannelUnitTest {
|
||||
buff.clear();
|
||||
}
|
||||
|
||||
// the original file is 11 bytes long, so that's where the position pointer should be
|
||||
assertEquals(11, channel.position());
|
||||
|
||||
channel.position(4);
|
||||
assertEquals(4, channel.position());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -147,10 +140,9 @@ public class FileChannelUnitTest {
|
||||
try (RandomAccessFile reader = new RandomAccessFile("src/test/resources/test_read.in", "r");
|
||||
FileChannel channel = reader.getChannel();) {
|
||||
|
||||
long imageFileSize = channel.size();
|
||||
assertEquals(11, imageFileSize);
|
||||
// the original file is 11 bytes long, so that's where the position pointer should be
|
||||
assertEquals(11, channel.size());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
x
Reference in New Issue
Block a user