Package ca.odell.glazedlists.impl.testing

Examples of ca.odell.glazedlists.impl.testing.ListConsistencyListener


        NotFirstMatcherEditor<String> matcherEditor = new NotFirstMatcherEditor<String>();
        FilterList<String> filtered = new FilterList<String>(source, matcherEditor);
        source.addListEventListener(matcherEditor);
        source.add("A");

        ListConsistencyListener filteredListener = ListConsistencyListener.install(filtered);
        assertEquals(0, filteredListener.getEventCount());
    }
View Full Code Here


     * Test that the ListEvent iterator isn't adjusted by calling
     * {@link ListEventAssembler#forwardEvent}.
     */
    public void testEventStateAfterForwardEvent() {
        EventList<String> source = new BasicEventList<String>();
        ListConsistencyListener lcl = ListConsistencyListener.install(source);
       
        source.add("Hello");
        assertEquals(1, lcl.getChangeCount(0));
    }
View Full Code Here

        SortedSet<Object> replacementSet = new TreeSet<Object>();
        replacementSet.addAll(source);

        // listen to changes on the unique list
        ListConsistencyListener counter = ListConsistencyListener.install(unique);

        // replace the values with the replacement set
        GlazedLists.replaceAllSorted(unique, replacementSet, true, null);

        // verify that only one event has occured
        assertEquals(3, counter.getEventCount());
    }
View Full Code Here

    /**
     * When {@link UniqueList#set} is called, this should fire an updated event.
     */
    public void testEventsFiredBySet() {
        source.addAll(GlazedListsTests.stringToList("AAABBBDDD"));
        ListConsistencyListener consistencyListener = ListConsistencyListener.install(unique);

        unique.set(1, "B");
        assertEquals(1, consistencyListener.getEventCount());
        assertEquals(1, consistencyListener.getChangeCount(0));

        unique.set(1, "C");
        assertEquals(2, consistencyListener.getEventCount());
        assertEquals(1, consistencyListener.getChangeCount(1));
    }
View Full Code Here

            new ObservableElementList<JLabel>(new BasicEventList<JLabel>(), GlazedLists.beanConnector(JLabel.class, falseMatcher));       
        final JLabel listElement1 = new JLabel();
        final JLabel listElement2 = new JLabel();
        labelList.add(listElement1);
        labelList.add(listElement2);
        ListConsistencyListener listener = ListConsistencyListener.install(labelList);
        assertEquals(0, listener.getEventCount());
        listElement1.setText("Item 1");
        listElement2.setText("Item 2");
        listElement1.setEnabled(false);
        listElement2.setBackground(Color.RED);
        assertEquals(0, listener.getEventCount());
       
        // match only property change events for properties 'text and 'enabled'
        Matcher<PropertyChangeEvent> byNameMatcher = Matchers.propertyEventNameMatcher(true, new String[] {"text", "enabled"});
        labelList = new ObservableElementList<JLabel>(new BasicEventList<JLabel>(), GlazedLists
                .beanConnector(JLabel.class, byNameMatcher));       
        labelList.add(listElement1);
        labelList.add(listElement2);
        listener = ListConsistencyListener.install(labelList);
        assertEquals(0, listener.getEventCount());
        listElement1.setText("Text 1");
        assertEquals(1, listener.getEventCount());
        listElement2.setText("Text 2");
        assertEquals(2, listener.getEventCount());       
        listElement1.setBackground(Color.RED);
        assertEquals(2, listener.getEventCount());
        listElement2.setForeground(Color.GRAY);
        assertEquals(2, listener.getEventCount());       
        listElement1.setEnabled(true);
        assertEquals(3, listener.getEventCount());

        // match only property change events for properties 'text and 'enabled'
        labelList = new ObservableElementList<JLabel>(new BasicEventList<JLabel>(), GlazedLists
                .beanConnector(JLabel.class, true, new String[] {"text", "enabled"}));       
        labelList.add(listElement1);
        labelList.add(listElement2);
        listener = ListConsistencyListener.install(labelList);
        assertEquals(0, listener.getEventCount());
        listElement1.setText("Item 1");
        assertEquals(1, listener.getEventCount());
        listElement2.setText("Item 2");
        assertEquals(2, listener.getEventCount());       
        listElement1.setBackground(Color.GREEN);
        assertEquals(2, listener.getEventCount());
        listElement2.setForeground(Color.WHITE);
        assertEquals(2, listener.getEventCount());       
        listElement1.setEnabled(false);
        assertEquals(3, listener.getEventCount());
       
        // match all property change events excluding properties 'text' and 'enabled'
        labelList = new ObservableElementList<JLabel>(new BasicEventList<JLabel>(), GlazedLists
                .beanConnector(JLabel.class, false, new String[] {"text", "enabled"}));       
        labelList.add(listElement1);
        labelList.add(listElement2);
        listener = ListConsistencyListener.install(labelList);
        assertEquals(0, listener.getEventCount());
        listElement1.setText("Text 1");
        assertEquals(0, listener.getEventCount());
        listElement2.setText("Text 2");
        assertEquals(0, listener.getEventCount());       
        listElement1.setBackground(Color.BLACK);
        assertEquals(1, listener.getEventCount());
        listElement2.setForeground(Color.YELLOW);
        assertEquals(2, listener.getEventCount());       
        listElement1.setEnabled(true);
        assertEquals(2, listener.getEventCount());       
    }
