Java 类org.junit.experimental.theories.PotentialAssignment 实例源码

项目:jamocha    文件:TestData.java   
@Override
public List<PotentialAssignment> getValueSources(final ParameterSignature param) {
    final ArrayList<PotentialAssignment> list = new ArrayList<>();
    list.add(PotentialAssignment.forValue("", "foo"));
    list.add(PotentialAssignment.forValue("", "bar"));
    list.add(PotentialAssignment.forValue("", "foo"));
    list.add(PotentialAssignment.forValue("", "bar"));
    list.add(PotentialAssignment.forValue("", "foobar"));
    list.add(PotentialAssignment.forValue("", "foobar"));
    list.add(PotentialAssignment.forValue("", "foobar"));
    list.add(PotentialAssignment.forValue("", "whut?"));
    list.add(PotentialAssignment.forValue("", "OMGWTFBBQ"));
    list.add(PotentialAssignment.forValue("", "muahhahahahahahahaha"));
    list.add(PotentialAssignment.forValue("", "ijrobbeoubgt3t9hboebalnpajtih39"));
    list.add(PotentialAssignment.forValue("", "ijrobbeoubgt3t9hboebalnpajtih39"));
    return list;
}
项目:sosiefier    文件:AllMembersSupplier.java   
private void addMultiPointMethods(ParameterSignature sig, List<PotentialAssignment> list) throws Throwable {
    for (FrameworkMethod dataPointsMethod : getDataPointsMethods(sig)) {
        Class<?> returnType = dataPointsMethod.getReturnType();

        if ((returnType.isArray() && sig.canPotentiallyAcceptType(returnType.getComponentType())) ||
                Iterable.class.isAssignableFrom(returnType)) {
            try {
                addDataPointsValues(returnType, sig, dataPointsMethod.getName(), list, 
                        dataPointsMethod.invokeExplosively(null));
            } catch (Throwable throwable) {
                DataPoints annotation = dataPointsMethod.getAnnotation(DataPoints.class);
                if (annotation != null && isAssignableToAnyOf(annotation.ignoredExceptions(), throwable)) {
                    return;
                } else {
                    throw throwable;
                }
            }
        }
    }
}
项目:lcm    文件:AllMembersSupplier.java   
private void addFields(ParameterSignature sig,
        List<PotentialAssignment> list) {
    for (final Field field : fClass.getJavaClass().getFields()) {
        if (Modifier.isStatic(field.getModifiers())) {
            Class<?> type = field.getType();
            if (sig.canAcceptArrayType(type)
                    && field.getAnnotation(DataPoints.class) != null) {
                try {
                    addArrayValues(field.getName(), list, getStaticFieldValue(field));
                } catch (Throwable e) {
                    // ignore and move on
                }
            } else if (sig.canAcceptType(type)
                    && field.getAnnotation(DataPoint.class) != null) {
                list.add(PotentialAssignment
                        .forValue(field.getName(), getStaticFieldValue(field)));
            }
        }
    }
}
项目:spliceengine    文件:ParallelTheoryRunner.java   
@Override
protected void runWithIncompleteAssignment(Assignments incomplete) throws Throwable{
    for(PotentialAssignment source:incomplete.potentialsForNextUnassigned()){
        final Assignments nextAssignment = incomplete.assignNext(source);
        ForkJoinTask<?> run = new RecursiveAction(){
            @Override
            protected void compute(){
                try{
                    ParallelTheoryAnchor.this.runWithAssignment(nextAssignment);
                }catch(Throwable t){
                    throw new RuntimeException(t);
                }
            }
        };
        runs.addFirst(run.fork());
    }
}
项目:junit    文件:AllMembersSupplier.java   
private void addFields(ParameterSignature sig,
        List<PotentialAssignment> list) {
    for (final Field field : fClass.getJavaClass().getFields()) {
        if (Modifier.isStatic(field.getModifiers())) {
            Class<?> type = field.getType();
            if (sig.canAcceptArrayType(type)
                    && field.getAnnotation(DataPoints.class) != null) {
                try {
                    addArrayValues(field.getName(), list, getStaticFieldValue(field));
                } catch (Throwable e) {
                    // ignore and move on
                }
            } else if (sig.canAcceptType(type)
                    && field.getAnnotation(DataPoint.class) != null) {
                list.add(PotentialAssignment
                        .forValue(field.getName(), getStaticFieldValue(field)));
            }
        }
    }
}
项目:org.openntf.domino    文件:AllMembersSupplier.java   
private void addFields(final ParameterSignature sig, final List<PotentialAssignment> list) {
    for (final Field field : fClass.getJavaClass().getFields()) {
        if (Modifier.isStatic(field.getModifiers())) {
            Class<?> type = field.getType();
            if (sig.canAcceptArrayType(type) && field.getAnnotation(DataPoints.class) != null) {
                try {
                    addArrayValues(field.getName(), list, getStaticFieldValue(field));
                } catch (Throwable e) {
                    // ignore and move on
                }
            } else if (sig.canAcceptType(type) && field.getAnnotation(DataPoint.class) != null) {
                list.add(PotentialAssignment.forValue(field.getName(), getStaticFieldValue(field)));
            }
        }
    }
}
项目:interview-preparation    文件:NumberSupplier.java   
@Override
public List<PotentialAssignment> getValueSources(ParameterSignature sig) throws Throwable {

    final List<PotentialAssignment> list = new ArrayList<PotentialAssignment>();

    list.add(PotentialAssignment.forValue("long", 2L));
    list.add(PotentialAssignment.forValue("float", 5.00f));
    list.add(PotentialAssignment.forValue("double", 89d));

    return list;
}
项目:jamocha    文件:TestData.java   
@Override
public List<PotentialAssignment> getValueSources(final ParameterSignature signature) {
    final ArrayList<PotentialAssignment> list = new ArrayList<>();
    list.add(PotentialAssignment.forValue("", new Object[]{-100L, 50L, 1L, 11L}));
    list.add(PotentialAssignment.forValue("", new Object[]{null}));
    list.add(PotentialAssignment.forValue("", new Object[]{"OMGWTFBBQ", "TEST test!!!"}));
    list.add(PotentialAssignment.forValue("", new Object[]{-100L}));
    list.add(PotentialAssignment.forValue("", new Object[]{0.3562}));
    list.add(PotentialAssignment.forValue("", new Object[]{}));
    return list;
}
项目:jamocha    文件:TestData.java   
@Override
public List<PotentialAssignment> getValueSources(final ParameterSignature signature) {
    final ArrayList<PotentialAssignment> list = new ArrayList<>();
    final Random randomGen = new Random();
    for (int i = 0; i < 20; ++i) {
        list.add(PotentialAssignment.forValue("", randomGen.nextLong()));
    }
    return list;
}
项目:jamocha    文件:TestData.java   
@Override
public List<PotentialAssignment> getValueSources(final ParameterSignature signature) {
    final ArrayList<PotentialAssignment> list = new ArrayList<>();
    final Random randomGen = new Random();
    for (int i = 0; i < 20; ++i) {
        list.add(PotentialAssignment.forValue("", randomGen.nextGaussian()));
    }
    return list;
}
项目:jamocha    文件:TestData.java   
@Override
public List<PotentialAssignment> getValueSources(final ParameterSignature arg0) {
    final ArrayList<PotentialAssignment> list = new ArrayList<>();
    list.add(PotentialAssignment.forValue("", new Boolean(true)));
    list.add(PotentialAssignment.forValue("", new Boolean(true)));
    list.add(PotentialAssignment.forValue("", new Boolean(true)));
    list.add(PotentialAssignment.forValue("", new Boolean(false)));
    list.add(PotentialAssignment.forValue("", new Boolean(false)));
    list.add(PotentialAssignment.forValue("", new Boolean(false)));
    list.add(PotentialAssignment.forValue("", new Boolean(false)));
    return list;
}
项目:sosiefier    文件:TestedOnSupplier.java   
@Override
public List<PotentialAssignment> getValueSources(ParameterSignature sig) {
    List<PotentialAssignment> list = new ArrayList<PotentialAssignment>();
    TestedOn testedOn = sig.getAnnotation(TestedOn.class);
    int[] ints = testedOn.ints();
    for (final int i : ints) {
        list.add(PotentialAssignment.forValue("ints", i));
    }
    return list;
}
项目:sosiefier    文件:AllMembersSupplier.java   
@Override
public List<PotentialAssignment> getValueSources(ParameterSignature sig) throws Throwable {
    List<PotentialAssignment> list = new ArrayList<PotentialAssignment>();

    addSinglePointFields(sig, list);
    addMultiPointFields(sig, list);
    addSinglePointMethods(sig, list);
    addMultiPointMethods(sig, list);

    return list;
}
项目:sosiefier    文件:AllMembersSupplier.java   
private void addSinglePointMethods(ParameterSignature sig, List<PotentialAssignment> list) {
    for (FrameworkMethod dataPointMethod : getSingleDataPointMethods(sig)) {
        if (sig.canAcceptType(dataPointMethod.getType())) {
            list.add(new MethodParameterValue(dataPointMethod));
        }
    }
}
项目:sosiefier    文件:AllMembersSupplier.java   
private void addSinglePointFields(ParameterSignature sig, List<PotentialAssignment> list) {
    for (final Field field : getSingleDataPointFields(sig)) {
        Object value = getStaticFieldValue(field);

        if (sig.canAcceptValue(value)) {
            list.add(PotentialAssignment.forValue(field.getName(), value));
        }
    }
}
项目:sosiefier    文件:AllMembersSupplier.java   
private void addDataPointsValues(Class<?> type, ParameterSignature sig, String name, 
        List<PotentialAssignment> list, Object value) {
    if (type.isArray()) {
        addArrayValues(sig, name, list, value);
    }
    else if (Iterable.class.isAssignableFrom(type)) {
        addIterableValues(sig, name, list, (Iterable<?>) value);
    }
}
项目:sosiefier    文件:AllMembersSupplier.java   
private void addArrayValues(ParameterSignature sig, String name, List<PotentialAssignment> list, Object array) {
    for (int i = 0; i < Array.getLength(array); i++) {
        Object value = Array.get(array, i);
        if (sig.canAcceptValue(value)) {
            list.add(PotentialAssignment.forValue(name + "[" + i + "]", value));
        }
    }
}
项目:sosiefier    文件:AllMembersSupplier.java   
private void addIterableValues(ParameterSignature sig, String name, List<PotentialAssignment> list, Iterable<?> iterable) {
    Iterator<?> iterator = iterable.iterator();
    int i = 0;
    while (iterator.hasNext()) {
        Object value = iterator.next();
        if (sig.canAcceptValue(value)) {
            list.add(PotentialAssignment.forValue(name + "[" + i + "]", value));
        }
        i += 1;
    }
}
项目:sosiefier    文件:EnumSupplier.java   
@Override
public List<PotentialAssignment> getValueSources(ParameterSignature sig) {
    Object[] enumValues = enumType.getEnumConstants();

    List<PotentialAssignment> assignments = new ArrayList<PotentialAssignment>();
    for (Object value : enumValues) {
        assignments.add(PotentialAssignment.forValue(value.toString(), value));
    }

    return assignments;
}
项目:sosiefier    文件:Assignments.java   
/**
 * Returns a new assignment list for {@code testMethod}, with no params
 * assigned.
 */
