0

I want to test JTextField.paste(), however it is not working.

I created a JUnit test with the following code:

JTextField textfield = new JTextField();
textfield.paste();
assertEquals("my text", textfield.getText())

however, textfield.getText() is empty (I copied "my text" to the clipboard, before)

Can you help me?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
matthias
  • 1,938
  • 23
  • 51
  • 1
    yeah, sure - where else if you are asking about a unit test ;-) Check if there's really something on the clipboard, f.i. along the lines of @Grove's answer – kleopatra Sep 17 '13 at 21:53
  • Cool, it is working. I am not sure what I did wrong, however it works now :-) – matthias Sep 18 '13 at 07:36

1 Answers1

0

Perhaps you could try forcing the "copy-to-clipboard" operation before pasting the text, as described here

Community
  • 1
  • 1
Morfic
  • 15,178
  • 3
  • 51
  • 61