FileDocCategorySizeDatePackage
TestModelFactory.javaAPI DocApache Poi 3.0.15274Mon Jan 01 12:39:46 GMT 2007org.apache.poi.hssf.eventmodel

TestModelFactory

public class TestModelFactory extends TestCase
Tests the ModelFactory.
author
Andrew C. Oliver acoliver@apache.org

Fields Summary
private ModelFactory
factory
private HSSFWorkbook
book
private InputStream
in
private List
models
Constructors Summary
public TestModelFactory(String arg0)
Tests that the listeners collection is created

param
arg0

        super(arg0);
        ModelFactory mf = new ModelFactory();
        assertTrue("listeners member cannot be null", mf.listeners != null);
        assertTrue("listeners member must be a List", mf.listeners instanceof List);     
    
Methods Summary
public static voidmain(java.lang.String[] args)

        junit.textui.TestRunner.run(TestModelFactory.class);
    
protected voidsetUp()

        super.setUp();
        models = new ArrayList(3);
        factory = new ModelFactory();
        book = new HSSFWorkbook();
        ByteArrayOutputStream stream = (ByteArrayOutputStream)setupRunFile(book);    
        POIFSFileSystem fs = new POIFSFileSystem(
                                   new ByteArrayInputStream(stream.toByteArray())
                                   );
        in = fs.createDocumentInputStream("Workbook");
    
private java.io.ByteArrayOutputStreamsetupRunFile(org.apache.poi.hssf.usermodel.HSSFWorkbook book)
Sets up a test file

        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        HSSFSheet sheet = book.createSheet("Test");
        HSSFRow   row   = sheet.createRow(0);
        HSSFCell  cell  = row.createCell((short)0);
        cell.setCellValue(10.5);
        book.write(stream);
        return stream;
    
protected voidtearDown()

        super.tearDown();
        factory = null;
        book = null;
        in = null;
    
public voidtestRegisterListener()
tests that listeners can be registered

        if (factory.listeners.size() != 0) {
         factory = new ModelFactory();   
        }
        
        factory.registerListener(new MFListener(null));
        factory.registerListener(new MFListener(null));
        assertTrue("Factory listeners should be two, was="+
                                  factory.listeners.size(),
                    factory.listeners.size() == 2);
    
public voidtestRun()
tests that given a simple input stream with one workbook and sheet that those models are processed and returned.

        Model temp = null;
        Iterator mi = null;
        
        if (factory.listeners.size() != 0) {
         factory = new ModelFactory();   
        }
        
        factory.registerListener(new MFListener(models));
        factory.run(in);
        
        assertTrue("Models size must be 2 was = "+models.size(),
                                             models.size() == 2);
        mi = models.iterator();    
        temp = (Model)mi.next();
        
        assertTrue("First model is Workbook was " + temp.getClass().getName(),
                    temp instanceof Workbook);
                    
        temp = (Model)mi.next();
        
        assertTrue("Second model is Sheet was " + temp.getClass().getName(),
                    temp instanceof Sheet);