-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use mock network tables in tests (#675)
- Loading branch information
1 parent
953c09e
commit 7996fc8
Showing
5 changed files
with
562 additions
and
52 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
core/src/test/java/edu/wpi/grip/core/operations/network/networktables/MockNTReceiver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package edu.wpi.grip.core.operations.network.networktables; | ||
|
||
import edu.wpi.grip.core.operations.network.NetworkReceiver; | ||
|
||
import edu.wpi.first.wpilibj.tables.ITable; | ||
|
||
import java.util.function.Consumer; | ||
|
||
public class MockNTReceiver extends NetworkReceiver { | ||
|
||
private final ITable table; | ||
|
||
/** | ||
* Create a new NetworkReceiver with the specified path. | ||
* | ||
* @param path The path of the object to get | ||
* @param table the network table that values will be retrieved from | ||
*/ | ||
public MockNTReceiver(String path, ITable table) { | ||
super(path); | ||
this.table = table; | ||
} | ||
|
||
@Override | ||
public Object getValue() { | ||
return table.getValue(path); | ||
} | ||
|
||
@Override | ||
public void addListener(Consumer<Object> consumer) { | ||
// Never called | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
table.delete(path); | ||
} | ||
} |
Oops, something went wrong.