john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

ResourceTest

//2012-03-16 johnpfeiffer

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

import java.io.PrintWriter;

import org.junit.Test;


public class ResourceTest
{
    private static Resource r;

    @Test   public void testResource()
    {
        try{
            r = new Resource( "" );
            assertEquals( "" , r.getId() );
        }catch( IllegalArgumentException ie )
      { return;
      }
        fail( "Expected IllegalArgumentException" );
    }

    @Test public void testGetId()
    {
        r = new Resource( "01cd59e5-07d6-4e69-a31b-bf343f658beb" );
        assertEquals( "01cd59e5-07d6-4e69-a31b-bf343f658beb" , r.getId() );

        try{
            r = new Resource( "" );
            assertEquals( "" , r.getId() );
        }catch( IllegalArgumentException ie )
      { return;
      }
        fail( "Expected IllegalArgumentException" );

    }

    @Test   public void testAddBlock()
    {
        r = new Resource( "testAddBlock" );
        Block b = new Block( "0" , 0 );
        r.addBlock( b );
        assertEquals( 1 , r.getBlockCount() );
    }

    @Test   public void testDisplayBlocks()
    {
        r = new Resource( "testDisplayBlocks" );
        PrintWriter pw = new PrintWriter( System.out , true );
        r.displayBlocks( pw );
    }

    @Test   public void testGetBlockCount()
    {
        r = new Resource( "testBlockCount" );
        Block b = new Block( "0" , 0 );
        r.addBlock( b );
        r.addBlock( b );
        assertEquals( 2 , r.getBlockCount() );

    }

} //end class

  • « Block
  • XMLElementAttribute »

Published

Mar 17, 2012

Category

java-classes

~118 words

Tags

  • classes 92
  • java 252
  • resourcetest 1