DiskFileTestCase.java :  » Google-tech » goofs » goofs » fs » Java Open Source

Java Open Source » Google tech » goofs 
goofs » goofs » fs » DiskFileTestCase.java
package goofs.fs;

import java.nio.ByteBuffer;

import junit.framework.TestCase;

public class DiskFileTestCase extends TestCase {

  protected DiskFile file;

  protected void setUp() throws Exception {
    super.setUp();

    file = new DiskFile(null, "hello", 0777) {

      @Override
      public int save() {
        // TODO Auto-generated method stub
        return 0;
      }

      @Override
      public int delete() {
        // TODO Auto-generated method stub
        return 0;
      }

      @Override
      public int rename(Dir newParent, String name) {
        // TODO Auto-generated method stub
        return 0;
      }

    };

    file.setContent("hello world".getBytes());

  }

  protected void tearDown() throws Exception {
    super.tearDown();

    file = null;
  }

  public void testRead() throws Exception {

    ByteBuffer buf = ByteBuffer.allocate(file.getContent().length);

    file.read(buf, 6);

    String bufStr = new String(buf.array());

    assert (bufStr.equals("world"));

  }

  public void testWrite() throws Exception {

    ByteBuffer buf = ByteBuffer.wrap("mello".getBytes());

    file.write(false, buf, 6);

    assert (file.getContent().equals("hello mellow"));

  }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.