From: Roman Kennke <roman@kennke.org>
To: mauve-patches <mauve-patches@sources.redhat.com>
Subject: FYI: New TransferHandler test
Date: Sat, 28 Oct 2006 10:31:00 -0000 [thread overview]
Message-ID: <1162031425.7168.0.camel@localhost> (raw)
[-- Attachment #1: Type: text/plain, Size: 185 bytes --]
This adds extensive test for TransferHandler.importData().
2006-10-28 Roman Kennke <kennke@aicas.com>
* gnu/testlet/javax/swing/TransferHandler/importData.java:
New test.
/Roman
[-- Attachment #2: patch.diff --]
[-- Type: text/x-patch, Size: 5917 bytes --]
Index: gnu/testlet/javax/swing/TransferHandler/importData.java
===================================================================
RCS file: gnu/testlet/javax/swing/TransferHandler/importData.java
diff -N gnu/testlet/javax/swing/TransferHandler/importData.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/javax/swing/TransferHandler/importData.java 28 Oct 2006 10:29:22 -0000
@@ -0,0 +1,221 @@
+/* importData.java -- Tests the TransferHandler importData() method
+ 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.4
+
+package gnu.testlet.javax.swing.TransferHandler;
+
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.Transferable;
+import java.awt.datatransfer.UnsupportedFlavorException;
+import java.io.IOException;
+
+import javax.swing.JComponent;
+import javax.swing.TransferHandler;
+
+import junit.framework.TestCase;
+import gnu.testlet.TestHarness;
+
+/**
+ * Tests the TransferHandler.importData() method.
+ */
+public class importData extends TestCase
+{
+
+ /**
+ * Implements test properties in JComponent.
+ */
+ public static class TestComponent extends JComponent
+ {
+ String property = null;
+ public void setTestProperty(String prop)
+ {
+ property = prop;
+ }
+ public String getTestProperty()
+ {
+ return property;
+ }
+ }
+
+ /**
+ * A Transferable used for our tests.
+ */
+ static class TestTransferable implements Transferable
+ {
+
+ public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException
+ {
+ return "Hello World";
+ }
+
+ public DataFlavor[] getTransferDataFlavors()
+ {
+ try
+ {
+ DataFlavor flavor = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType
+ + "; class=java.lang.String");
+ return new DataFlavor[]{ flavor };
+ }
+ catch (ClassNotFoundException ex)
+ {
+ throw new InternalError();
+ }
+ }
+
+ public boolean isDataFlavorSupported(DataFlavor flavor)
+ {
+ return flavor.getPrimaryType().equals("application")
+ && flavor.getSubType().equals("x-java-jvm-local-objectref")
+ && flavor.getRepresentationClass().equals("java.lang.String");
+ }
+
+ }
+
+ /**
+ * The component to which we transfer.
+ */
+ private JComponent component;
+
+ /**
+ * The transfer handler that we use.
+ */
+ private TransferHandler transferHandler;
+
+ /**
+ * The transferable that gets transferred.
+ */
+ private Transferable transferable;
+
+ /**
+ * Sets up the test case.
+ */
+ public void setUp()
+ {
+ component = new TestComponent();
+ transferHandler = new TransferHandler("testProperty");
+ transferable = new TestTransferable();
+ }
+
+ /**
+ * Tears down the test case.
+ */
+ public void tearDown()
+ {
+ component = null;
+ transferHandler = null;
+ transferable = null;
+ }
+
+ /**
+ * Tests a normal transfer.
+ */
+ public void testOK()
+ {
+ boolean ok = transferHandler.importData(component, transferable);
+ assertTrue(ok);
+ assertEquals(((TestComponent) component).getTestProperty(),
+ "Hello World");
+ }
+
+ /**
+ * Tests a transfer with a transferable that does not support the correct
+ * flavor.
+ */
+ public void testWrongFlavor()
+ {
+ transferable = new TestTransferable()
+ {
+ public DataFlavor[] getTransferDataFlavors()
+ {
+ return new DataFlavor[0];
+ }
+ };
+ boolean ok = transferHandler.importData(component, transferable);
+ assertFalse(ok);
+ assertNull(((TestComponent) component).getTestProperty());
+ }
+
+ /**
+ * Tests a transfer to a component that doesn't have the correct property
+ * write method.
+ */
+ public void testInvalidWriter()
+ {
+ component = new JComponent()
+ {
+ public void setTestProperty(String prop, int i)
+ {
+
+ }
+ public String getTestProperty()
+ {
+ return "test";
+ }
+ };
+ boolean ok = transferHandler.importData(component, transferable);
+ assertFalse(ok);
+ }
+
+ /**
+ * Tests a transfer to a component without the property writer.
+ */
+ public void testMissingPropertyWriter()
+ {
+ component = new JComponent()
+ {
+ public String getTestProperty()
+ {
+ return "test";
+ }
+ };
+ boolean ok = transferHandler.importData(component, transferable);
+ assertFalse(ok);
+ }
+
+ /**
+ * Tests a transfer to a component without the property reader.
+ */
+ public void testMissingPropertyReader()
+ {
+ component = new JComponent()
+ {
+ public void setTestProperty(String prop)
+ {
+
+ }
+ };
+ boolean ok = transferHandler.importData(component, transferable);
+ assertFalse(ok);
+ }
+
+ /**
+ * Tests a transfer with a TransferHandler initialized with a null
+ * property.
+ */
+ public void testNullProperty()
+ {
+ transferHandler = new TransferHandler(null);
+ boolean ok = transferHandler.importData(component, transferable);
+ assertFalse(ok);
+ }
+
+}
next reply other threads:[~2006-10-28 10:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-10-28 10:31 Roman Kennke [this message]
-- strict thread matches above, loose matches on Subject: below --
2006-10-17 15:24 Roman Kennke
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1162031425.7168.0.camel@localhost \
--to=roman@kennke.org \
--cc=mauve-patches@sources.redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).