View Full Code Here

        BasicEventList<String> unsortedSource = new BasicEventList<String>();
        SortedList<String> source = new SortedList<String>(unsortedSource, null);
        unsortedSource.addAll(GlazedListsTests.stringToList("CcaCbCcCAaADdaAbBDbBdDb"));

        SeparatorList<String> separatorList = new SeparatorList<String>(source, caseInsensitive, 0, Integer.MAX_VALUE);
        ListConsistencyListener consistencyTest = ListConsistencyListener.install(separatorList);
        consistencyTest.setPreviousElementTracked(false);

        assertEqualsIgnoreSeparators(source, separatorList, caseInsensitive);

        source.setComparator(caseSensitive);
        expectedEventCount++;
        assertEquals(expectedEventCount, consistencyTest.getEventCount());
        assertTrue(consistencyTest.isReordering(0));

        // collapse some
        for(int i = 0; i < separatorList.size(); i++) {
            Object value = separatorList.get(i);
            if(!(value instanceof SeparatorList.Separator)) continue;
            SeparatorList.Separator separator = (SeparatorList.Separator)value;
            if(dice.nextBoolean()) {
                separator.setLimit(0);
                expectedEventCount++;
                assertEquals(expectedEventCount, consistencyTest.getEventCount());
            }
        }

        // do some more reorderings: to null comparator
        source.setComparator(null);
        expectedEventCount++;
        assertEquals(expectedEventCount, consistencyTest.getEventCount());
        assertTrue(consistencyTest.isReordering(expectedEventCount - 1));

        // do some more reorderings: back to case sensitive comparator
        source.setComparator(caseSensitive);
        expectedEventCount++;
        assertEquals(expectedEventCount, consistencyTest.getEventCount());
        assertTrue(consistencyTest.isReordering(expectedEventCount - 1));
    }
View Full Code Here

    public void testSeparatorIsThreadSafe() throws InterruptedException {
        final BasicEventList<String> source = new BasicEventList<String>();
        source.addAll(GlazedListsTests.stringToList("AABBBCCCCDDDDEFGHHHH"));

        final SeparatorList<String> separatorList = new SeparatorList<String>(source, GlazedLists.comparableComparator(), 0, Integer.MAX_VALUE);
        ListConsistencyListener listConsistencyListener = ListConsistencyListener.install(separatorList);
        listConsistencyListener.setPreviousElementTracked(false);
        assertEqualsIgnoreSeparators(source, separatorList, GlazedLists.comparableComparator());

        SeparatorList.Separator separator = (SeparatorList.Separator)(Object)separatorList.get(0);
        assertEquals("A", separator.first());
        assertEquals(2, separator.size());
View Full Code Here

    /**
     * Verifies that the ThresholdList fires consistent events.
     */
    public void testNumberOfEventsFired() {
        // count events
        ListConsistencyListener counter = ListConsistencyListener.install(thresholdList);

        // putz around with the thresholds on an empty list
        thresholdList.setLowerThreshold(-14922);
        thresholdList.setUpperThreshold(-1922);
        thresholdList.setLowerThreshold(-13923);
        thresholdList.setUpperThreshold(-923);
        assertEquals(0, counter.getEventCount());

        // add an element that is not in range
        source.add(new Integer(1139));
        assertEquals(0, counter.getEventCount());
        thresholdList.setLowerThreshold(-12923);
        thresholdList.setUpperThreshold(77);
        thresholdList.setLowerThreshold(-11922);
        thresholdList.setUpperThreshold(1078);
        thresholdList.setLowerThreshold(-10923);

        // adjust the range to include our element
        thresholdList.setUpperThreshold(2077);
        assertEquals(source, thresholdList);
        assertEquals(1, counter.getEventCount());
        assertEquals(1, counter.getChangeCount(0));

        // keep the element in range for some changes
        thresholdList.setLowerThreshold(-9923);
        thresholdList.setUpperThreshold(3077);
        thresholdList.setLowerThreshold(-8923);
        thresholdList.setUpperThreshold(4077);
        thresholdList.setLowerThreshold(-7921);
        thresholdList.setUpperThreshold(5079);
        thresholdList.setLowerThreshold(-6923);
        thresholdList.setUpperThreshold(6077);
        thresholdList.setLowerThreshold(-5923);
        thresholdList.setUpperThreshold(7077);
        thresholdList.setLowerThreshold(-4922);
        thresholdList.setUpperThreshold(8078);
        thresholdList.setLowerThreshold(-3923);
        thresholdList.setUpperThreshold(9077);
        thresholdList.setLowerThreshold(-2923);
        thresholdList.setUpperThreshold(10077);
        thresholdList.setLowerThreshold(-1922);
        thresholdList.setUpperThreshold(11078);
        thresholdList.setLowerThreshold(-923);
        thresholdList.setUpperThreshold(12077);
        thresholdList.setLowerThreshold(77);
        thresholdList.setUpperThreshold(13077);
        thresholdList.setLowerThreshold(1077);
        thresholdList.setUpperThreshold(14077);

        // move past our element
        thresholdList.setLowerThreshold(2078);
        assertEquals(2, counter.getEventCount());
        assertEquals(1, counter.getChangeCount(1));
        assertEquals(Collections.EMPTY_LIST, thresholdList);
    }
View Full Code Here

    public void testReorder() {
        // establish a control for this test case with the normal Function
        SortedList<Integer> source = new SortedList<Integer>(new BasicEventList<Integer>(), null);
        FunctionList<Integer, String> intsToStrings = new FunctionList<Integer, String>(source, new AdvancedIntegerToString(), new StringToInteger());
        ListConsistencyListener consistencyListener = ListConsistencyListener.install(intsToStrings);

        source.add(ONE);
        source.add(ZERO);
        assertEquals(2, consistencyListener.getEventCount());

        source.setComparator(GlazedLists.comparableComparator());

        assertEquals(3, consistencyListener.getEventCount());
    }
View Full Code Here

TOP

Related Classes of ca.odell.glazedlists.impl.testing.ListConsistencyListener

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.