AnalysesToolBarImpl extends Composite implements AnalysisToolBarView { boolean canCancelSelection(final List<Analysis> selection) { for (Analysis ae : selection) { if (ae == null) continue; final String status = ae.getStatus(); if (SUBMITTED.toString().equalsIgnoreCase(status) || IDLE.toString().equalsIgnoreCase(status) || RUNNING.toString().equalsIgnoreCase(status)) { return true; } } return false; } @Inject  AnalysesToolBarImpl(final AnalysesView.Appearance appearance,
                        @Assisted final AnalysesView.Presenter presenter,
                        @Assisted PagingLoader<FilterPagingLoadConfig, PagingLoadResult<Analysis>> loader); @Override void filterByAnalysisId(String analysisId, String name); @Override void filterByParentAnalysisId(String analysisId); @Override void onSelectionChanged(SelectionChangedEvent<Analysis> event); @Override void setFilterInView(AnalysisFilter filter);  }
@Test public void testCanCancelSelection() { Analysis mock1 = mock(Analysis.class); when(mock1.getStatus()).thenReturn(SUBMITTED.toString()); assertTrue("Selection should be cancellable", uut.canCancelSelection(Lists.newArrayList(mock1))); when(mock1.getStatus()).thenReturn(RUNNING.toString()); assertTrue("Selection should be cancellable", uut.canCancelSelection(Lists.newArrayList(mock1))); when(mock1.getStatus()).thenReturn(IDLE.toString()); assertTrue("Selection should be cancellable", uut.canCancelSelection(Lists.newArrayList(mock1))); when(mock1.getStatus()).thenReturn(UNKNOWN.toString()); assertFalse("Selection should be not be cancellable", uut.canCancelSelection(Lists.newArrayList(mock1))); when(mock1.getStatus()).thenReturn(COMPLETED.toString()); assertFalse("Selection should be not be cancellable", uut.canCancelSelection(Lists.newArrayList(mock1))); when(mock1.getStatus()).thenReturn(HELD.toString()); assertFalse("Selection should be not be cancellable", uut.canCancelSelection(Lists.newArrayList(mock1))); when(mock1.getStatus()).thenReturn(FAILED.toString()); assertFalse("Selection should be not be cancellable", uut.canCancelSelection(Lists.newArrayList(mock1))); when(mock1.getStatus()).thenReturn(SUBMISSION_ERR.toString()); assertFalse("Selection should be not be cancellable", uut.canCancelSelection(Lists.newArrayList(mock1))); when(mock1.getStatus()).thenReturn(REMOVED.toString()); assertFalse("Selection should be not be cancellable", uut.canCancelSelection(Lists.newArrayList(mock1))); }