Search in sources :

Example 1 with MockValueChangeHandler

use of com.googlecode.gwt.MockValueChangeHandler in project gwt-test-utils by gwt-test-utils.

the class RadioButtonTest method clickOnDetachedRadionButton.

@Test
public void clickOnDetachedRadionButton() {
    // Given
    RadioButton rb0 = new RadioButton("myRadioGroup", "foo");
    rb0.setValue(true);
    RootPanel.get().add(rb0);
    MockValueChangeHandler<Boolean> rb0MockChangeHandler = new MockValueChangeHandler<Boolean>();
    rb0.addValueChangeHandler(rb0MockChangeHandler);
    RadioButton rb1 = new RadioButton("myRadioGroup", "bar");
    RootPanel.get().add(rb1);
    MockValueChangeHandler<Boolean> rb1MockChangeHandler = new MockValueChangeHandler<Boolean>();
    rb1.addValueChangeHandler(rb1MockChangeHandler);
    // Preconditions
    assertThat(rb0.getValue()).isTrue();
    assertThat(rb0MockChangeHandler.getCallCount()).isEqualTo(0);
    assertThat(rb1.getValue()).isFalse();
    assertThat(rb1MockChangeHandler.getCallCount()).isEqualTo(0);
    // When
    RootPanel.get().remove(rb1);
    Browser.click(rb1);
    // Then
    assertThat(rb1.getValue()).isTrue();
    assertThat(rb1MockChangeHandler.getCallCount()).isEqualTo(1);
    assertThat(rb0.getValue()).isTrue();
    assertThat(rb0MockChangeHandler.getCallCount()).isEqualTo(0);
}
Also used : RadioButton(com.google.gwt.user.client.ui.RadioButton) MockValueChangeHandler(com.googlecode.gwt.MockValueChangeHandler) Test(org.junit.Test)

Example 2 with MockValueChangeHandler

use of com.googlecode.gwt.MockValueChangeHandler in project gwt-test-utils by gwt-test-utils.

the class RadioButtonTest method radioButton_Group.

@Test
public void radioButton_Group() {
    // Given
    RadioButton rb0 = new RadioButton("myRadioGroup", "foo");
    RootPanel.get().add(rb0);
    MockValueChangeHandler<Boolean> rb0MockChangeHandler = new MockValueChangeHandler<Boolean>();
    rb0.addValueChangeHandler(rb0MockChangeHandler);
    RadioButton rb1 = new RadioButton("myRadioGroup", "bar");
    RootPanel.get().add(rb1);
    MockValueChangeHandler<Boolean> rb1MockChangeHandler = new MockValueChangeHandler<Boolean>();
    rb1.addValueChangeHandler(rb1MockChangeHandler);
    RadioButton rb2 = new RadioButton("myRadioGroup", "baz");
    RootPanel.get().add(rb2);
    MockValueChangeHandler<Boolean> rb2MockChangeHandler = new MockValueChangeHandler<Boolean>();
    rb2.addValueChangeHandler(rb2MockChangeHandler);
    // When 1
    Browser.click(rb1);
    // Then 1
    assertThat(rb0.getValue()).isEqualTo(false);
    assertThat(rb0MockChangeHandler.getCallCount()).isEqualTo(0);
    assertThat(rb1.getValue()).isEqualTo(true);
    assertThat(rb1MockChangeHandler.getCallCount()).isEqualTo(1);
    assertThat(rb1MockChangeHandler.getLast()).isTrue();
    assertThat(rb2.getValue()).isEqualTo(false);
    assertThat(rb2MockChangeHandler.getCallCount()).isEqualTo(0);
    // When 2
    Browser.click(rb2);
    // Then 2
    assertThat(rb0.getValue()).isEqualTo(false);
    assertThat(rb0MockChangeHandler.getCallCount()).isEqualTo(0);
    assertThat(rb1.getValue()).isEqualTo(false);
    assertThat(rb1MockChangeHandler.getCallCount()).isEqualTo(2);
    assertThat(rb1MockChangeHandler.getLast()).isFalse();
    assertThat(rb2.getValue()).isEqualTo(true);
    assertThat(rb2MockChangeHandler.getCallCount()).isEqualTo(1);
    assertThat(rb2MockChangeHandler.getLast()).isTrue();
}
Also used : RadioButton(com.google.gwt.user.client.ui.RadioButton) MockValueChangeHandler(com.googlecode.gwt.MockValueChangeHandler) Test(org.junit.Test)

