This is the mail archive of the mauve-patches@sourceware.org mailing list for the Mauve project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

FYI: New JComponent.putClientProperty() test


This adds a test for JComponent.putClientProperty() that tests if an
event should be fired, when a property that is null has
putClientProperty() called with null. No event should be fired in that
case. This is different from the behaviour of PropertyChangeSupport
which fires an event in that case. I also added a testcase for this.

2006-11-28  Roman Kennke <kennke@aicas.com>

	* gnu/testlet/java/beans/PropertyChangeSupport/firePropertyChange.java:
	New test.
	* gnu/testlet/javax/swing/JComponent/putClientProperty.java:
	Added check for how setting a null property fires an event or
	not.

/Roman

Index: gnu/testlet/java/beans/PropertyChangeSupport/firePropertyChange.java
===================================================================
RCS file: gnu/testlet/java/beans/PropertyChangeSupport/firePropertyChange.java
diff -N gnu/testlet/java/beans/PropertyChangeSupport/firePropertyChange.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/java/beans/PropertyChangeSupport/firePropertyChange.java	28 Nov 2006 12:34:45 -0000
@@ -0,0 +1,73 @@
+/* firePropertyChange.java -- Tests firePropertyChange()
+   Copyright (C) 2006 Roman Kennke (kennke@aicas.com)
+This file is part of Mauve.
+
+Mauve is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+Mauve is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Mauve; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+*/
+
+// Tags: JDK1.2
+
+package gnu.testlet.java.beans.PropertyChangeSupport;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.util.ArrayList;
+
+import junit.framework.TestCase;
+
+public class firePropertyChange extends TestCase
+  implements PropertyChangeListener
+{
+  /**
+   * The object to test.
+   */
+  private PropertyChangeSupport change;
+
+  /**
+   * The received events.
+   */
+  private ArrayList events;
+
+  public void setUp()
+  {
+    change = new PropertyChangeSupport(this);
+    change.addPropertyChangeListener(this);
+    events = new ArrayList();
+  }
+
+  public void tearDown()
+  {
+    change = null;
+    events = null;
+  }
+
+  public void testNullNull()
+  {
+    change.firePropertyChange("test", null, null);
+    assertEquals(events.size(), 1);
+    PropertyChangeEvent ev = (PropertyChangeEvent) events.get(0);
+    assertEquals(ev.getPropertyName(), "test");
+    assertNull(ev.getNewValue());
+    assertNull(ev.getOldValue());
+  }
+
+  public void propertyChange(PropertyChangeEvent e)
+  {
+    events.add(e);
+  }
+}
Index: gnu/testlet/javax/swing/JComponent/putClientProperty.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/javax/swing/JComponent/putClientProperty.java,v
retrieving revision 1.1
diff -u -1 -5 -r1.1 putClientProperty.java
--- gnu/testlet/javax/swing/JComponent/putClientProperty.java	12 Sep 2005 21:55:39 -0000	1.1
+++ gnu/testlet/javax/swing/JComponent/putClientProperty.java	28 Nov 2006 12:34:45 -0000
@@ -45,38 +45,48 @@
   {
     name = e.getPropertyName();
     oldValue = e.getOldValue();
     newValue = e.getNewValue();
   }
   
   /**
    * Runs the test using the specified harness.
    * 
    * @param harness  the test harness (<code>null</code> not permitted).
    */
   public void test(TestHarness harness)      
   {   
     JComponent label = new JLabel("Test");
     label.addPropertyChangeListener(this);
-    
+
     // add a new property
     label.putClientProperty("Property1", Boolean.TRUE);
     harness.check(label.getClientProperty("Property1"), Boolean.TRUE);
     harness.check(name, "Property1");
     harness.check(oldValue, null);
     harness.check(newValue, Boolean.TRUE);
-    
+
+    // Set testnull to null. No event is fired.
+    label.putClientProperty("testnull", null);
+    name = null;
+    oldValue = null;
+    newValue = null;
+    label.putClientProperty("testnull", null);
+    harness.check(name, null);
+    harness.check(oldValue, null);
+    harness.check(newValue, null);
+
     // overwrite an existing property
     label.putClientProperty("Property1", Boolean.FALSE);
     harness.check(label.getClientProperty("Property1"), Boolean.FALSE);
     harness.check(name, "Property1");
     harness.check(oldValue, Boolean.TRUE);
     harness.check(newValue, Boolean.FALSE);
     
     // clear the property
     label.putClientProperty("Property1", null);
     harness.check(label.getClientProperty("Property1"), null);
     harness.check(name, "Property1");
     harness.check(oldValue, Boolean.FALSE);
     harness.check(newValue, null);
     
     // try a null key

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]