FileDocCategorySizeDatePackage
TestPOIFSReaderRegistry.javaAPI DocApache Poi 3.0.15690Mon Jan 01 12:39:44 GMT 2007org.apache.poi.poifs.eventfilesystem

TestPOIFSReaderRegistry

public class TestPOIFSReaderRegistry extends TestCase
Class to test POIFSReaderRegistry functionality
author
Marc Johnson

Fields Summary
private POIFSReaderListener[]
listeners
private POIFSDocumentPath[]
paths
private String[]
names
Constructors Summary
public TestPOIFSReaderRegistry(String name)
Constructor TestPOIFSReaderRegistry

param
name


             

      
    
        super(name);
    
Methods Summary
public static voidmain(java.lang.String[] ignored_args)
main method to run the unit tests

param
ignored_args

        System.out.println(
            "Testing org.apache.poi.poifs.eventfilesystem.POIFSReaderRegistry");
        junit.textui.TestRunner.run(TestPOIFSReaderRegistry.class);
    
public voidtestEmptyRegistry()
Test empty registry

        POIFSReaderRegistry registry = new POIFSReaderRegistry();

        for (int j = 0; j < paths.length; j++)
        {
            for (int k = 0; k < names.length; k++)
            {
                Iterator listeners = registry.getListeners(paths[ j ],
                                                           names[ k ]);

                assertTrue(!listeners.hasNext());
            }
        }
    
public voidtestMixedRegistrationOperations()
Test mixed registration operations

        POIFSReaderRegistry registry = new POIFSReaderRegistry();

        for (int j = 0; j < listeners.length; j++)
        {
            for (int k = 0; k < paths.length; k++)
            {
                for (int n = 0; n < names.length; n++)
                {
                    if ((j != k) && (k != n))
                    {
                        registry.registerListener(listeners[ j ], paths[ k ],
                                                  names[ n ]);
                    }
                }
            }
        }
        for (int k = 0; k < paths.length; k++)
        {
            for (int n = 0; n < names.length; n++)
            {
                Iterator listeners = registry.getListeners(paths[ k ],
                                                           names[ n ]);

                if (k == n)
                {
                    assertTrue(!listeners.hasNext());
                }
                else
                {
                    Set registeredListeners = new HashSet();

                    while (listeners.hasNext())
                    {
                        registeredListeners.add(listeners.next());
                    }
                    assertEquals(this.listeners.length - 1,
                                 registeredListeners.size());
                    for (int j = 0; j < this.listeners.length; j++)
                    {
                        if (j == k)
                        {
                            assertTrue(!registeredListeners
                                .contains(this.listeners[ j ]));
                        }
                        else
                        {
                            assertTrue(registeredListeners
                                .contains(this.listeners[ j ]));
                        }
                    }
                }
            }
        }
        for (int j = 0; j < listeners.length; j++)
        {
            registry.registerListener(listeners[ j ]);
        }
        for (int k = 0; k < paths.length; k++)
        {
            for (int n = 0; n < names.length; n++)
            {
                Iterator listeners           =
                    registry.getListeners(paths[ k ], names[ n ]);
                Set      registeredListeners = new HashSet();

                while (listeners.hasNext())
                {
                    registeredListeners.add(listeners.next());
                }
                assertEquals(this.listeners.length,
                             registeredListeners.size());
                for (int j = 0; j < this.listeners.length; j++)
                {
                    assertTrue(registeredListeners
                        .contains(this.listeners[ j ]));
                }
            }
        }