PipelineNodeUtil { public static @CheckForNull String getCauseOfBlockage(@Nonnull FlowNode stage, @Nullable FlowNode nodeBlock) { if(nodeBlock != null){ for(FlowNode p:nodeBlock.getParents()){ if(p.equals(stage)){ Queue.Item item = QueueItemAction.getQueueItem(nodeBlock); if (item != null) { CauseOfBlockage causeOfBlockage = item.getCauseOfBlockage(); String cause = null; if (causeOfBlockage != null) { cause = causeOfBlockage.getShortDescription(); if (cause == null) { causeOfBlockage = item.task.getCauseOfBlockage(); if(causeOfBlockage != null) { return causeOfBlockage.getShortDescription(); } } } return cause; } } } } return null; }  @Nonnull static BlueRun.BlueRunResult getStatus(@Nullable ErrorAction errorAction); @Nonnull static BlueRun.BlueRunResult getStatus(@Nonnull Throwable error); @Nonnull static String getDisplayName(@Nonnull FlowNode node); static boolean isStage(FlowNode node); static boolean isSyntheticStage(@Nullable FlowNode node); @CheckForNull static TagsAction getSyntheticStage(@Nullable FlowNode node); static boolean isPostSyntheticStage(@Nullable FlowNode node); static boolean isSkippedStage(@Nullable FlowNode node); static boolean isPreSyntheticStage(@Nullable FlowNode node); static boolean isParallelBranch(@Nullable FlowNode node); static @CheckForNull String getCauseOfBlockage(@Nonnull FlowNode stage, @Nullable FlowNode nodeBlock); static boolean isPausedForInputStep(@Nonnull StepAtomNode step, @Nullable InputAction inputAction); static boolean isAgentStart(@Nullable FlowNode node); static final Predicate<FlowNode> isLoggable; }
@Test public void getCauseOfBlockage() throws Exception { CauseOfBlockage blockage = mock(CauseOfBlockage.class); CauseOfBlockage taskBlockage = mock(CauseOfBlockage.class); FlowNode stage = mock(FlowNode.class); FlowNode nodeBlock = mock(FlowNode.class); Queue.Item item = mock(Queue.Item.class); mockStatic(QueueItemAction.class); String cause = null; cause = PipelineNodeUtil.getCauseOfBlockage(stage, null); assertNull(cause); when(nodeBlock.getParents()).thenReturn(ImmutableList.of()); cause = PipelineNodeUtil.getCauseOfBlockage(stage, null); assertNull(cause); when(nodeBlock.getParents()).thenReturn(ImmutableList.of(stage)); when(QueueItemAction.getQueueItem(nodeBlock)).thenReturn(null); cause = PipelineNodeUtil.getCauseOfBlockage(stage, null); assertNull(cause); when(QueueItemAction.getQueueItem(nodeBlock)).thenReturn(item); when(item.getCauseOfBlockage()).thenReturn(null); cause = PipelineNodeUtil.getCauseOfBlockage(stage, null); assertNull(cause); when(blockage.getShortDescription()).thenReturn("test"); when(item.getCauseOfBlockage()).thenReturn(blockage); cause = PipelineNodeUtil.getCauseOfBlockage(stage, nodeBlock); assertEquals("test", cause); when(blockage.getShortDescription()).thenReturn(null); cause = PipelineNodeUtil.getCauseOfBlockage(stage, null); assertNull(cause); when(taskBlockage.getShortDescription()).thenReturn("test1"); Whitebox.setInternalState(item,"task", mock(Queue.Task.class)); when(item.task.getCauseOfBlockage()).thenReturn(taskBlockage); cause = PipelineNodeUtil.getCauseOfBlockage(stage, nodeBlock); assertEquals("test1", cause); }