}
}
public void testTransferableTransferData()
{
Transferable transferable = transferHandler.createTransferable(component);
// Try invalid data flavor.
try
{
DataFlavor flavor = new DataFlavor("xyz/x-java-jvm-local-objectref; class=java.lang.String");
Object data = transferable.getTransferData(flavor);
fail("UnsupportedOperationException must be thrown");
}
catch (UnsupportedFlavorException ex)
{
// Ok.
}
catch (IOException ex)
{
fail("UnsupportedFlavorException must be thrown, no IOException");
}
catch (ClassNotFoundException ex)
{
fail(ex.getMessage());
}
// Try OK data flavor.
try
{
DataFlavor flavor = new DataFlavor("application/x-java-jvm-local-objectref; class=java.lang.String");
Object data = transferable.getTransferData(flavor);
assertEquals(data, "HelloWorld");
}
catch (UnsupportedFlavorException ex)
{
fail("UnsupportedFlavorException must not be thrown");
}
catch (IOException ex)
{
System.err.println(ex.getMessage());
fail("IOException must not be thrown");
}
catch (ClassNotFoundException ex)
{
fail(ex.getMessage());
}
// Try non-accessible component.
component = new JComponent()
{
public String getTestProperty()
{
return "Hello World";
}
};
transferable = transferHandler.createTransferable(component);
try
{
DataFlavor flavor = new DataFlavor("application/x-java-jvm-local-objectref; class=java.lang.String");
Object data = transferable.getTransferData(flavor);
fail("IOException must be thrown");
}
catch (UnsupportedFlavorException ex)
{
fail("UnsupportedFlavorException must not be thrown");