PublishAnnotatedOperation extends
    NetworkPublishOperation<D> { protected Object get(Method accessor, Object instance) { try { return accessor.invoke(instance); } catch (IllegalAccessException | InvocationTargetException ex) { return null; } } protected  PublishAnnotatedOperation(InputSocket.Factory isf,
                                      Class<D> dataType,
                                      Class<P> publishType,
                                      Function<D, P> converter,
                                      MapNetworkPublisherFactory publisherFactory); Class<D> getSocketType(); @Override void cleanUp();  }
@Test public void testNTValueOrder() { Operation ntPublishOperation = new TestPublishAnnotatedOperation<>(SimpleReport.class); List<InputSocket> sockets = ntPublishOperation.getInputSockets(); assertEquals("Unexpected number of sockets", 4, sockets.size()); assertEquals("Wrong publish name", "Publish bar", sockets.get(2).getSocketHint() .getIdentifier()); assertEquals("Wrong publish name", "Publish foo", sockets.get(3).getSocketHint() .getIdentifier()); }
@Test @SuppressWarnings("unchecked") public void testPublishSimpleReportReturnsExpectedValues() { final String publisherName = "PUBLISH QUACKERY!"; final boolean[] publishNameChangedRan = {false}; final boolean[] doPublishRan = {false}; class TestMapNetworkPublisher<T> extends MapNetworkPublisher<T> { public TestMapNetworkPublisher(Set keys) { super(keys); } @Override protected void publishNameChanged(Optional oldName, String newName) { assertEquals("Name was not what was expected", newName, publisherName); assertFalse("There was an old name when there shouldn't have been", oldName.isPresent()); publishNameChangedRan[0] = true; } @Override public void close() { fail("Close should not have run!"); } @Override protected void doPublish() { fail("This should not have run"); } @Override protected void doPublish(Map<String, T> publishMap) { assertTrue("The first key didn't get passed to the map", publishMap.containsKey(SimpleReport.KEY_1)); assertTrue("The second key didn't get passed to the map", publishMap.containsKey(SimpleReport.KEY_2)); doPublishRan[0] = true; } @Override protected void doPublishSingle(T value) { fail("This should not have run"); } } final MapNetworkPublisherFactory factory = new MapNetworkPublisherFactory() { @Override public <T> MapNetworkPublisher<T> create(Set<String> keys) { return new TestMapNetworkPublisher<>(keys); } }; final TestPublishAnnotatedOperation<SimpleReport> testPublishAnnotatedOperation = new TestPublishAnnotatedOperation<>(SimpleReport.class, factory); final List<InputSocket> inputSockets = testPublishAnnotatedOperation.getInputSockets(); inputSockets.get(0).setValue(new SimpleReport()); inputSockets.get(1).setValue(publisherName); testPublishAnnotatedOperation.perform(); assertTrue("publishNameChanged never ran", publishNameChangedRan[0]); assertTrue("doPublish never ran", doPublishRan[0]); }