public static Assignments allUnassigned(Method testMethod,
        TestClass testClass) {
    List<ParameterSignature> signatures;
    signatures = ParameterSignature.signatures(testClass
            .getOnlyConstructor());
    signatures.addAll(ParameterSignature.signatures(testMethod));
    return new Assignments(new ArrayList<PotentialAssignment>(),
            signatures, testClass);
}
项目:sosiefier    文件:Assignments.java   
public Assignments assignNext(PotentialAssignment source) {
    List<PotentialAssignment> assigned = new ArrayList<PotentialAssignment>(
            fAssigned);
    assigned.add(source);

    return new Assignments(assigned, fUnassigned.subList(1,
            fUnassigned.size()), fClass);
}
项目:sosiefier    文件:Assignments.java   
public List<PotentialAssignment> potentialsForNextUnassigned()
        throws Throwable {
    ParameterSignature unassigned = nextUnassigned();
    List<PotentialAssignment> assignments = getSupplier(unassigned).getValueSources(unassigned);

    if (assignments.size() == 0) {
        assignments = generateAssignmentsFromTypeAlone(unassigned);
    }

    return assignments;
}
项目:sosiefier    文件:Assignments.java   
private List<PotentialAssignment> generateAssignmentsFromTypeAlone(ParameterSignature unassigned) {
    Class<?> paramType = unassigned.getType();

    if (paramType.isEnum()) {
        return new EnumSupplier(paramType).getValueSources(unassigned);  
    } else if (paramType.equals(Boolean.class) || paramType.equals(boolean.class)) {
        return new BooleanSupplier().getValueSources(unassigned);
    } else {
        return emptyList();
    }
}
项目:sosiefier    文件:PotentialAssignmentTest.java   
@Test
public void shouldUseQuotedValueInDescription() throws CouldNotGenerateValueException {
    String name = "stringDatapoint";
    Object value = new Object() {
        @Override
        public String toString() {
            return "string value";
        }
    };

    PotentialAssignment assignment = PotentialAssignment.forValue(name, value);

    assertEquals("\"string value\" <from stringDatapoint>", assignment.getDescription());
}
项目:sosiefier    文件:PotentialAssignmentTest.java   
@Test
public void shouldNotUseQuotesForNullValueDescriptions() throws CouldNotGenerateValueException {
    String name = "nullDatapoint";
    Object value = null;

    PotentialAssignment assignment = PotentialAssignment.forValue(name, value);

    assertEquals("null <from nullDatapoint>", assignment.getDescription());
}
项目:sosiefier    文件:PotentialAssignmentTest.java   
@Test
public void shouldIncludeFailureInDescriptionIfToStringFails() throws CouldNotGenerateValueException {
    String name = "explodingValue";
    Object value = new Object() {
        @Override
        public String toString() {
            throw new RuntimeException("Oh no!");
        }
    };

    PotentialAssignment assignment = PotentialAssignment.forValue(name, value);

    assertEquals("[toString() threw RuntimeException: Oh no!] <from explodingValue>", assignment.getDescription());
}
项目:sosiefier    文件:SpecificDataPointsSupplierTest.java   
@Test
public void shouldReturnOnlyTheNamedDataPoints() throws Throwable {
    SpecificDataPointsSupplier supplier = new SpecificDataPointsSupplier(new TestClass(TestClassWithNamedDataPoints.class));

    List<PotentialAssignment> assignments = supplier.getValueSources(signature("methodWantingAllNamedStrings"));
    List<String> assignedStrings = getStringValuesFromAssignments(assignments);

    assertEquals(4, assignedStrings.size());
    assertThat(assignedStrings, hasItems("named field", "named method", "named single value", "named single method value"));
}
项目:sosiefier    文件:SpecificDataPointsSupplierTest.java   
@Test
public void shouldReturnOnlyTheNamedFieldDataPoints() throws Throwable {
    SpecificDataPointsSupplier supplier = new SpecificDataPointsSupplier(new TestClass(TestClassWithNamedDataPoints.class));

    List<PotentialAssignment> assignments = supplier.getValueSources(signature("methodWantingNamedFieldString"));
    List<String> assignedStrings = getStringValuesFromAssignments(assignments);

    assertEquals(1, assignedStrings.size());
    assertThat(assignedStrings, hasItem("named field"));
}
项目:sosiefier    文件:SpecificDataPointsSupplierTest.java   
@Test
public void shouldReturnOnlyTheNamedMethodDataPoints() throws Throwable {
    SpecificDataPointsSupplier supplier = new SpecificDataPointsSupplier(new TestClass(TestClassWithNamedDataPoints.class));

    List<PotentialAssignment> assignments = supplier.getValueSources(signature("methodWantingNamedMethodString"));
    List<String> assignedStrings = getStringValuesFromAssignments(assignments);

    assertEquals(1, assignedStrings.size());
    assertThat(assignedStrings, hasItem("named method"));
}
项目:sosiefier    文件:SpecificDataPointsSupplierTest.java   
@Test
public void shouldReturnOnlyTheNamedSingleFieldDataPoints() throws Throwable {
    SpecificDataPointsSupplier supplier = new SpecificDataPointsSupplier(new TestClass(TestClassWithNamedDataPoints.class));

    List<PotentialAssignment> assignments = supplier.getValueSources(signature("methodWantingNamedSingleFieldString"));
    List<String> assignedStrings = getStringValuesFromAssignments(assignments);

    assertEquals(1, assignedStrings.size());
    assertThat(assignedStrings, hasItem("named single value"));
}
项目:sosiefier    文件:SpecificDataPointsSupplierTest.java   
@Test
public void shouldReturnOnlyTheNamedSingleMethodDataPoints() throws Throwable {
    SpecificDataPointsSupplier supplier = new SpecificDataPointsSupplier(new TestClass(TestClassWithNamedDataPoints.class));

    List<PotentialAssignment> assignments = supplier.getValueSources(signature("methodWantingNamedSingleMethodString"));
    List<String> assignedStrings = getStringValuesFromAssignments(assignments);

    assertEquals(1, assignedStrings.size());
    assertThat(assignedStrings, hasItem("named single method value"));
}
项目:sosiefier    文件:SpecificDataPointsSupplierTest.java   
@Test
public void shouldReturnNothingIfTheNamedDataPointsAreMissing() throws Throwable {
    SpecificDataPointsSupplier supplier = new SpecificDataPointsSupplier(new TestClass(TestClassWithNamedDataPoints.class));

    List<PotentialAssignment> assignments = supplier.getValueSources(signature("methodWantingWrongNamedString"));
    List<String> assignedStrings = getStringValuesFromAssignments(assignments);

    assertEquals(0, assignedStrings.size());
}
项目:sosiefier    文件:SpecificDataPointsSupplierTest.java   
private List<String> getStringValuesFromAssignments(List<PotentialAssignment> assignments) throws CouldNotGenerateValueException {
    List<String> stringValues = new ArrayList<String>();
    for (PotentialAssignment assignment : assignments) {
        stringValues.add((String) assignment.getValue());
    }
    return stringValues;
}
项目:sosiefier    文件:AllMembersSupplierTest.java   
@Test
public void dataPointsArrayShouldBeRecognized() throws Throwable {
    List<PotentialAssignment> assignments = potentialAssignments(
            HasDataPointsArrayField.class.getMethod("theory", String.class));

    assertEquals(2, assignments.size());
}
项目:sosiefier    文件:AllMembersSupplierTest.java   
@Test
public void dataPointsArrayShouldBeRecognizedOnValueTypeNotFieldType() throws Throwable {
    List<PotentialAssignment> assignments = potentialAssignments(
            HasDataPointsArrayWithMatchingButInaccurateTypes.class.getMethod("theory", Integer.class));

    assertEquals(2, assignments.size());
}
项目:sosiefier    文件:AllMembersSupplierTest.java   
@Test
public void dataPointMethodShouldBeRecognizedForOverlyGeneralParameters() throws Throwable {
    List<PotentialAssignment> assignments = potentialAssignments(
            HasDataPointMethodWithOverlyGeneralTypes.class.getMethod("theory", Object.class));

    assertEquals(1, assignments.size());
}
项目:sosiefier    文件:AllMembersSupplierTest.java   
@Test
public void dataPointsAnnotationMeansTreatAsArrayOnly() throws Throwable {
    List<PotentialAssignment> assignments = potentialAssignments(
            HasDataPointsWithObjectParameter.class.getMethod("theory", Object.class));

    assertEquals(2, assignments.size());
    for (PotentialAssignment assignment : assignments) {
        assertNotEquals(HasDataPointsWithObjectParameter.objectField, assignment.getValue());
    }
}
项目:sosiefier    文件:AllMembersSupplierTest.java   
private List<PotentialAssignment> allMemberValuesFor(Class<?> testClass,
        Class<?>... constructorParameterTypes) throws Throwable {
    return new AllMembersSupplier(new TestClass(testClass))
            .getValueSources(ParameterSignature.signatures(
                    testClass.getConstructor(constructorParameterTypes))
                    .get(0));
}
项目:sosiefier    文件:AllMembersSupplierTest.java   
@Test
public void dataPointsCollectionFieldsShouldBeRecognized() throws Throwable {
    List<PotentialAssignment> assignments = potentialAssignments(
        HasDataPointsListField.class.getMethod("theory", String.class));

    assertEquals(2, assignments.size());
}
项目:sosiefier    文件:AllMembersSupplierTest.java   
@Test
public void dataPointsCollectionMethodShouldBeRecognized() throws Throwable {
    List<PotentialAssignment> assignments = potentialAssignments(
        HasDataPointsListMethod.class.getMethod("theory", String.class));

    assertEquals(2, assignments.size());
}