AnalysesToolBarImpl extends Composite implements AnalysisToolBarView { boolean isSharable(List<Analysis> selection) { for (Analysis a : selection) { if ((!(a.getStatus().equals(COMPLETED.toString()) || a.getStatus().equals(FAILED.toString())) || !( a.isSharable()))) { return false; } } return true; } @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 testCanShareSelection() { Analysis mock1 = mock(Analysis.class); Analysis mock2 = mock(Analysis.class); when(mock1.getStatus()).thenReturn(SUBMITTED.toString()); when(mock2.getStatus()).thenReturn(RUNNING.toString()); when(mock1.isSharable()).thenReturn(true); when(mock2.isSharable()).thenReturn(true); assertFalse("Selection should not be sharable", uut.isSharable(Lists.newArrayList(mock1, mock2))); when(mock1.getStatus()).thenReturn(COMPLETED.toString()); when(mock2.getStatus()).thenReturn(RUNNING.toString()); when(mock1.isSharable()).thenReturn(true); when(mock2.isSharable()).thenReturn(true); assertFalse("Selection should not be sharable", uut.isSharable(Lists.newArrayList(mock1, mock2))); when(mock1.getStatus()).thenReturn(COMPLETED.toString()); when(mock2.getStatus()).thenReturn(FAILED.toString()); when(mock1.isSharable()).thenReturn(false); when(mock2.isSharable()).thenReturn(false); assertFalse("Selection should not be sharable", uut.isSharable(Lists.newArrayList(mock1, mock2))); when(mock1.getStatus()).thenReturn(COMPLETED.toString()); when(mock2.getStatus()).thenReturn(FAILED.toString()); when(mock1.isSharable()).thenReturn(false); when(mock2.isSharable()).thenReturn(true); assertFalse("Selection should not be sharable", uut.isSharable(Lists.newArrayList(mock1, mock2))); when(mock1.getStatus()).thenReturn(COMPLETED.toString()); when(mock2.getStatus()).thenReturn(FAILED.toString()); when(mock1.isSharable()).thenReturn(true); when(mock2.isSharable()).thenReturn(true); assertTrue("Selection should be sharable", uut.isSharable(Lists.newArrayList(mock1, mock2))); }