All Downloads are FREE. Search and download functionalities are using the official Maven repository.

test.ca.odell.glazedlists.calculation.ManyElementsTest Maven / Gradle / Ivy

There is a newer version: 1.9.1
Show newest version
/* Glazed Lists                                                 (c) 2003-2007 */
/* http://publicobject.com/glazedlists/                      publicobject.com,*/
/*                                                     O'Dell Engineering Ltd.*/
package ca.odell.glazedlists.calculation;

import ca.odell.glazedlists.BasicEventList;
import ca.odell.glazedlists.EventList;
import junit.framework.TestCase;

public class ManyElementsTest extends TestCase {

    public void testPropertyChanges() {
        final EventList source = new BasicEventList();

        final PropertyChangeCounter counter = new PropertyChangeCounter();
        final Calculation manyCount = Calculations.manyElements(source);
        manyCount.addPropertyChangeListener(counter);

        // check the initial Count state
        assertEquals(Boolean.FALSE, manyCount.getValue());
        assertEquals(0, counter.getCountAndReset());

        // test add
        source.add("a");
        assertEquals(Boolean.FALSE, manyCount.getValue());
        assertEquals(0, counter.getCountAndReset());

        // test add 2nd element
        source.add("b");
        assertEquals(Boolean.TRUE, manyCount.getValue());
        assertEquals(1, counter.getCountAndReset());

        // test add 3rd element
        source.add("c");
        assertEquals(Boolean.TRUE, manyCount.getValue());
        assertEquals(0, counter.getCountAndReset());

        // test update
        source.set(0, "b");
        assertEquals(Boolean.TRUE, manyCount.getValue());
        assertEquals(0, counter.getCountAndReset());

        // test remove
        source.remove(0);
        assertEquals(Boolean.TRUE, manyCount.getValue());
        assertEquals(0, counter.getCountAndReset());

        // test remove again
        source.remove(0);
        assertEquals(Boolean.FALSE, manyCount.getValue());
        assertEquals(1, counter.getCountAndReset());

        // test remove last element
        source.remove(0);
        assertEquals(Boolean.FALSE, manyCount.getValue());
        assertEquals(0, counter.getCountAndReset());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy