public inbox for mauve-patches@sourceware.org
 help / color / mirror / Atom feed
* FYI: New JComponent.putClientProperty() test
@ 2006-11-28 12:37 Roman Kennke
  0 siblings, 0 replies; only message in thread
From: Roman Kennke @ 2006-11-28 12:37 UTC (permalink / raw)
  To: mauve-patches

[-- Attachment #1: Type: text/plain, Size: 603 bytes --]

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


[-- Attachment #2: patch.diff --]
[-- Type: text/x-patch, Size: 4528 bytes --]

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2006-11-28 12:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-11-28 12:37 FYI: New JComponent.putClientProperty() test Roman Kennke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).