1 package org.junit.tests.experimental.theories.extendingwithstubs; 2 3 import java.util.ArrayList; 4 import java.util.Collections; 5 import java.util.List; 6 7 import org.junit.experimental.theories.PotentialAssignment; 8 import org.junit.internal.AssumptionViolatedException; 9 10 public class GuesserQueue extends ArrayList<ReguessableValue> { 11 static class ReguessableDecorator extends ReguessableValue { 12 private final PotentialAssignment delegate; 13 14 public ReguessableDecorator(PotentialAssignment delegate) { 15 this.delegate = delegate; 16 } 17 18 @Override 19 public List<ReguessableValue> reguesses(AssumptionViolatedException e) { 20 return Collections.emptyList(); 21 } 22 23 @Override 24 public Object getValue() throws CouldNotGenerateValueException { 25 return delegate.getValue(); 26 } 27 28 @Override 29 public String getDescription() throws CouldNotGenerateValueException { 30 return delegate.getDescription(); 31 } 32 } 33 34 static GuesserQueue forSingleValues( 35 List<PotentialAssignment> potentials) { 36 GuesserQueue returnThis = new GuesserQueue(); 37 for (PotentialAssignment potentialParameterValue : potentials) { 38 returnThis 39 .add(new GuesserQueue.ReguessableDecorator(potentialParameterValue)); 40 } 41 return returnThis; 42 } 43 44 private static final long serialVersionUID = 1L; 45 private ReguessableValue lastRemoved; 46 47 public void update(AssumptionViolatedException e) { 48 if (lastRemoved != null) { 49 addAll(lastRemoved.reguesses(e)); 50 } 51 } 52 53 @Override 54 public ReguessableValue remove(int index) { 55 lastRemoved = super.remove(index); 56 return lastRemoved; 57 } 58 }