How to fire value change event on TextField manually


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.argThat(new ArgumentMatcher<ValueChangeListener>() {

					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(

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


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( 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( 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?

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( 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: