import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
-import edu.emory.mathcs.backport.java.util.Collections;
import org.sonar.api.ServerComponent;
import org.sonar.api.issue.IssueFinder;
import org.sonar.api.issue.IssueQuery;
import org.sonar.server.user.UserSession;
import javax.annotation.CheckForNull;
+
import java.util.List;
import java.util.Map;
}
public List<DefaultIssueFilter> findFavoriteFilters(UserSession userSession) {
- if (!userSession.isLoggedIn()) {
- return Collections.emptyList();
- }
return toIssueFilters(filterDao.selectFavoriteFiltersByUser(getLoggedLogin(userSession)));
}
@Test
public void should_not_save_shared_filter_if_name_already_used_by_shared_filter() {
- when(issueFilterDao.selectByUser(eq("john"))).thenReturn(Collections.<IssueFilterDto>emptyList());
+ when(issueFilterDao.selectByUser(eq("john"))).thenReturn(Collections.<IssueFilterDto> emptyList());
when(issueFilterDao.selectSharedFilters()).thenReturn(newArrayList(new IssueFilterDto().setId(1L).setName("My Issue").setUserLogin("henry").setShared(true)));
DefaultIssueFilter issueFilter = new DefaultIssueFilter().setName("My Issue").setShared(true);
try {
when(issueFilterDao.selectSharedFilters()).thenReturn(newArrayList(
new IssueFilterDto().setId(1L).setName("My Issue").setUserLogin("john").setShared(true),
new IssueFilterDto().setId(2L).setName("Project Issues").setUserLogin("arthur").setShared(true)
- ));
+ ));
List<DefaultIssueFilter> results = service.findSharedFiltersWithoutUserFilters(userSession);
assertThat(results).hasSize(1);
}
@Test
- public void should_find_empty_favourite_issue_filter_if_not_logged() {
+ public void should_not_find_favourite_issue_filter_if_not_logged() {
UserSession userSession = MockUserSession.create().setLogin(null);
- assertThat(service.findFavoriteFilters(userSession)).isEmpty();
+
+ try {
+ service.findFavoriteFilters(userSession);
+ fail();
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(UnauthorizedException.class).hasMessage("User is not logged in");
+ }
}
@Test
public void should_add_favourite_issue_filter_id() {
when(issueFilterDao.selectById(1L)).thenReturn(new IssueFilterDto().setId(1L).setName("My Issues").setUserLogin("john").setData("componentRoots=struts"));
// The filter is not in the favorite list --> add to favorite
- when(issueFilterFavouriteDao.selectByFilterId(1L)).thenReturn(Collections.<IssueFilterFavouriteDto>emptyList());
+ when(issueFilterFavouriteDao.selectByFilterId(1L)).thenReturn(Collections.<IssueFilterFavouriteDto> emptyList());
ArgumentCaptor<IssueFilterFavouriteDto> issueFilterFavouriteDtoCaptor = ArgumentCaptor.forClass(IssueFilterFavouriteDto.class);
service.toggleFavouriteIssueFilter(1L, userSession);
public void should_add_favourite_on_shared_filter() {
when(issueFilterDao.selectById(1L)).thenReturn(new IssueFilterDto().setId(1L).setName("My Issues").setUserLogin("arthur").setShared(true));
// The filter is not in the favorite list --> add to favorite
- when(issueFilterFavouriteDao.selectByFilterId(1L)).thenReturn(Collections.<IssueFilterFavouriteDto>emptyList());
+ when(issueFilterFavouriteDao.selectByFilterId(1L)).thenReturn(Collections.<IssueFilterFavouriteDto> emptyList());
ArgumentCaptor<IssueFilterFavouriteDto> issueFilterFavouriteDtoCaptor = ArgumentCaptor.forClass(IssueFilterFavouriteDto.class);
service.toggleFavouriteIssueFilter(1L, userSession);
if (o != null && o instanceof IssueFilterDto) {
IssueFilterDto otherFilter = (IssueFilterDto) o;
return ObjectUtils.equals(referenceFilter.isShared(), otherFilter.isShared())
- && ObjectUtils.equals(referenceFilter.getUserLogin(), otherFilter.getUserLogin())
- && ObjectUtils.equals(referenceFilter.getDescription(), otherFilter.getDescription())
- && ObjectUtils.equals(referenceFilter.getName(), otherFilter.getName())
- && ObjectUtils.equals(referenceFilter.getData(), otherFilter.getData());
+ && ObjectUtils.equals(referenceFilter.getUserLogin(), otherFilter.getUserLogin())
+ && ObjectUtils.equals(referenceFilter.getDescription(), otherFilter.getDescription())
+ && ObjectUtils.equals(referenceFilter.getName(), otherFilter.getName())
+ && ObjectUtils.equals(referenceFilter.getData(), otherFilter.getData());
}
return false;
}