Skip to content

Commit

Permalink
LPD-2249 portal-search: Fix broken test
Browse files Browse the repository at this point in the history
  • Loading branch information
AlmirFe authored and brianchandotcom committed May 14, 2024
1 parent 4a25d76 commit 0b62688
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
import com.liferay.portal.kernel.search.SearchPermissionChecker;
import com.liferay.portal.kernel.security.permission.PermissionChecker;
import com.liferay.portal.kernel.security.permission.UserBag;
import com.liferay.portal.kernel.service.GroupLocalService;
import com.liferay.portal.kernel.service.ResourcePermissionLocalService;
import com.liferay.portal.kernel.service.RoleLocalService;
import com.liferay.portal.kernel.service.UserLocalService;
import com.liferay.portal.kernel.test.ReflectionTestUtil;
import com.liferay.portal.kernel.test.util.RandomTestUtil;
import com.liferay.portal.kernel.util.ListUtil;
import com.liferay.portal.search.configuration.SearchPermissionCheckerConfiguration;
import com.liferay.portal.test.rule.LiferayUnitTestRule;

Expand Down Expand Up @@ -73,6 +75,7 @@ public void testPermissionFilterTakesOverNullInputFilter()

long userId = RandomTestUtil.randomLong();

_whenGroupLocalServiceGetGroupIds(RandomTestUtil.randomLong());
_whenIndexerIsPermissionAware(true);
_whenPermissionCheckerGetUser(_user);
_whenPermissionCheckerGetUserBag(_userBag);
Expand All @@ -86,6 +89,9 @@ public void testPermissionFilterTakesOverNullInputFilter()
private SearchPermissionCheckerImpl _createSearchPermissionChecker() {
_searchPermissionCheckerImpl = new SearchPermissionCheckerImpl();

ReflectionTestUtil.setFieldValue(
_searchPermissionCheckerImpl, "_groupLocalService",
_groupLocalService);
ReflectionTestUtil.setFieldValue(
_searchPermissionCheckerImpl, "_indexerRegistry", _indexerRegistry);
ReflectionTestUtil.setFieldValue(
Expand All @@ -111,6 +117,16 @@ private SearchPermissionCheckerImpl _createSearchPermissionChecker() {
return _searchPermissionCheckerImpl;
}

private void _whenGroupLocalServiceGetGroupIds(long... groupIds) {
Mockito.doReturn(
ListUtil.fromArray(groupIds)
).when(
_groupLocalService
).getGroupIds(
Mockito.anyLong(), Mockito.eq(true)
);
}

private boolean _whenIndexerIsPermissionAware(boolean permissionAware) {
return Mockito.doReturn(
permissionAware
Expand Down Expand Up @@ -145,6 +161,8 @@ private long _whenUserGetUserId(long userId) {
).getUserId();
}

private final GroupLocalService _groupLocalService = Mockito.mock(
GroupLocalService.class);
private final Indexer<?> _indexer = Mockito.mock(Indexer.class);
private final IndexerRegistry _indexerRegistry = Mockito.mock(
IndexerRegistry.class);
Expand Down

0 comments on commit 0b62688

Please sign in to comment.