Skip to content

Commit c00aa07

Browse files
vursenclaude
andcommitted
test: add unit test for setStep IllegalArgumentException
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 69da7a7 commit c00aa07

File tree

2 files changed

+21
-0
lines changed
  • vaadin-slider-flow-parent/vaadin-slider-flow/src

2 files changed

+21
-0
lines changed

vaadin-slider-flow-parent/vaadin-slider-flow/src/main/java/com/vaadin/flow/component/slider/Slider.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ public Slider(double min, double max, double value) {
7070
setValue(value);
7171
}
7272

73+
/**
74+
* @throws IllegalArgumentException
75+
* if the value is not between min and max
76+
*/
7377
@Override
7478
public void setValue(Double value) {
7579
if (value < getMin() || value > getMax()) {
@@ -85,6 +89,8 @@ public void setValue(Double value) {
8589
*
8690
* @param min
8791
* the minimum value
92+
* @throws IllegalArgumentException
93+
* if the min is greater than the max value
8894
*/
8995
public void setMin(double min) {
9096
if (min > getMax()) {
@@ -109,6 +115,8 @@ public double getMin() {
109115
*
110116
* @param max
111117
* the maximum value
118+
* @throws IllegalArgumentException
119+
* if the max is less than the min value
112120
*/
113121
public void setMax(double max) {
114122
if (max < getMin()) {
@@ -134,8 +142,15 @@ public double getMax() {
134142
*
135143
* @param step
136144
* the step value
145+
* @throws IllegalArgumentException
146+
* if the step is less than or equal to zero
137147
*/
138148
public void setStep(double step) {
149+
if (step <= 0) {
150+
throw new IllegalArgumentException(
151+
"The step value must be a positive number");
152+
}
153+
139154
getElement().setProperty("step", step);
140155
}
141156

vaadin-slider-flow-parent/vaadin-slider-flow/src/test/java/com/vaadin/flow/component/slider/tests/SliderTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,10 @@ public void setValue_greaterThanMax_throws() {
107107
Slider slider = new Slider(0, 100);
108108
slider.setValue(150.0);
109109
}
110+
111+
@Test(expected = IllegalArgumentException.class)
112+
public void setStep_notPositive_throws() {
113+
Slider slider = new Slider();
114+
slider.setStep(0);
115+
}
110116
}

0 commit comments

Comments
 (0)