@Test public void testIssue157() throws EntityNotFoundException, AddEntityException { HandicapGroupSetAddPayload payload = mock(HandicapGroupSetAddPayload.class); HandicapGroup domainEntity = DomainEntityTestUtils.fullHandicapGroup(); when(payload.getHandicapGroupIds()).thenReturn(Sets.newHashSet(domainEntity.getId())); when(handicapGroupEntityService.getById(domainEntity.getId())).thenReturn(domainEntity); HandicapGroupSet domainSetEntity = mock(HandicapGroupSet.class); when(gateway.add(payload)).thenReturn(domainSetEntity); HandicapGroupSet actual = service.add(payload); verify(payload).setHandicapGroups( argThat(argument -> argument.contains(domainEntity)) ); verify(gateway).add(payload); assertThat(actual).isSameAs(domainSetEntity); }
@Override public HandicapGroupSet add(HandicapGroupSetAddPayload addPayload) throws AddEntityException { ImmutableSet.Builder<HandicapGroup> handicapGroupBuilder = ImmutableSet.builder(); try { for (String handicapGroupId : addPayload.getHandicapGroupIds()) { handicapGroupBuilder.add(handicapGroupEntityService.getById(handicapGroupId)); } } catch (EntityNotFoundException e) { throw new AddEntityException(e); } addPayload.setHandicapGroups(handicapGroupBuilder.build()); return gateway.add(addPayload); }
HandicapGroupSetService extends AbstractEntityService<
        HandicapGroupSet,
        HandicapGroupSetAddPayload,
        HandicapGroupSetGateway> { @Override public HandicapGroupSet add(HandicapGroupSetAddPayload addPayload) throws AddEntityException { ImmutableSet.Builder<HandicapGroup> handicapGroupBuilder = ImmutableSet.builder(); try { for (String handicapGroupId : addPayload.getHandicapGroupIds()) { handicapGroupBuilder.add(handicapGroupEntityService.getById(handicapGroupId)); } } catch (EntityNotFoundException e) { throw new AddEntityException(e); } addPayload.setHandicapGroups(handicapGroupBuilder.build()); return gateway.add(addPayload); } }
HandicapGroupSetService extends AbstractEntityService<
        HandicapGroupSet,
        HandicapGroupSetAddPayload,
        HandicapGroupSetGateway> { @Override public HandicapGroupSet add(HandicapGroupSetAddPayload addPayload) throws AddEntityException { ImmutableSet.Builder<HandicapGroup> handicapGroupBuilder = ImmutableSet.builder(); try { for (String handicapGroupId : addPayload.getHandicapGroupIds()) { handicapGroupBuilder.add(handicapGroupEntityService.getById(handicapGroupId)); } } catch (EntityNotFoundException e) { throw new AddEntityException(e); } addPayload.setHandicapGroups(handicapGroupBuilder.build()); return gateway.add(addPayload); } @Inject  HandicapGroupSetService(
            HandicapGroupSetGateway gateway,
            HandicapGroupEntityService handicapGroupEntityService
    ); }
HandicapGroupSetService extends AbstractEntityService<
        HandicapGroupSet,
        HandicapGroupSetAddPayload,
        HandicapGroupSetGateway> { @Override public HandicapGroupSet add(HandicapGroupSetAddPayload addPayload) throws AddEntityException { ImmutableSet.Builder<HandicapGroup> handicapGroupBuilder = ImmutableSet.builder(); try { for (String handicapGroupId : addPayload.getHandicapGroupIds()) { handicapGroupBuilder.add(handicapGroupEntityService.getById(handicapGroupId)); } } catch (EntityNotFoundException e) { throw new AddEntityException(e); } addPayload.setHandicapGroups(handicapGroupBuilder.build()); return gateway.add(addPayload); } @Inject  HandicapGroupSetService(
            HandicapGroupSetGateway gateway,
            HandicapGroupEntityService handicapGroupEntityService
    ); @Override HandicapGroupSet add(HandicapGroupSetAddPayload addPayload); HandicapGroupSet addToHandicapGroups(HandicapGroupSet handicapGroupSet, HandicapGroup handicapGroup); }
HandicapGroupSetService extends AbstractEntityService<
        HandicapGroupSet,
        HandicapGroupSetAddPayload,
        HandicapGroupSetGateway> { @Override public HandicapGroupSet add(HandicapGroupSetAddPayload addPayload) throws AddEntityException { ImmutableSet.Builder<HandicapGroup> handicapGroupBuilder = ImmutableSet.builder(); try { for (String handicapGroupId : addPayload.getHandicapGroupIds()) { handicapGroupBuilder.add(handicapGroupEntityService.getById(handicapGroupId)); } } catch (EntityNotFoundException e) { throw new AddEntityException(e); } addPayload.setHandicapGroups(handicapGroupBuilder.build()); return gateway.add(addPayload); } @Inject  HandicapGroupSetService(
            HandicapGroupSetGateway gateway,
            HandicapGroupEntityService handicapGroupEntityService
    ); @Override HandicapGroupSet add(HandicapGroupSetAddPayload addPayload); HandicapGroupSet addToHandicapGroups(HandicapGroupSet handicapGroupSet, HandicapGroup handicapGroup);  }