protected void setUp() throws Exception { super.setUp(); fileUtil = mock(FileUtil.class); reader = new ShuntNioRecordReader(FILE); reader.setRecordLength(5); reader.setFileUtil((FileUtil) fileUtil.proxy()); }
public void test_close() throws IOException { ByteArrayChannel channel = new ByteArrayChannel("12345".getBytes()); fileUtil.expects(once()).method("channel").with(eq(FILE)).will(returnValue(channel)); fileUtil.expects(once()).method("length").with(eq(FILE)).will(returnValue(5L)); reader.readRecord(); fileUtil.expects(once()).method("close").with(eq(channel)); reader.close(); }
public void test_readRecord_BufferSizeNotLargeEnoughForRecord_MustMakeMultipleReads() throws IOException { reader.bufferSize = 2; fileUtil .expects(once()) .method("channel") .with(eq(FILE)) .will(returnValue(new ByteArrayChannel("12345".getBytes()))); fileUtil.expects(once()).method("length").with(eq(FILE)).will(returnValue(5L)); assertEquals("12345", new String(reader.readRecord())); assertNull(reader.readRecord()); }
public void test_readRecord_HasOneRecord() throws IOException { fileUtil .expects(once()) .method("channel") .with(eq(FILE)) .will(returnValue(new ByteArrayChannel("12345".getBytes()))); fileUtil.expects(once()).method("length").with(eq(FILE)).will(returnValue(5L)); byte[] actualRecord = reader.readRecord(); assertNotNull(actualRecord); assertEquals(5, actualRecord.length); assertEquals("12345", new String(actualRecord)); assertNull(reader.readRecord()); }
public void test_setRecordLength_ZeroRecordLength() { try { reader.setRecordLength(0); fail(); } catch (IllegalArgumentException err) { assertEquals("Record length MUST be greater than zero", err.getMessage()); } }
public void test_readRecord_FileIsEmpty() throws IOException { fileUtil .expects(once()) .method("channel") .with(eq(FILE)) .will(returnValue(new ByteArrayChannel("".getBytes()))); fileUtil.expects(once()).method("length").with(eq(FILE)).will(returnValue(0L)); assertNull(reader.readRecord()); }
public void test_readRecord_RecordLengthNeverSet() throws IOException { try { reader = new ShuntNioRecordReader(FILE); reader.readRecord(); fail(); } catch (IllegalArgumentException err) { assertEquals("Record length MUST be greater than zero", err.getMessage()); } }