Skip to content

Commit b3c1979

Browse files
author
nicolaiparlog
committed
Improve null tests in 'concurrent.when'
1 parent 77fb7a0 commit b3c1979

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

src/main/java/org/codefx/libfx/concurrent/when/ExecuteAlwaysWhen.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ public class ExecuteAlwaysWhen<T> {
110110
* the action which will be executed
111111
*/
112112
ExecuteAlwaysWhen(ObservableValue<T> observable, Predicate<? super T> condition, Consumer<? super T> action) {
113+
assert observable != null : "The argument 'observable' must not be null.";
114+
assert condition != null : "The argument 'condition' must not be null.";
115+
assert action != null : "The argument 'action' must not be null.";
116+
113117
this.observable = observable;
114118
this.condition = condition;
115119
this.action = action;

src/main/java/org/codefx/libfx/concurrent/when/ExecuteOnceWhen.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* value (the one tested during {@code executeWhen()}) or one of several which were set by those threads.
2626
* <p>
2727
* Use {@link ExecuteWhen} to build an instance of this class.
28-
*
28+
*
2929
* @param <T>
3030
* the type the observed {@link ObservableValue}'s wraps
3131
*/
@@ -96,6 +96,10 @@ public class ExecuteOnceWhen<T> {
9696
* the action which will be executed
9797
*/
9898
ExecuteOnceWhen(ObservableValue<T> observable, Predicate<? super T> condition, Consumer<? super T> action) {
99+
assert observable != null : "The argument 'observable' must not be null.";
100+
assert condition != null : "The argument 'condition' must not be null.";
101+
assert action != null : "The argument 'action' must not be null.";
102+
99103
this.observable = observable;
100104
this.condition = condition;
101105
this.action = action;

src/main/java/org/codefx/libfx/concurrent/when/ExecuteWhen.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public class ExecuteWhen<T> {
4949
* the {@link ObservableValue} which will be observed by the created {@code Execute...When} instances
5050
*/
5151
private ExecuteWhen(ObservableValue<T> observable) {
52+
Objects.requireNonNull(observable, "The argument 'observable' must not be null.");
53+
5254
this.observable = observable;
5355
condition = Optional.empty();
5456
}
@@ -79,6 +81,7 @@ public static <T> ExecuteWhen<T> on(ObservableValue<T> observable) {
7981
*/
8082
public ExecuteWhen<T> when(Predicate<? super T> condition) {
8183
Objects.requireNonNull(condition, "The argument 'condition' must not be null.");
84+
8285
this.condition = Optional.of(condition);
8386
return this;
8487
}
@@ -104,6 +107,8 @@ public ExecuteWhen<T> when(Predicate<? super T> condition) {
104107
* if {@link #when(Predicate)} was not called
105108
*/
106109
public ExecuteOnceWhen<T> thenOnce(Consumer<? super T> action) throws IllegalStateException {
110+
Objects.requireNonNull(action, "The argument 'action' must not be null.");
111+
107112
ensureConditionWasSet();
108113
return new ExecuteOnceWhen<T>(observable, condition.get(), action);
109114
}
@@ -125,6 +130,8 @@ public ExecuteOnceWhen<T> thenOnce(Consumer<? super T> action) throws IllegalSta
125130
* if {@link #when(Predicate)} was not called
126131
*/
127132
public ExecuteAlwaysWhen<T> thenAlways(Consumer<? super T> action) throws IllegalStateException {
133+
Objects.requireNonNull(action, "The argument 'action' must not be null.");
134+
128135
ensureConditionWasSet();
129136
return new ExecuteAlwaysWhen<T>(observable, condition.get(), action);
130137
}
@@ -139,7 +146,7 @@ private void ensureConditionWasSet() throws IllegalStateException {
139146
boolean noCondition = !condition.isPresent();
140147
if (noCondition)
141148
throw new IllegalStateException(
142-
"Set a condition with 'when(Predicate<? super T>)' before calling any 'then' method.");
149+
"Set a condition with 'when(Predicate<? super T>)' before calling any 'then...' method.");
143150
}
144151

145152
// #end BUILD

0 commit comments

Comments
 (0)