Exemplo n.º 1
0
 public static EntityIndependentValueSelector mockEntityIndependentValueSelector(
     GenuineVariableDescriptor variableDescriptor, Object... values) {
   EntityIndependentValueSelector valueSelector = mock(EntityIndependentValueSelector.class);
   when(valueSelector.getVariableDescriptor()).thenReturn(variableDescriptor);
   final List<Object> valueList = Arrays.<Object>asList(values);
   when(valueSelector.iterator(any()))
       .thenAnswer(
           new Answer<Iterator<Object>>() {
             @Override
             public Iterator<Object> answer(InvocationOnMock invocation) throws Throwable {
               return valueList.iterator();
             }
           });
   when(valueSelector.endingIterator(any()))
       .thenAnswer(
           new Answer<Iterator<Object>>() {
             @Override
             public Iterator<Object> answer(InvocationOnMock invocation) throws Throwable {
               return valueList.iterator();
             }
           });
   when(valueSelector.iterator())
       .thenAnswer(
           new Answer<Iterator<Object>>() {
             @Override
             public Iterator<Object> answer(InvocationOnMock invocation) throws Throwable {
               return valueList.iterator();
             }
           });
   when(valueSelector.isCountable()).thenReturn(true);
   when(valueSelector.isNeverEnding()).thenReturn(false);
   when(valueSelector.getSize(any())).thenReturn((long) valueList.size());
   when(valueSelector.getSize()).thenReturn((long) valueList.size());
   return valueSelector;
 }
 public ProbabilityValueSelector(
     EntityIndependentValueSelector childValueSelector,
     SelectionCacheType cacheType,
     SelectionProbabilityWeightFactory probabilityWeightFactory) {
   this.childValueSelector = childValueSelector;
   this.cacheType = cacheType;
   this.probabilityWeightFactory = probabilityWeightFactory;
   if (childValueSelector.isNeverEnding()) {
     throw new IllegalStateException(
         "The selector ("
             + this
             + ") has a childValueSelector ("
             + childValueSelector
             + ") with neverEnding ("
             + childValueSelector.isNeverEnding()
             + ").");
   }
   phaseLifecycleSupport.addEventListener(childValueSelector);
   if (cacheType.isNotCached()) {
     throw new IllegalArgumentException(
         "The selector (" + this + ") does not support the cacheType (" + cacheType + ").");
   }
   phaseLifecycleSupport.addEventListener(new SelectionCacheLifecycleBridge(cacheType, this));
 }
 public GenuineVariableDescriptor getVariableDescriptor() {
   return childValueSelector.getVariableDescriptor();
 }