* {@code true} if this event originates from the client,
* {@code false} otherwise.
*/
+
public ValueChangeEvent(Component component, HasValue<V> hasValue,
boolean userOriginated) {
super(hasValue);
@FunctionalInterface
public interface ValueChangeListener<V>
extends Consumer<ValueChangeEvent<V>>, Serializable {
-
@Deprecated
public static final Method VALUE_CHANGE_METHOD = ReflectTools
.findMethod(ValueChangeListener.class, "accept",
/**
* Sets the selected color of this color picker. If the new color is not
- * equal to getValue(), fires a value change event.
+ * equal to getValue(), fires a {@link ValueChangeEvent}.
*
* @param color
* the new selected color, not null
+ * @throws NullPointerException
+ * if {@code color} is {@code null}
*/
@Override
public void setValue(Color color) {
return value;
}
+ /**
+ * Sets the value of this object. If the new value is not equal to
+ * {@code getValue()}, fires a {@link ValueChangeEvent} .
+ *
+ * @param value
+ * the new value, may be {@code null}
+ */
@Override
public void setValue(LocalDate value) {
/*
implements HasValue<T>, HasRequired, Focusable {
@Deprecated
- private static final Method VALUE_CHANGE_METHOD = ReflectTools
- .findMethod(ValueChangeListener.class, "accept", ValueChangeEvent.class);
+ private static final Method VALUE_CHANGE_METHOD = ReflectTools.findMethod(
+ ValueChangeListener.class, "accept", ValueChangeEvent.class);
@Override
public void setValue(T value) {
*
* @param value
* the items to select, not {@code null}
- * @throws IllegalArgumentException
+ * @throws NullPointerException
* if the value is invalid
*/
@Override
registerRpc(new AbstractTextFieldFocusAndBlurRpcImpl());
}
+ /**
+ * Sets the value of this text field. If the new value is not equal to
+ * {@code getValue()}, fires a {@link ValueChangeEvent}. Throws
+ * {@code NullPointerException} if the value is not null.
+ *
+ * @param value
+ * the new value, not {@code null}
+ * @throws NullPointerException
+ * if {@code value} is {@code null}
+ */
@Override
public void setValue(String value) {
- Objects.requireNonNull(value, "Null value not supported");
+ Objects.requireNonNull(value, "value cannot be null");
setValue(value, false);
}
package com.vaadin.ui;
import java.util.Collection;
+import java.util.Objects;
import org.jsoup.nodes.Attributes;
import org.jsoup.nodes.Element;
}
/**
- * Sets the value of this ComboBox. If the new value is not equal to
- * {@code getValue()}, fires a value change event. Throws
- * {@code IllegalArgumentException} if the value is null.
+ * Sets the value of this CheckBox. If the new value is not equal to
+ * {@code getValue()}, fires a {@link ValueChangeEvent}. Throws
+ * {@code NullPointerException} if the value is null.
*
* @param value
- * the new value
- * @throws IllegalArgumentException
- * if the value is null
+ * the new value, not {@code null}
+ * @throws NullPointerException
+ * if {@code value} is {@code null}
*/
@Override
public void setValue(Boolean value) {
- if (value == null) {
- throw new IllegalArgumentException(
- "CheckBox value must not be null");
- }
+ Objects.requireNonNull(value, "CheckBox value must not be null");
super.setValue(value);
}
this.filter = filter;
}
+ /**
+ * Sets the value of this object. If the new value is not equal to
+ * {@code getValue()}, fires a {@link ValueChangeEvent}.
+ *
+ * @param value
+ * the new value, may be {@code null}
+ */
@Override
public void setValue(T value) {
getSelectionModel().setSelectedFromServer(value);
package com.vaadin.ui;
+import java.util.Objects;
+
import org.jsoup.nodes.Element;
import com.vaadin.shared.ui.ValueChangeMode;
return (RichTextAreaState) super.getState(markAsDirty);
}
+ /**
+ * Sets the value of this object. If the new value is not equal to
+ * {@code getValue()}, fires a {@link ValueChangeEvent}. Throws
+ * {@code NullPointerException} if the value is null.
+ *
+ * @param value
+ * the new value, not {@code null}
+ * @throws NullPointerException
+ * if {@code value} is {@code null}
+ */
@Override
public void setValue(String value) {
- if (value == null) {
- setValue("", false);
- } else {
- setValue(value, false);
- }
+ Objects.requireNonNull(value, "value cannot be null");
+ setValue(value, false);
}
@Override
package com.vaadin.ui;
import java.util.Collection;
+import java.util.Objects;
import org.jsoup.nodes.Attributes;
import org.jsoup.nodes.Element;
getState().value = trimmedValue;
}
+ /**
+ * Sets the value of this object. If the new value is not equal to
+ * {@code getValue()}, fires a {@link ValueChangeEvent}. Throws
+ * {@code NullPointerException} if the value is null.
+ *
+ * @param value
+ * the new value, not {@code null}
+ * @throws NullPointerException
+ * if {@code value} is {@code null}
+ */
+ @Override
+ public void setValue(Double value) {
+ Objects.requireNonNull(value, "color cannot be null");
+ super.setValue(value);
+ }
+
@Override
public Double getValue() {
return getState().value;
*/
package com.vaadin.ui.components.colorpicker;
+import java.util.Objects;
+
import com.vaadin.shared.ui.colorpicker.Color;
import com.vaadin.shared.ui.colorpicker.ColorPickerGradientServerRpc;
import com.vaadin.shared.ui.colorpicker.ColorPickerGradientState;
this.converter = converter;
}
+ /**
+ * Sets the value of this object. If the new value is not equal to
+ * {@code getValue()}, fires a {@link ValueChangeEvent}. Throws
+ * {@code NullPointerException} if the value is null.
+ *
+ * @param color
+ * the new color, not {@code null}
+ * @throws NullPointerException
+ * if {@code color} is {@code null}
+ */
+ @Override
+ public void setValue(Color color) {
+ Objects.requireNonNull(color, "value must not be null");
+ super.setValue(color);
+ }
+
@Override
public Color getValue() {
return color;
import java.awt.Point;
import java.util.HashMap;
import java.util.Map;
+import java.util.Objects;
import com.vaadin.shared.ui.colorpicker.Color;
import com.vaadin.shared.ui.colorpicker.ColorPickerGridServerRpc;
return new int[] { x, y };
}
+ /**
+ * Sets the value of this object. If the new value is not equal to
+ * {@code getValue()}, fires a {@link ValueChangeEvent}. Throws
+ * {@code NullPointerException} if the value is null.
+ *
+ * @param color
+ * the new value, not {@code null}
+ * @throws NullPointerException
+ * if {@code color} is {@code null}
+ */
+ @Override
+ public void setValue(Color color) {
+ Objects.requireNonNull(color, "value cannot be null");
+ super.setValue(color);
+ }
+
@Override
public Color getValue() {
return colorGrid[x][y];
return history;
}
+ /**
+ * Sets the value of this object. If the new value is not equal to
+ * {@code getValue()}, fires a {@link ValueChangeEvent}. Throws
+ * {@code NullPointerException} if the value is null.
+ *
+ * @param color
+ * the new value, not {@code null}
+ * @throws NullPointerException
+ * if {@code color} is {@code null}
+ */
@Override
public void setValue(Color color) {
- if (color == null) {
- return;
- }
+ Objects.requireNonNull(color, "color cannot be null");
selectedColor = color;
setValue(color);
}
+ /**
+ * Sets the value of this object. If the new value is not equal to
+ * {@code getValue()}, fires a {@link ValueChangeEvent}. Throws
+ * {@code NullPointerException} if the value is null.
+ *
+ * @param color
+ * the new value, not {@code null}
+ * @throws NullPointerException
+ * if {@code color} is {@code null}
+ */
@Override
public void setValue(Color color) {
+ Objects.requireNonNull(color, "color cannot be null");
this.color = color;
// Unregister listener
}
oldValue = value;
- fireEvent(new ValueChangeEvent<>(this, event.isUserOriginated()));
+ fireEvent(
+ new ValueChangeEvent<>(this, event.isUserOriginated()));
}
} catch (NumberFormatException nfe) {
--- /dev/null
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.server.component.abstracttextfield;
+
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import com.vaadin.ui.AbstractTextField;
+
+/**
+ * @author Vaadin Ltd
+ *
+ */
+public class AbstractTextFieldTest {
+
+ @Test(expected = NullPointerException.class)
+ public void setValue_nullValue_throwsNPE() {
+ AbstractTextField field = Mockito.mock(AbstractTextField.class);
+ Mockito.doCallRealMethod().when(field).setValue(null);
+
+ field.setValue(null);
+ }
+}
--- /dev/null
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.server.component.colorpicker;
+
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import com.vaadin.ui.AbstractColorPicker;
+
+/**
+ * @author Vaadin Ltd
+ *
+ */
+public class AbstractColorPickerTest {
+
+ @Test(expected = NullPointerException.class)
+ public void setValue_nullValue_throwsNPE() {
+ AbstractColorPicker picker = Mockito.mock(AbstractColorPicker.class);
+ Mockito.doCallRealMethod().when(picker).setValue(null);
+
+ picker.setValue(null);
+ }
+}
--- /dev/null
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.server.component.colorpicker;
+
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import com.vaadin.shared.ui.colorpicker.Color;
+import com.vaadin.ui.AbstractColorPicker.Coordinates2Color;
+import com.vaadin.ui.components.colorpicker.ColorPickerGradient;
+import com.vaadin.ui.components.colorpicker.ColorPickerGrid;
+import com.vaadin.ui.components.colorpicker.ColorPickerPopup;
+import com.vaadin.ui.components.colorpicker.ColorPickerPreview;
+
+/**
+ * @author Vaadin Ltd
+ *
+ */
+public class ColorPickerComponentsTest {
+
+ @Test(expected = NullPointerException.class)
+ public void setValue_nullValue_colorPickerGradientThrowsNPE() {
+ ColorPickerGradient gradient = new ColorPickerGradient("foo",
+ Mockito.mock(Coordinates2Color.class));
+ gradient.setValue(null);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void setValue_nullValue_colorPickerGridThrowsNPE() {
+ ColorPickerGrid grid = new ColorPickerGrid();
+ grid.setValue(null);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void setValue_nullValue_colorPickerPopupThrowsNPE() {
+ ColorPickerPopup popup = new ColorPickerPopup(Color.WHITE);
+ popup.setValue(null);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void setValue_nullValue_colorPickerPreviewThrowsNPE() {
+ ColorPickerPreview preview = new ColorPickerPreview(Color.WHITE);
+ preview.setValue(null);
+ }
+}
assertThat(slider.getValue(), is(1.23));
}
+
+ @Test(expected = NullPointerException.class)
+ public void setValue_nullValue_throwNPE() {
+ Slider slider = new Slider();
+ slider.setValue(null);
+ }
}
Assert.assertFalse(cb.getValue());
}
+ @Test(expected = NullPointerException.class)
+ public void setValue_nullValue_throwsNPE() {
+ CheckBox cb = new CheckBox();
+ cb.setValue(null);
+ }
+
}
Assert.assertEquals("bar", tf.getValue());
}
- @Test
- public void setValueNullBecomesEmptyString() {
+ @Test(expected = NullPointerException.class)
+ public void setValue_nullValue_throwsNPE() {
RichTextArea tf = new RichTextArea();
tf.setValue(null);
- Assert.assertEquals("", tf.getValue());
}
@Test