UserProjectionFactory { public <T> T createProjection(@NonNull User user, @NonNull Class<T> projectionType) { var data = userService.getUserData(user); var manager = userService.userIsManager(user); return projectionFactory.createProjection(projectionType, new UserProjectionSource(user, data, manager)); } @Autowired  UserProjectionFactory(UserService userService, ProjectionFactory projectionFactory); List<T> createProjections(@NonNull Collection<UserData> userData, @NonNull Class<T> projectionType); T createProjection(@NonNull User user, @NonNull Class<T> projectionType);  }
@Test public void createProjectionReturnsExpectedProjection() { var projection = Integer.class; var expectedProjection = 12345; var userProjectionSource = new UserProjectionSource(userMock, userDataMock, true); given(projectionFactoryMock.createProjection(projection, userProjectionSource)).willReturn(expectedProjection); given(userServiceMock.getUserData(userMock)).willReturn(userDataMock); given(userServiceMock.userIsManager(userMock)).willReturn(true); var actualProjection = userProjectionFactory.createProjection(userMock, projection); assertThat(actualProjection).isEqualTo(expectedProjection); }