ConfigRequestFulfiller implements RequestFulfiller { public void fulfillRequest(RunnableFunction onRequestFulfilled) { writeConfigResponse(); onRequestFulfilled.run(); } ConfigRequestFulfiller(
      ResponseWriter responseWriter,
      RootNodeFinder rootNodeFinder,
      EventHelper eventHelper,
      DeviceConfigFactory deviceConfigFactory); void fulfillRequest(RunnableFunction onRequestFulfilled);  }
@Test public void callsOnRequestFulfilled() { setupSuccessfulRequest(); testSubject.fulfillRequest(onRequestFulfilledMock); verify(onRequestFulfilledMock, times(1)).run(); }
@Test public void writesCorrectResponse() { setupSuccessfulRequest(); testSubject.fulfillRequest(onRequestFulfilledMock); verify(responseWriter).writeSuccessfulResponse(configJson); }
@Test public void recyclesNodes() { setupSuccessfulRequest(); testSubject.fulfillRequest(onRequestFulfilledMock); verify(rootNodeMock, times(1)).recycle(); verify(sourceNodeMock, times(1)).recycle(); }
@Test public void recyclesNodeOnceIfRootEqualsSource() { setupSuccessfulRequest(); reset(rootNodeFinder); reset(deviceConfigFactory); when(rootNodeFinder.getRootNodeFromSource(any())).thenReturn(sourceNodeMock); when(deviceConfigFactory.getDeviceConfig(sourceNodeMock)).thenReturn(deviceConfig); testSubject.fulfillRequest(onRequestFulfilledMock); verifyZeroInteractions(rootNodeMock); verify(sourceNodeMock, times(1)).recycle(); }
@Test public void doesNotRecycleSourceIfRestoreLastSourceSucceeds() { setupSuccessfulRequest(); when(eventHelper.restoreLastSource(sourceNodeMock)).thenReturn(true); testSubject.fulfillRequest(onRequestFulfilledMock); verify(rootNodeMock, times(1)).recycle(); verify(sourceNodeMock, never()).recycle(); }