Skip to content

Commit 79bdd9d

Browse files
committed
Merge pull request #475 from JLLeitschuh/core/sanityTests
Adds Sanity Tests to Most Core Packages
2 parents 21c6dc8 + e6dbe93 commit 79bdd9d

28 files changed

Lines changed: 220 additions & 36 deletions

core/src/main/java/edu/wpi/grip/core/OutputSocket.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.thoughtworks.xstream.annotations.XStreamAlias;
77
import edu.wpi.grip.core.events.SocketPreviewChangedEvent;
88

9+
import javax.annotation.Nullable;
910
import java.util.NoSuchElementException;
1011
import java.util.Optional;
1112

@@ -37,7 +38,7 @@ public void setValueOptional(Optional<? extends T> optionalValue) {
3738
}
3839

3940
@Override
40-
public void setValue(T value) {
41+
public void setValue(@Nullable T value) {
4142
super.setValue(value);
4243
}
4344

core/src/main/java/edu/wpi/grip/core/Palette.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import java.util.Map;
1212
import java.util.Optional;
1313

14+
import static com.google.common.base.Preconditions.checkNotNull;
15+
1416
/**
1517
* The palette is a library of operations that can be added as steps in the {@link Pipeline}
1618
*/
@@ -43,6 +45,6 @@ public Collection<Operation> getOperations() {
4345
* @return The operation with the specified unique name
4446
*/
4547
public Optional<Operation> getOperationByName(String name) {
46-
return Optional.ofNullable(this.operations.get(name));
48+
return Optional.ofNullable(this.operations.get(checkNotNull(name, "name cannot be null")));
4749
}
4850
}

core/src/main/java/edu/wpi/grip/core/PipelineRunner.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import edu.wpi.grip.core.util.service.AutoRestartingService;
1616
import edu.wpi.grip.core.util.service.RestartableService;
1717

18+
import javax.annotation.Nullable;
1819
import javax.inject.Inject;
1920
import java.util.concurrent.Executor;
2021
import java.util.concurrent.Semaphore;
@@ -206,7 +207,7 @@ public void onRunPipeline(RunPipelineEvent event) {
206207
}
207208

208209
@Subscribe
209-
public void onStopPipeline(StopPipelineEvent event) {
210+
public void onStopPipeline(@Nullable StopPipelineEvent event) {
210211
stopAsync();
211212
}
212213

core/src/main/java/edu/wpi/grip/core/Socket.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,16 @@
33
import com.google.common.base.MoreObjects;
44
import com.google.common.collect.ImmutableSet;
55
import com.google.common.eventbus.EventBus;
6-
import com.google.common.eventbus.Subscribe;
7-
import edu.wpi.grip.core.events.ConnectionAddedEvent;
8-
import edu.wpi.grip.core.events.ConnectionRemovedEvent;
96
import edu.wpi.grip.core.events.SocketChangedEvent;
107
import edu.wpi.grip.core.events.SocketConnectedChangedEvent;
118

9+
import javax.annotation.Nullable;
1210
import java.util.HashSet;
1311
import java.util.Optional;
1412
import java.util.Set;
1513

16-
import static com.google.common.base.Preconditions.checkState;
1714
import static com.google.common.base.Preconditions.checkNotNull;
15+
import static com.google.common.base.Preconditions.checkState;
1816

1917
/**
2018
* A Socket is an abstract wrapper for a value that can be updated and passed around operations. Sockets contain a set of hints
@@ -75,7 +73,7 @@ public synchronized void setValueOptional(Optional<? extends T> optionalValue) {
7573
*
7674
* @param value The value to store in this socket. Nullable.
7775
*/
78-
public void setValue(T value) {
76+
public void setValue(@Nullable T value) {
7977
setValueOptional(Optional.ofNullable(this.getSocketHint().getType().cast(value)));
8078

8179
}

core/src/main/java/edu/wpi/grip/core/SocketHint.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.google.common.base.MoreObjects;
44

5+
import javax.annotation.Nullable;
56
import java.util.Arrays;
67
import java.util.List;
78
import java.util.NoSuchElementException;
@@ -112,7 +113,7 @@ public Builder<T> initialValueSupplier(Supplier<T> initialValueSupplier) {
112113
return this;
113114
}
114115

115-
public Builder<T> initialValue(T value) {
116+
public Builder<T> initialValue(@Nullable T value) {
116117
this.initialValueSupplier = value == null ? Optional.empty() : Optional.of(() -> value);
117118
return this;
118119
}

core/src/main/java/edu/wpi/grip/core/SocketHints.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import java.util.List;
1111
import java.util.function.Supplier;
1212

13+
import static com.google.common.base.Preconditions.checkNotNull;
14+
1315

1416
/**
1517
* Commonly used {@link SocketHint SocketHints}
@@ -88,7 +90,7 @@ public static SocketHint<Boolean> createBooleanSocketHint(final String identifie
8890
}
8991

9092
public static SocketHint<Number> createNumberSocketHint(final String identifier, Number defaultValue) {
91-
return new SocketHint.Builder<>(Number.class).identifier(identifier).initialValue(defaultValue).build();
93+
return createNumberSocketHintBuilder(identifier, defaultValue).build();
9294
}
9395
}
9496

@@ -139,6 +141,6 @@ private static SocketHint.Builder<Number> createNumberSocketHintBuilder(final St
139141

140142
private static SocketHint.Builder<Number> createNumberSocketHintBuilder(final String identifier,
141143
final Number number) {
142-
return new SocketHint.Builder<>(Number.class).identifier(identifier).initialValue(number);
144+
return new SocketHint.Builder<>(Number.class).identifier(identifier).initialValue(checkNotNull(number, "Number can not be null"));
143145
}
144146
}

core/src/main/java/edu/wpi/grip/core/events/ConnectionRemovedEvent.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import com.google.common.base.MoreObjects;
44
import edu.wpi.grip.core.Connection;
55

6+
import static com.google.common.base.Preconditions.checkNotNull;
7+
68
/**
79
* An event that occurs when a connection is removed from the pipeline. This is triggered by the user deleting a
810
* connection with the GUI.
@@ -14,7 +16,7 @@ public class ConnectionRemovedEvent {
1416
* @param connection The connection being deleted
1517
*/
1618
public ConnectionRemovedEvent(Connection connection) {
17-
this.connection = connection;
19+
this.connection = checkNotNull(connection, "Connection cannot be null");
1820
}
1921

2022
/**

core/src/main/java/edu/wpi/grip/core/events/ExceptionEvent.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import edu.wpi.grip.core.util.ExceptionWitness;
44

5+
import javax.annotation.Nullable;
56
import java.util.Optional;
67

78
import static com.google.common.base.Preconditions.checkNotNull;
@@ -22,9 +23,9 @@ public final class ExceptionEvent {
2223
* @param message The message associated with this event.
2324
* If <tt>null</tt> will use {@link Exception#getMessage()}
2425
*/
25-
public ExceptionEvent(Object origin, Exception exception, String message) {
26+
public ExceptionEvent(Object origin, Exception exception, @Nullable String message) {
2627
this.exception = Optional.of(exception);
27-
this.origin = checkNotNull(origin, "The origin can not be null");
28+
this.origin = checkNotNull(origin, "The origin cannot be null");
2829
this.message = message != null ? message : exception.getMessage();
2930
}
3031

@@ -33,9 +34,9 @@ public ExceptionEvent(Object origin, Exception exception, String message) {
3334
* @param message The message associated with this event.
3435
*/
3536
public ExceptionEvent(Object origin, String message) {
36-
this.origin = checkNotNull(origin, "The origin can not be null");
37+
this.origin = checkNotNull(origin, "The origin cannot be null");
3738
this.exception = Optional.empty();
38-
this.message = message;
39+
this.message = checkNotNull(message, "The message cannot be null");
3940
}
4041

4142
/**

core/src/main/java/edu/wpi/grip/core/events/OperationAddedEvent.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import com.google.common.base.MoreObjects;
44
import edu.wpi.grip.core.Operation;
55

6+
import static com.google.common.base.Preconditions.checkNotNull;
7+
68
/**
79
* Event for when a new operation is added to the application. This happens, for example, if a user loads a new Python
810
* script, or at startup for the built-in operations. This is NOT the event for adding a new step to the pipeline.
@@ -14,7 +16,7 @@ public class OperationAddedEvent {
1416
* @param operation The operation being added
1517
*/
1618
public OperationAddedEvent(Operation operation) {
17-
this.operation = operation;
19+
this.operation = checkNotNull(operation, "Operation cannot be null");
1820
}
1921

2022
/**

core/src/main/java/edu/wpi/grip/core/events/SocketConnectedChangedEvent.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import com.google.common.base.MoreObjects;
44
import edu.wpi.grip.core.Socket;
55

6+
import static com.google.common.base.Preconditions.checkNotNull;
7+
68
/**
79
* This event is sent when the state of a socket (connected vs. disconnected) is changed. Specifically, this will only
810
* be called if the number of connections either goes to zero when it was non-zero, or when it was zero and one is
@@ -17,7 +19,7 @@ public class SocketConnectedChangedEvent {
1719
* @param socket The socket that was either connected or disconneted.
1820
*/
1921
public SocketConnectedChangedEvent(Socket socket) {
20-
this.socket = socket;
22+
this.socket = checkNotNull(socket, "Socket cannot be null");
2123
}
2224

2325
/**

0 commit comments

Comments
 (0)