Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
How to fire value change event on TextField manually
Hi,
I have added the ValueChangeListener to a textField. Anyhow the event is listening fine but for a Mockito testcase i have to fire the value change event manually,
so that i can verify it using Mockito-Junit . Here please have a look at my code..
Mockito.verify(weightField).addListener(
Mockito.argThat(new ArgumentMatcher<ValueChangeListener>() {
@Override
public boolean matches(final Object argument) {
changeListener = (ValueChangeListener) argument;
return true;
}
}));
// here am firing value change event manually of weightField
changeListener.valueChange((weightField).new ValueChangeEvent(
weightField));
}
but am getting the compilation error "Illegal enclosing instance specification for type Field.ValueChangeEvent" . Please clarify the way to fire the event manually.. eagerly waiting for reply..
thanks & regards in advance
Rakesh
Change the value with setValue() and it'll fire a ValueChangeEvent.
Jens Jansson: Change the value with setValue() and it'll fire a ValueChangeEvent.
Hi Jansson, i have tried with changing the value for the field using setValue() but no luck. Actually i fired button click event like
private ClickListener saveButtonListener; //initializied using stubbing in mockito f/m
private final Button save = Mockito.mock(Button.class); // save is a Mock object
saveButtonListener.buttonClick(save.new ClickEvent(save));
and hence i tried firing value change event by
private ValueChangeListener changeListener; //initializied using stubbing in mockito f/m
private final Field weightField = Mockito.mock(Button.class); // weight is a Mock object
changeListener.valueChange(weightField.new ValueChangeEvent(
weightField)); // compilation error here as explained in above
but event not fired for both approaches..
Do you have other idea?
Well if you just mock a field then the field.setValue will most likely not have an implementation behind it that would call a valuechangelistener. Do you really want to mock fields and then actually use them?
Do you really want to mock fields and then actually use them?
Yes because am using Mokito with Junit f/m to test functionality. Since weightField is mock object it could remember the interactions happened on it and i can verify the same using verify statement on mock field.
I'm not familiar with Junit f/m but how about instead of calling
changeListener.valueChange(weightField.new ValueChangeEvent(weightField));
you would call
changeListener.valueChange((new Field.ValueChangeEvent(weightField));/code]
Thank you Jens Jansson, finally am able to fire the event using Custom listener...:lol: