1 19 20 package org.openide.util.datatransfer; 21 22 import java.awt.datatransfer.StringSelection ; 23 import java.awt.datatransfer.Transferable ; 24 import junit.framework.TestCase; 25 26 30 public class ExClipboardTest extends TestCase { 31 private ExClipboard clipboard; 32 33 private ExClipboard.Convertor[] convertors = new ExClipboard.Convertor[0]; 34 35 public ExClipboardTest (String testName) { 36 super (testName); 37 } 38 39 protected void setUp () throws Exception { 40 clipboard = new ExClipboard ("test clipboard") { 41 protected ExClipboard.Convertor[] getConvertors () { 42 return convertors; 43 } 44 }; 45 } 46 47 public void testAddRemoveClipboardListener () { 48 49 class L implements ClipboardListener { 50 public int cnt; 51 public ClipboardEvent ev; 52 public void clipboardChanged (ClipboardEvent ev) { 53 cnt++; 54 this.ev = ev; 55 } 56 } 57 L listener = new L (); 58 59 clipboard.addClipboardListener (listener); 60 clipboard.fireClipboardChange (); 61 assertEquals ("One event", 1, listener.cnt); 62 assertNotNull ("An event", listener.ev); 63 assertEquals ("source is right", clipboard, listener.ev.getSource ()); 64 65 clipboard.removeClipboardListener (listener); 66 clipboard.fireClipboardChange (); 67 68 assertEquals ("no new change", 1, listener.cnt); 69 } 70 71 public void testConvert () { 72 class WillNotGetNull implements ExClipboard.Convertor { 73 public Transferable convert (Transferable t) { 74 assertNotNull ("Never get null", t); 75 return null; 76 } 77 } 78 79 convertors = new ExClipboard.Convertor[] { 80 new WillNotGetNull (), 81 new WillNotGetNull (), 82 new WillNotGetNull (), 83 }; 84 85 Transferable ret = clipboard.convert (new StringSelection ("Ahoj")); 86 assertNull ("Correctly returned null", ret); 87 assertNull ("Handle also null parameter", clipboard.convert (null)); 88 } 89 90 } 91 | Popular Tags |