@Test public void testIssue172() throws EntityNotFoundException, AddEntityException { CompetitionGroupSetAddPayload payload = mock(CompetitionGroupSetAddPayload.class); CompetitionGroup domainEntity = DomainEntityTestUtils.fullCompetitionGroup(); when(payload.getCompetitionGroupIds()).thenReturn(Sets.newHashSet(domainEntity.getId())); when(competitionGroupEntityService.getById(domainEntity.getId())).thenReturn(domainEntity); CompetitionGroupSet domainSetEntity = mock(CompetitionGroupSet.class); when(gateway.add(payload)).thenReturn(domainSetEntity); CompetitionGroupSet actual = service.add(payload); verify(payload).setCompetitionGroups( argThat(argument -> argument.contains(domainEntity)) ); verify(gateway).add(payload); assertThat(actual).isSameAs(domainSetEntity); }
@Override public CompetitionGroupSet add(CompetitionGroupSetAddPayload addPayload) throws AddEntityException { ImmutableSet.Builder<CompetitionGroup> competitionGroupsBuilder = ImmutableSet.builder(); try { for (String competitionGroupId : addPayload.getCompetitionGroupIds()) { competitionGroupsBuilder.add(competitionGroupEntityService.getById(competitionGroupId)); } } catch (EntityNotFoundException e) { throw new AddEntityException(e); } addPayload.setCompetitionGroups(competitionGroupsBuilder.build()); return gateway.add(addPayload); }
CompetitionGroupSetService extends AbstractEntityService<
        CompetitionGroupSet,
        CompetitionGroupSetAddPayload,
        CompetitionGroupSetGateway> { @Override public CompetitionGroupSet add(CompetitionGroupSetAddPayload addPayload) throws AddEntityException { ImmutableSet.Builder<CompetitionGroup> competitionGroupsBuilder = ImmutableSet.builder(); try { for (String competitionGroupId : addPayload.getCompetitionGroupIds()) { competitionGroupsBuilder.add(competitionGroupEntityService.getById(competitionGroupId)); } } catch (EntityNotFoundException e) { throw new AddEntityException(e); } addPayload.setCompetitionGroups(competitionGroupsBuilder.build()); return gateway.add(addPayload); } }
CompetitionGroupSetService extends AbstractEntityService<
        CompetitionGroupSet,
        CompetitionGroupSetAddPayload,
        CompetitionGroupSetGateway> { @Override public CompetitionGroupSet add(CompetitionGroupSetAddPayload addPayload) throws AddEntityException { ImmutableSet.Builder<CompetitionGroup> competitionGroupsBuilder = ImmutableSet.builder(); try { for (String competitionGroupId : addPayload.getCompetitionGroupIds()) { competitionGroupsBuilder.add(competitionGroupEntityService.getById(competitionGroupId)); } } catch (EntityNotFoundException e) { throw new AddEntityException(e); } addPayload.setCompetitionGroups(competitionGroupsBuilder.build()); return gateway.add(addPayload); } @Inject  CompetitionGroupSetService(
            CompetitionGroupSetGateway gateway,
            CompetitionGroupEntityService competitionGroupEntityService); }
CompetitionGroupSetService extends AbstractEntityService<
        CompetitionGroupSet,
        CompetitionGroupSetAddPayload,
        CompetitionGroupSetGateway> { @Override public CompetitionGroupSet add(CompetitionGroupSetAddPayload addPayload) throws AddEntityException { ImmutableSet.Builder<CompetitionGroup> competitionGroupsBuilder = ImmutableSet.builder(); try { for (String competitionGroupId : addPayload.getCompetitionGroupIds()) { competitionGroupsBuilder.add(competitionGroupEntityService.getById(competitionGroupId)); } } catch (EntityNotFoundException e) { throw new AddEntityException(e); } addPayload.setCompetitionGroups(competitionGroupsBuilder.build()); return gateway.add(addPayload); } @Inject  CompetitionGroupSetService(
            CompetitionGroupSetGateway gateway,
            CompetitionGroupEntityService competitionGroupEntityService); @Override CompetitionGroupSet add(CompetitionGroupSetAddPayload addPayload); CompetitionGroupSet addToCompetitionGroups(
            CompetitionGroupSet competitionGroupSet,
            CompetitionGroup competitionGroup
    ); }
CompetitionGroupSetService extends AbstractEntityService<
        CompetitionGroupSet,
        CompetitionGroupSetAddPayload,
        CompetitionGroupSetGateway> { @Override public CompetitionGroupSet add(CompetitionGroupSetAddPayload addPayload) throws AddEntityException { ImmutableSet.Builder<CompetitionGroup> competitionGroupsBuilder = ImmutableSet.builder(); try { for (String competitionGroupId : addPayload.getCompetitionGroupIds()) { competitionGroupsBuilder.add(competitionGroupEntityService.getById(competitionGroupId)); } } catch (EntityNotFoundException e) { throw new AddEntityException(e); } addPayload.setCompetitionGroups(competitionGroupsBuilder.build()); return gateway.add(addPayload); } @Inject  CompetitionGroupSetService(
            CompetitionGroupSetGateway gateway,
            CompetitionGroupEntityService competitionGroupEntityService); @Override CompetitionGroupSet add(CompetitionGroupSetAddPayload addPayload); CompetitionGroupSet addToCompetitionGroups(
            CompetitionGroupSet competitionGroupSet,
            CompetitionGroup competitionGroup
    );  }