NetworkTableEntrySource extends Source { @Override protected boolean updateOutputSockets() { try { output.setValue(networkReceiver.getValue()); } catch (ClassCastException ex) { getExceptionWitness().flagException(ex, getName() + " is not of type " + output.getSocketHint().getTypeLabel()); return false; } return true; } @AssistedInject  NetworkTableEntrySource(
      EventBus eventBus,
      ExceptionWitness.Factory exceptionWitnessFactory,
      OutputSocket.Factory osf,
      @Named("ntManager") MapNetworkReceiverFactory networkReceiverFactory,
      @Assisted Properties properties); @AssistedInject  NetworkTableEntrySource(
      EventBus eventBus,
      ExceptionWitness.Factory exceptionWitnessFactory,
      OutputSocket.Factory osf,
      @Named("ntManager") MapNetworkReceiverFactory networkReceiverFactory,
      @Assisted String path,
      @Assisted Types type); @Override String getName(); @Override Properties getProperties(); @Override void initialize(); @Subscribe void onSourceRemovedEvent(SourceRemovedEvent event);  }
@Test public void testBoolean() { source = new NetworkTableEntrySource(eventBus, origin -> new MockExceptionWitness(eventBus, origin), osf, testingNtManager, BOOLEAN_PATH, NetworkTableEntrySource.Types.BOOLEAN); assertTrue("Socket could not be updated", source.updateOutputSockets()); assertTrue("The socket's value was false, expected true.", (boolean) source.getOutputSockets().get(0).getValue().get()); }
@Test public void testBooleanWrongTypeNumber() { source = new NetworkTableEntrySource(eventBus, origin -> new MockExceptionWitness(eventBus, origin), osf, testingNtManager, NUMBER_PATH, NetworkTableEntrySource.Types.BOOLEAN); assertFalse("The socket was able to update with an invalid type", source.updateOutputSockets()); }
@Test public void testBooleanWrongTypeString() { source = new NetworkTableEntrySource(eventBus, origin -> new MockExceptionWitness(eventBus, origin), osf, testingNtManager, STRING_PATH, NetworkTableEntrySource.Types.BOOLEAN); assertFalse("The socket was able to update with an invalid type", source.updateOutputSockets()); }
@Test public void testNumber() { source = new NetworkTableEntrySource(eventBus, origin -> new MockExceptionWitness(eventBus, origin), osf, testingNtManager, NUMBER_PATH, NetworkTableEntrySource.Types.NUMBER); assertTrue("Socket could not be updated", source.updateOutputSockets()); assertEquals("Expected numbers to be equal -- they are not equal", TEST_NUMBER, (double) source.getOutputSockets().get(0).getValue().get(), 0.00001); }
@Test public void testNumberWrongTypeBoolean() { source = new NetworkTableEntrySource(eventBus, origin -> new MockExceptionWitness(eventBus, origin), osf, testingNtManager, BOOLEAN_PATH, NetworkTableEntrySource.Types.NUMBER); assertFalse("The socket was able to update with an invalid type", source.updateOutputSockets()); }
@Test public void testNumberWrongTypeString() { source = new NetworkTableEntrySource(eventBus, origin -> new MockExceptionWitness(eventBus, origin), osf, testingNtManager, STRING_PATH, NetworkTableEntrySource.Types.NUMBER); assertFalse("The socket was able to update with an invalid type", source.updateOutputSockets()); }
@Test public void testString() { source = new NetworkTableEntrySource(eventBus, origin -> new MockExceptionWitness(eventBus, origin), osf, testingNtManager, STRING_PATH, NetworkTableEntrySource.Types.STRING); assertTrue("Socket could not be updated", source.updateOutputSockets()); assertEquals("Expected Strings to be equal -- they are not equal", TEST_STRING, source.getOutputSockets().get(0).getValue().get()); }
@Test public void testStringWrongTypeBoolean() { source = new NetworkTableEntrySource(eventBus, origin -> new MockExceptionWitness(eventBus, origin), osf, testingNtManager, BOOLEAN_PATH, NetworkTableEntrySource.Types.STRING); assertFalse("The socket was able to update with an invalid type", source.updateOutputSockets()); }
@Test public void testStringWrongTypeNumber() { source = new NetworkTableEntrySource(eventBus, origin -> new MockExceptionWitness(eventBus, origin), osf, testingNtManager, NUMBER_PATH, NetworkTableEntrySource.Types.STRING); assertFalse("The socket was able to update with an invalid type", source.updateOutputSockets()); }