Skip to content

Commit

Permalink
Only use networktables when we need it
Browse files Browse the repository at this point in the history
  • Loading branch information
AustinShalit committed Aug 27, 2016
1 parent d2e9bd8 commit 40450c5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package edu.wpi.grip.core.operations.network;

import edu.wpi.grip.core.operations.network.networktables.TestingNTManager;
import edu.wpi.grip.core.operations.network.ros.MockROSManager;
import edu.wpi.grip.core.operations.network.ros.ROSNetworkPublisherFactory;

Expand All @@ -25,6 +24,6 @@ protected void configure() {

bind(MapNetworkReceiverFactory.class)
.annotatedWith(Names.named("ntManager"))
.to(TestingNTManager.class);
.to(MockNetworkReceiver.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package edu.wpi.grip.core.operations.network;

public class MockNetworkReceiver implements MapNetworkReceiverFactory {

@Override
public NetworkReceiver create(String path) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* This class encapsulates the way we map various settings to the global NetworkTables state.
*/
@Singleton
public class TestingNTManager extends NTManager {
public class TestingNTManager extends NTManager implements AutoCloseable {

private static final Logger logger = Logger.getLogger(TestingNTManager.class.getName());

Expand All @@ -33,4 +33,9 @@ public TestingNTManager() {
NetworkTable.initialize();
}

@Override
public void close() {
NetworkTable.shutdown();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import edu.wpi.first.wpilibj.networktables.NetworkTablesJNI;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
Expand All @@ -20,9 +21,9 @@ public class NetworkTableEntrySourceTest {

private final EventBus eventBus;
private final MockOutputSocketFactory osf;
private final TestingNTManager testingNtManager;

private NetworkTableEntrySource source;
private TestingNTManager testingNtManager;

private static final double TEST_NUMBER = 13.13;
private static final String TEST_STRING = "Some test string";
Expand All @@ -33,6 +34,10 @@ public class NetworkTableEntrySourceTest {
public NetworkTableEntrySourceTest() {
eventBus = new EventBus();
osf = new MockOutputSocketFactory(eventBus);
}

@Before
public void setUp() {
testingNtManager = new TestingNTManager();

NetworkTablesJNI.putBoolean(BOOLEAN_PATH, true);
Expand All @@ -41,8 +46,9 @@ public NetworkTableEntrySourceTest() {
}

@After
public void cleanup() {
public void tearDown() {
eventBus.post(new SourceRemovedEvent(source));
testingNtManager.close();
}

@Test
Expand Down

0 comments on commit 40450c5

Please sign in to comment.