Source Code Cross Referenced for ClipboardTest.java in  » Apache-Harmony-Java-SE » java-package » java » awt » datatransfer » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » java package » java.awt.datatransfer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:        /**
018:         * @author Michael Danilov
019:         * @version $Revision$
020:         */package java.awt.datatransfer;
021:
022:        import java.io.IOException;
023:        import java.lang.reflect.InvocationTargetException;
024:        import java.util.Arrays;
025:        import java.awt.*;
026:
027:        import junit.framework.TestCase;
028:
029:        public class ClipboardTest extends TestCase {
030:
031:            private boolean calledBack;
032:            private boolean listenerCalled;
033:
034:            public final void testClipboard() {
035:                assertNull(new Clipboard(null).getName());
036:                assertEquals(new Clipboard("Clipboard").getName(), "Clipboard");
037:            }
038:
039:            public final void testGetName() {
040:                testClipboard();
041:            }
042:
043:            public final void testAddFlavorListener() {
044:                Clipboard c = new Clipboard("");
045:                FlavorListener l = new FlavorListener() {
046:                    public void flavorsChanged(FlavorEvent e) {
047:                    }
048:                };
049:
050:                c.addFlavorListener(null);
051:                assertTrue(c.getFlavorListeners().length == 0);
052:
053:                c.addFlavorListener(l);
054:                assertTrue(c.getFlavorListeners().length > 0);
055:                assertTrue(Arrays.asList(c.getFlavorListeners()).contains(l));
056:            }
057:
058:            public final void testRemoveFlavorListener() {
059:                Clipboard c = new Clipboard("");
060:                FlavorListener l = new FlavorListener() {
061:                    public void flavorsChanged(FlavorEvent e) {
062:                    }
063:                };
064:
065:                c.addFlavorListener(l);
066:                c.removeFlavorListener(null);
067:                assertTrue(c.getFlavorListeners().length == 1);
068:
069:                c.removeFlavorListener(l);
070:                assertTrue(c.getFlavorListeners().length == 0);
071:
072:                c.removeFlavorListener(l);
073:                assertTrue(c.getFlavorListeners().length == 0);
074:            }
075:
076:            public final void testGetFlavorListeners() {
077:                Clipboard c = new Clipboard("");
078:                FlavorListener l = new FlavorListener() {
079:                    public void flavorsChanged(FlavorEvent e) {
080:                    }
081:                };
082:
083:                assertTrue(c.getFlavorListeners().length == 0);
084:
085:                c.addFlavorListener(l);
086:                assertTrue(c.getFlavorListeners().length > 0);
087:                assertTrue(Arrays.asList(c.getFlavorListeners()).contains(l));
088:
089:                c.removeFlavorListener(l);
090:                assertTrue(c.getFlavorListeners().length == 0);
091:            }
092:
093:            public final void testSetContents() throws InterruptedException,
094:                    InvocationTargetException {
095:                Clipboard c = new Clipboard("");
096:                FlavorListener l = new FlavorListener() {
097:                    public void flavorsChanged(FlavorEvent e) {
098:                        listenerCalled = true;
099:                    }
100:                };
101:                StringSelection t = new StringSelection("") {
102:                    @Override
103:                    public void lostOwnership(Clipboard clipboard,
104:                            Transferable contents) {
105:                        calledBack = true;
106:                    }
107:                };
108:
109:                c.addFlavorListener(l);
110:                c.setContents(t, t);
111:                listenerCalled = calledBack = false;
112:                c.setContents(new Transferable() {
113:                    public Object getTransferData(DataFlavor flavor)
114:                            throws UnsupportedFlavorException, IOException {
115:                        return null;
116:                    }
117:
118:                    public boolean isDataFlavorSupported(DataFlavor flavor) {
119:                        return false;
120:                    }
121:
122:                    public DataFlavor[] getTransferDataFlavors() {
123:                        return new DataFlavor[0];
124:                    }
125:                }, new ClipboardOwner() {
126:                    public void lostOwnership(Clipboard clipboard,
127:                            Transferable contents) {
128:                    }
129:                });
130:                EventQueue.invokeAndWait(new Runnable() {
131:                    public void run() {
132:                    }
133:                });
134:                assertTrue(listenerCalled);
135:                assertTrue(calledBack);
136:            }
137:
138:            public final void testGetContents() {
139:                Clipboard c = new Clipboard("");
140:                StringSelection s = new StringSelection("");
141:
142:                c.setContents(s, s);
143:                assertEquals(c.getContents(null), s);
144:            }
145:
146:            @SuppressWarnings("deprecation")
147:            public final void testIsDataFlavorAvailable() {
148:                Clipboard c = new Clipboard("");
149:                StringSelection s = new StringSelection("");
150:
151:                c.setContents(s, s);
152:                assertTrue(c.isDataFlavorAvailable(DataFlavor.stringFlavor));
153:                assertTrue(c.isDataFlavorAvailable(DataFlavor.plainTextFlavor));
154:                assertFalse(c.isDataFlavorAvailable(new DataFlavor(
155:                        Rectangle.class, "")));
156:            }
157:
158:            @SuppressWarnings("deprecation")
159:            public final void testGetAvailableDataFlavors() {
160:                Clipboard c = new Clipboard("");
161:                StringSelection s = new StringSelection("");
162:
163:                c.setContents(s, s);
164:                assertTrue(Arrays.asList(c.getAvailableDataFlavors()).contains(
165:                        DataFlavor.stringFlavor));
166:                assertTrue(Arrays.asList(c.getAvailableDataFlavors()).contains(
167:                        DataFlavor.plainTextFlavor));
168:                assertFalse(Arrays.asList(c.getAvailableDataFlavors())
169:                        .contains(new DataFlavor(Rectangle.class, "")));
170:            }
171:
172:            public final void testGetData() {
173:                Clipboard c = new Clipboard("");
174:                StringSelection s = new StringSelection("");
175:                boolean string = false;
176:                boolean unsupported = false;
177:
178:                c.setContents(s, s);
179:
180:                try {
181:                    string = c.getData(DataFlavor.stringFlavor).equals("");
182:                    c.getData(new DataFlavor(Rectangle.class, "")).equals("");
183:                } catch (Exception e) {
184:                    unsupported = true;
185:                }
186:                assertTrue(string);
187:                assertTrue(unsupported);
188:            }
189:
190:            public final void testNullContent() throws NullPointerException {
191:                // Regression for HARMONY-2067
192:                Clipboard c = new Clipboard("");
193:                c.setContents(null, null);
194:            }
195:
196:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.