Exemplo n.º 1
0
  protected void setUp() throws Exception {
    super.setUp();

    fileUtil = mock(FileUtil.class);

    reader = new ShuntNioRecordReader(FILE);
    reader.setRecordLength(5);
    reader.setFileUtil((FileUtil) fileUtil.proxy());
  }
Exemplo n.º 2
0
  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();
  }
Exemplo n.º 3
0
  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());
  }
Exemplo n.º 4
0
  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());
  }
Exemplo n.º 5
0
 public void test_setRecordLength_ZeroRecordLength() {
   try {
     reader.setRecordLength(0);
     fail();
   } catch (IllegalArgumentException err) {
     assertEquals("Record length MUST be greater than zero", err.getMessage());
   }
 }
Exemplo n.º 6
0
  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());
  }
Exemplo n.º 7
0
  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());
    }
  }