BaseProjectionFactory { Class<?> getProjectionType(Class<?> normalProjectionType, Class<?> managerProjectionType) { var authenticatedUser = userAuthService.getAuthenticatedUser(); return userAuthService.userIsEffectivelyAManager(authenticatedUser) ? managerProjectionType : normalProjectionType; } @Autowired  BaseProjectionFactory(ProjectionFactory projectionFactory, UserAuthService userAuthService); T createProjection(@NotNull Object object, @NotNull Class<T> projectionType); List<T> createProjections(@NotNull Collection<?> objects, @NotNull Class<T> projectionType); Object createProjectionForAuthenticatedUser(@NotNull Object object, @NotNull Class<?> normalProjectionType, @NotNull Class<?> managerProjectionType); List<?> createProjectionsForAuthenticatedUser(@NotNull Collection<?> objects, @NotNull Class<?> normalProjectionType, @NotNull Class<?> managerProjectionType); Page<?> createProjectionsForAuthenticatedUser(@NotNull Page<?> page, @NotNull Class<?> normalProjectionType, @NotNull Class<?> managerProjectionType);  }
@Test public void getProjectionTypeReturnsNormalTypeWhenUserNotAManager() { var normalProjection = Integer.class; var managerProjection = String.class; given(userAuthServiceMock.getAuthenticatedUser()).willReturn(userMock); given(userAuthServiceMock.userIsEffectivelyAManager(userMock)).willReturn(false); var actualProjection = baseProjectionFactory.getProjectionType(normalProjection, managerProjection); assertThat(actualProjection).isEqualTo(normalProjection); }
@Test public void getProjectionTypeReturnsManagerTypeWhenUserIsAManager() { var normalProjection = Integer.class; var managerProjection = String.class; given(userAuthServiceMock.getAuthenticatedUser()).willReturn(userMock); given(userAuthServiceMock.userIsEffectivelyAManager(userMock)).willReturn(true); var actualProjection = baseProjectionFactory.getProjectionType(normalProjection, managerProjection); assertThat(actualProjection).isEqualTo(managerProjection); }