### Question:
PipelineStateManager { Pipeline finalizePipeline(PipelineID pipelineId) throws PipelineNotFoundException { Pipeline pipeline = pipelineStateMap.getPipeline(pipelineId); if (!pipeline.isClosed()) { pipeline = pipelineStateMap .updatePipelineState(pipelineId, PipelineState.CLOSED); LOG.info("Pipeline {} moved to CLOSED state", pipeline); } return pipeline; } PipelineStateManager(); void addPipeline(Pipeline pipeline); List<Pipeline> getPipelines(); void activatePipeline(PipelineID pipelineID); void deactivatePipeline(PipelineID pipelineID); void updatePipelineState(PipelineID id, PipelineState newState);  }### Answer:
@Test public void testFinalizePipeline() throws IOException { Pipeline pipeline = createDummyPipeline(1); stateManager.addPipeline(pipeline); stateManager.finalizePipeline(pipeline.getId()); Assert.assertEquals(Pipeline.PipelineState.CLOSED, stateManager.getPipeline(pipeline.getId()).getPipelineState()); removePipeline(pipeline); pipeline = createDummyPipeline(1); stateManager.addPipeline(pipeline); stateManager.openPipeline(pipeline.getId()); stateManager.finalizePipeline(pipeline.getId()); Assert.assertEquals(Pipeline.PipelineState.CLOSED, stateManager.getPipeline(pipeline.getId()).getPipelineState()); removePipeline(pipeline); pipeline = createDummyPipeline(1); stateManager.addPipeline(pipeline); stateManager.openPipeline(pipeline.getId()); stateManager.finalizePipeline(pipeline.getId()); stateManager.finalizePipeline(pipeline.getId()); Assert.assertEquals(Pipeline.PipelineState.CLOSED, stateManager.getPipeline(pipeline.getId()).getPipelineState()); removePipeline(pipeline); }