ContentBufferTest.java :  » Testing » StoryTestIQ » fitnesse » components » Java Open Source

Java Open Source » Testing » StoryTestIQ 
StoryTestIQ » fitnesse » components » ContentBufferTest.java
// Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
// Released under the terms of the GNU General Public License version 2 or later.
package fitnesse.components;

import junit.framework.TestCase;
import java.io.*;
import fitnesse.util.*;

public class ContentBufferTest extends TestCase {
  protected void tearDown() throws Exception {
    System.gc();
  }

  public void testName() throws Exception {
    String name = new ContentBuffer().getFile().getName();
    assertTrue(name.startsWith("FitNesse-"));
    assertTrue(name.endsWith(".tmp"));

    name = new ContentBuffer(".html").getFile().getName();
    assertTrue(name.startsWith("FitNesse-"));
    assertTrue(name.endsWith(".html"));
  }

  public void testSimpleUsage() throws Exception {
    ContentBuffer buffer = new ContentBuffer();
    buffer.append("some content");
    assertEquals("some content", buffer.getContent());
  }

  public void testGettingInputStream() throws Exception {
    ContentBuffer buffer = new ContentBuffer();
    buffer.append("some content");

    int bytes = buffer.getSize();
    assertEquals(12, bytes);

    InputStream input = buffer.getInputStream();
    String content = new StreamReader(input).read(12);
    assertEquals("some content", content);
  }

  public void testDelete() throws Exception {
    ContentBuffer buffer = new ContentBuffer();
    File file = buffer.getFile();

    assertTrue(file.exists());
    buffer.delete();
    assertFalse(file.exists());
  }

  public void testUnicode() throws Exception {
    ContentBuffer buffer = new ContentBuffer();
    buffer.append("??");
    assertEquals("??", new StreamReader(buffer.getInputStream()).read(buffer.getSize()));
  }
}
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.