Skip to content

Commit 7996fc8

Browse files
authored
Use mock network tables in tests (#675)
1 parent 953c09e commit 7996fc8

File tree

5 files changed

+562
-52
lines changed

5 files changed

+562
-52
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package edu.wpi.grip.core.operations.network.networktables;
2+
3+
import edu.wpi.grip.core.operations.network.NetworkReceiver;
4+
5+
import edu.wpi.first.wpilibj.tables.ITable;
6+
7+
import java.util.function.Consumer;
8+
9+
public class MockNTReceiver extends NetworkReceiver {
10+
11+
private final ITable table;
12+
13+
/**
14+
* Create a new NetworkReceiver with the specified path.
15+
*
16+
* @param path The path of the object to get
17+
* @param table the network table that values will be retrieved from
18+
*/
19+
public MockNTReceiver(String path, ITable table) {
20+
super(path);
21+
this.table = table;
22+
}
23+
24+
@Override
25+
public Object getValue() {
26+
return table.getValue(path);
27+
}
28+
29+
@Override
30+
public void addListener(Consumer<Object> consumer) {
31+
// Never called
32+
throw new UnsupportedOperationException();
33+
}
34+
35+
@Override
36+
public void close() {
37+
table.delete(path);
38+
}
39+
}

0 commit comments

Comments
 (0)