Tuesday, July 12, 2016

Simple radio button unit test using gwtmockito/mockito?

I wanted to write a simple unit test avoiding GWTTeseCase for an extension of a radio button.


This is the class:

public class DeselectableRadioButton extends RadioButton {

   
private Boolean backingValue;

   
private final class RadioButtonClickHandler implements ClickHandler {

       
public RadioButtonClickHandler(Boolean value) {
            backingValue
= value;
       
}

       
@Override
       
public void onClick(ClickEvent event) {
           
RadioButton button = (RadioButton) event.getSource();
           
if (!backingValue) {
                button
.setValue(true);
                backingValue
= true;
           
} else {
                button
.setValue(false);
                backingValue
= false;
           
}
       
}
   
}

   
/**
     * Constructor creates radio button with name and value
     *
     * @param name The name to be assigned to the radio button
     * @param value The default value to be given to the radio button
     */

   
public DeselectableRadioButton(String name, Boolean value) {
       
super(name);
       
this.setValue(value);
        setupHandlers
(value);
   
}

   
private void setupHandlers(Boolean value) {
        addClickHandler
(new RadioButtonClickHandler(value));
   
}

}



I was looking at some examples with GWTMockito such as: https://gist.github.com/nbuesing/7090529

But it doesn't seem possible with the current implementation of the widget I have?

Thanks for any help


--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment