ActionPluginClientService { public void addPluginToActionList(final RuleModeller ruleModeller, final Command addCommand, final Collection supportedScoreHolderTypes) { invokeScoreInformationCachedOperation(ruleModeller, scoreInformation -> { Collection<String> scoreHolderFqns = scoreInformation.getScoreHolderFqnTypeFqns(); if (scoreHolderFqns.size() == 1 && supportedScoreHolderTypes.containsAll(scoreHolderFqns)) { addCommand.execute(); } }); } @Inject  ActionPluginClientService(final Caller<ScoreHolderService> scoreHolderService,
                                     final TranslationService translationService); void invokeScoreInformationCachedOperation(final RuleModeller ruleModeller,
                                                      final Consumer<ScoreInformation> scoreInformationConsumer); void initScoreHolderAwarePlugin(final RuleModeller ruleModeller,
                                           final ScoreHolderGlobalAware scoreHolderGlobalAware,
                                           final Collection supportedScoreHolderTypes); void addPluginToActionList(final RuleModeller ruleModeller,
                                      final Command addCommand,
                                      final Collection supportedScoreHolderTypes); void initBendableScoreLevels(final RuleModeller ruleModeller,
                                        final AbstractActionMultiConstraintBendableMatch constraintMatch);  }
@Test public void addPluginToActionList() { ScoreInformation scoreInformation = new ScoreInformation(Arrays.asList(HardSoftScoreHolder.class.getName()), Arrays.asList(new BendableScoreLevelsWrapper(1, 1))); Map<String, Object> serviceCache = new HashMap<>(); serviceCache.put(ActionPluginClientService.SCORE_INFORMATION, scoreInformation); RuleModeller ruleModeller = mock(RuleModeller.class); when(ruleModeller.getServiceInvocationCache()).thenReturn(serviceCache); Command addCommand = mock(Command.class); service.addPluginToActionList(ruleModeller, addCommand, Arrays.asList(HardSoftScoreHolder.class.getName())); verify(addCommand, times(1)).execute(); }
@Test public void addPluginToActionListAmbigiousScoreHolder() { ScoreInformation scoreInformation = new ScoreInformation(Arrays.asList(HardSoftScoreHolder.class.getName(), SimpleScoreHolder.class.getName()), Arrays.asList(new BendableScoreLevelsWrapper(1, 1))); Map<String, Object> serviceCache = new HashMap<>(); serviceCache.put(ActionPluginClientService.SCORE_INFORMATION, scoreInformation); RuleModeller ruleModeller = mock(RuleModeller.class); when(ruleModeller.getServiceInvocationCache()).thenReturn(serviceCache); Command addCommand = mock(Command.class); service.addPluginToActionList(ruleModeller, addCommand, Arrays.asList(HardSoftScoreHolder.class.getName())); verify(addCommand, never()).execute(); }