Example 3 with MockValueChangeHandler

use of com.googlecode.gwt.MockValueChangeHandler in project gwt-test-utils by gwt-test-utils.

the class RadioButtonTest method clickNotDetachedRadioButton.

@Test
public void clickNotDetachedRadioButton() {
    // Given
    RadioButton rb0 = new RadioButton("myRadioGroup", "foo");
    MockValueChangeHandler<Boolean> rb0MockChangeHandler = new MockValueChangeHandler<Boolean>();
    rb0.addValueChangeHandler(rb0MockChangeHandler);
    RadioButton rb1 = new RadioButton("myRadioGroup", "bar");
    MockValueChangeHandler<Boolean> rb1MockChangeHandler = new MockValueChangeHandler<Boolean>();
    rb1.addValueChangeHandler(rb1MockChangeHandler);
    // When
    Browser.click(rb0);
    Browser.click(rb1);
    // Then
    assertThat(rb0.getValue()).isTrue();
    assertThat(rb0MockChangeHandler.getCallCount()).isEqualTo(1);
    assertThat(rb1.getValue()).isTrue();
    assertThat(rb1MockChangeHandler.getCallCount()).isEqualTo(1);
}
Also used : RadioButton(com.google.gwt.user.client.ui.RadioButton) MockValueChangeHandler(com.googlecode.gwt.MockValueChangeHandler) Test(org.junit.Test)

Example 4 with MockValueChangeHandler

use of com.googlecode.gwt.MockValueChangeHandler in project gwt-test-utils by gwt-test-utils.

the class RadioButtonTest method changeName.

@Test
public void changeName() {
    // Given
    RadioButton rb0 = new RadioButton("myRadioGroup", "foo");
    RootPanel.get().add(rb0);
    MockValueChangeHandler<Boolean> rb0MockChangeHandler = new MockValueChangeHandler<Boolean>();
    rb0.addValueChangeHandler(rb0MockChangeHandler);
    RadioButton rb1 = new RadioButton("myRadioGroup", "bar");
    RootPanel.get().add(rb1);
    MockValueChangeHandler<Boolean> rb1MockChangeHandler = new MockValueChangeHandler<Boolean>();
    rb1.addValueChangeHandler(rb1MockChangeHandler);
    // When 1
    rb0.setName("changedGroup");
    Browser.click(rb0);
    // Then 1
    assertThat(rb0.getValue()).isTrue();
    assertThat(rb0MockChangeHandler.getCallCount()).isEqualTo(1);
    // When 2
    rb1.setName("changedGroup");
    Browser.click(rb1);
    assertThat(rb0.getValue()).isFalse();
    assertThat(rb0MockChangeHandler.getCallCount()).isEqualTo(2);
    assertThat(rb0MockChangeHandler.getLast()).isFalse();
    assertThat(rb1.getValue()).isTrue();
    assertThat(rb1MockChangeHandler.getCallCount()).isEqualTo(1);
    assertThat(rb1MockChangeHandler.getLast()).isTrue();
}
Also used : RadioButton(com.google.gwt.user.client.ui.RadioButton) MockValueChangeHandler(com.googlecode.gwt.MockValueChangeHandler) Test(org.junit.Test)

Aggregations

RadioButton (com.google.gwt.user.client.ui.RadioButton)4 MockValueChangeHandler (com.googlecode.gwt.MockValueChangeHandler)4 Test (org.junit.Test)4