assertj / assertj-swing

Fluent assertions for Swing apps
Other
108 stars 52 forks source link

BasicJTableCellWriter unable to enter an empty string #173

Closed baudren closed 8 years ago

baudren commented 8 years ago

Hi,

I am using the BasicJTableCellWriter to fill a swing table. I recover the initial values, set some new ones, then I would like to restore the table to its initial state. Some of the fields had no value at all, and their value is therefore stored as an empty string.

However, when executing the following:

BasicJTableCellWriter writer = new BasicJTableCellWriter(this.robot);
writer.enterValue(table.target(), 0, 0, "");

the call throws an exception,

java.lang.IllegalArgumentException: Argument expected not to be empty!
    at org.assertj.core.util.Preconditions.throwExceptionForBeingEmpty(Preconditions.java:107)
    at org.assertj.core.util.Preconditions.checkNotNullOrEmpty(Preconditions.java:49)
    at org.assertj.core.util.Preconditions.checkNotNullOrEmpty(Preconditions.java:34)
    at org.assertj.swing.driver.JTextComponentDriver.replaceText(JTextComponentDriver.java:113)
    at org.assertj.swing.driver.JTableTextComponentEditorCellWriter.enterValue(JTableTextComponentEditorCellWriter.java:51)
    at org.assertj.swing.driver.BasicJTableCellWriter.enterValue(BasicJTableCellWriter.java:66)

I don't really understand the point of this check. The field is a standard textbox, and an empty value should be completely ok. The guilty part of the code seems to be the fact that the method enterValue from JTableTextComponentEditorCellWriter calls the replaceText from JTextComponentDriver. The method deleteText is not accessible from the Cell Writer.

I think there should either be another method, maybe deleteValue, for the CellWriter, or that the method enterValue should handle the empty string case and call deleteText. Or am I missing something in the way to edit tables?

Thanks in advance,

croesch commented 8 years ago

Thanks for reporting! I'm working on a solution..

croesch commented 8 years ago

Part of 3.1.1.

baudren commented 8 years ago

Excellent, thank you!