PollConfigurator { public static void observe(StateNode node, Poller poller) { NodeMap configurationMap = node.getMap(NodeFeatures.POLL_CONFIGURATION); MapProperty pollIntervalProperty = configurationMap .getProperty(PollConfigurationMap.POLL_INTERVAL_KEY); pollIntervalProperty.addChangeListener(e -> { int interval = (int) (double) e.getNewValue(); poller.setInterval(interval); }); } private  PollConfigurator(); static void observe(StateNode node, Poller poller);  }
@Test public void listensToProperty() { PollConfigurator.observe(stateTree.getRootNode(), new Poller(registry) { @Override public void setInterval(int interval) { pollerSetIntervalCalled.incrementAndGet(); pollerInterval.set(interval); }; }); Assert.assertEquals(-2, pollerInterval.get()); Assert.assertEquals(0, pollerSetIntervalCalled.get()); MapProperty pollIntervalProperty = stateTree.getRootNode() .getMap(NodeFeatures.POLL_CONFIGURATION) .getProperty(PollConfigurationMap.POLL_INTERVAL_KEY); pollIntervalProperty.setValue(100.0); Assert.assertEquals(100, pollerInterval.get()); Assert.assertEquals(1, pollerSetIntervalCalled.get()); pollIntervalProperty.setValue(-1.0); Assert.assertEquals(-1, pollerInterval.get()); Assert.assertEquals(2, pollerSetIntervalCalled.get()); }