diff options
author | Sauli Tähkäpää <sauli@vaadin.com> | 2015-02-25 16:54:59 +0200 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2015-02-27 16:28:43 +0000 |
commit | f0a04197be3b536b23889bcce3178962b5e10733 (patch) | |
tree | 24e323e9f07c3eaedf1e7de7a64775a283db36d7 /server/tests | |
parent | c9586c93b93987d9b5942c38ef0b536c091092a5 (diff) | |
download | vaadin-framework-f0a04197be3b536b23889bcce3178962b5e10733.tar.gz vaadin-framework-f0a04197be3b536b23889bcce3178962b5e10733.zip |
Ensure that slider min is always smaller or equal to max. (#16776)
- Set slider min to max if max is being set to a smaller value than min,
and vice-versa.
- Set also an informative message to Slider.ValueOutOfBoundsException.
Change-Id: I06b6b05dd0ef2c1fb862cf4acc7df3e235db59ba
Diffstat (limited to 'server/tests')
-rw-r--r-- | server/tests/src/com/vaadin/tests/server/component/slider/SliderTest.java | 64 |
1 files changed, 54 insertions, 10 deletions
diff --git a/server/tests/src/com/vaadin/tests/server/component/slider/SliderTest.java b/server/tests/src/com/vaadin/tests/server/component/slider/SliderTest.java index f568da1392..48bba8a853 100644 --- a/server/tests/src/com/vaadin/tests/server/component/slider/SliderTest.java +++ b/server/tests/src/com/vaadin/tests/server/component/slider/SliderTest.java @@ -1,24 +1,68 @@ package com.vaadin.tests.server.component.slider; -import junit.framework.TestCase; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; import org.junit.Assert; +import org.junit.Test; import com.vaadin.ui.Slider; -import com.vaadin.ui.Slider.ValueOutOfBoundsException; -public class SliderTest extends TestCase { +public class SliderTest { - public void testOutOfBounds() { + @Test + public void minCannotBeLargerThanMax() { + Slider slider = new Slider(); + + slider.setMax(100); + slider.setMin(101); + + assertThat(slider.getMin(), is(101.0)); + assertThat(slider.getMax(), is(101.0)); + } + + @Test + public void maxCannotBeSmallerThanMin() { + Slider slider = new Slider(); + + slider.setMin(50); + slider.setMax(10); + + assertThat(slider.getMax(), is(10.0)); + assertThat(slider.getMin(), is(10.0)); + } + + @Test + public void valueOutOfBoundsExceptionMessageContainsBounds() { + Slider slider = new Slider(); + + try { + + slider.setValue(-1.0); + } catch (Slider.ValueOutOfBoundsException e) { + assertThat(e.getMessage(), + containsString("Value -1.0 is out of bounds: [0.0, 100.0]")); + } + } + + @Test + public void valueIsSet() { + Slider slider = new Slider(); + + slider.setValue(5.0); + + assertThat(slider.getValue(), is(5.0)); + } + + @Test + public void valueCannotBeOutOfBounds() { Slider s = new Slider(0, 10); - s.setValue(0.0); - Assert.assertEquals(0.0, s.getValue().doubleValue(), 0.001); - s.setValue(10.0); - Assert.assertEquals(10.0, s.getValue().doubleValue(), 0.001); + try { s.setValue(20.0); - fail("Should throw out of bounds exception"); - } catch (ValueOutOfBoundsException e) { + Assert.fail("Should throw out of bounds exception"); + } catch (Slider.ValueOutOfBoundsException e) { // TODO: handle exception } |