当前位置: 首页>>代码示例>>Java>>正文


Java Parameter类代码示例

本文整理汇总了Java中org.junit.runners.Parameterized.Parameter的典型用法代码示例。如果您正苦于以下问题:Java Parameter类的具体用法?Java Parameter怎么用?Java Parameter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Parameter类属于org.junit.runners.Parameterized包,在下文中一共展示了Parameter类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createTestUsingFieldInjection

import org.junit.runners.Parameterized.Parameter; //导入依赖的package包/类
private Object createTestUsingFieldInjection() throws Exception {
    List<FrameworkField> annotatedFieldsByParameter = getAnnotatedFieldsByParameter();
    if (annotatedFieldsByParameter.size() != parameters.length) {
        throw new Exception(
                "Wrong number of parameters and @Parameter fields."
                        + " @Parameter fields counted: "
                        + annotatedFieldsByParameter.size()
                        + ", available parameters: " + parameters.length
                        + ".");
    }
    Object testClassInstance = getTestClass().getJavaClass().newInstance();
    for (FrameworkField each : annotatedFieldsByParameter) {
        Field field = each.getField();
        Parameter annotation = field.getAnnotation(Parameter.class);
        int index = annotation.value();
        try {
            field.set(testClassInstance, parameters[index]);
        } catch (IllegalArgumentException iare) {
            throw new Exception(getTestClass().getName()
                    + ": Trying to set " + field.getName()
                    + " with the value " + parameters[index]
                    + " that is not the right type ("
                    + parameters[index].getClass().getSimpleName()
                    + " instead of " + field.getType().getSimpleName()
                    + ").", iare);
        }
    }
    return testClassInstance;
}
 
开发者ID:hortonworks,项目名称:registry,代码行数:30,代码来源:CustomParameterizedBlockJUnit4Runner.java

示例2: validateFields

import org.junit.runners.Parameterized.Parameter; //导入依赖的package包/类
@Override
protected void validateFields(List<Throwable> errors) {
    super.validateFields(errors);
    if (getInjectionType() == InjectionType.FIELD) {
        List<FrameworkField> annotatedFieldsByParameter = getAnnotatedFieldsByParameter();
        int[] usedIndices = new int[annotatedFieldsByParameter.size()];
        for (FrameworkField each : annotatedFieldsByParameter) {
            int index = each.getField().getAnnotation(Parameter.class)
                    .value();
            if (index < 0 || index > annotatedFieldsByParameter.size() - 1) {
                errors.add(new Exception("Invalid @Parameter value: "
                        + index + ". @Parameter fields counted: "
                        + annotatedFieldsByParameter.size()
                        + ". Please use an index between 0 and "
                        + (annotatedFieldsByParameter.size() - 1) + "."));
            } else {
                usedIndices[index]++;
            }
        }
        for (int index = 0; index < usedIndices.length; index++) {
            int numberOfUse = usedIndices[index];
            if (numberOfUse == 0) {
                errors.add(new Exception("@Parameter(" + index
                        + ") is never used."));
            } else if (numberOfUse > 1) {
                errors.add(new Exception("@Parameter(" + index
                        + ") is used more than once (" + numberOfUse + ")."));
            }
        }
    }
}
 
开发者ID:hortonworks,项目名称:registry,代码行数:32,代码来源:CustomParameterizedBlockJUnit4Runner.java

示例3: searchParameters

import org.junit.runners.Parameterized.Parameter; //导入依赖的package包/类
public Map<String, Object> searchParameters() {
	final Map<String, Object> fields = new HashMap<String, Object>();
	for (final Field field : description.getDeclaringClass().getFields()) {
		if (field.isAnnotationPresent(Parameter.class)) {
			try {
				fields.put(field.getName(), field.get(target));
			} catch (IllegalArgumentException | IllegalAccessException e) {
				LOGGER.error("Could not obtain the field {} in the junit test case, marks it public",
						field.getName(), e);
			}
		}
	}
	return fields;
}
 
开发者ID:sleroy,项目名称:bench4j,代码行数:15,代码来源:GetJUnitParameters.java

示例4: createTestUsingFieldInjection

import org.junit.runners.Parameterized.Parameter; //导入依赖的package包/类
private Object createTestUsingFieldInjection() throws Exception {
    List<FrameworkField> annotatedFieldsByParameter = getAnnotatedFieldsByParameter();
    if (annotatedFieldsByParameter.size() != fParameters.length) {
        throw new Exception(
                "Wrong number of parameters and @Parameter fields."
                        + " @Parameter fields counted: "
                        + annotatedFieldsByParameter.size()
                        + ", available parameters: " + fParameters.length
                        + ".");
    }
    Object testClassInstance = getTestClass().getJavaClass().newInstance();
    for (FrameworkField each : annotatedFieldsByParameter) {
        Field field = each.getField();
        Parameter annotation = field.getAnnotation(Parameter.class);
        int index = annotation.value();
        try {
            field.set(testClassInstance, fParameters[index]);
        } catch (IllegalArgumentException iare) {
            throw new Exception(getTestClass().getName()
                    + ": Trying to set " + field.getName()
                    + " with the value " + fParameters[index]
                    + " that is not the right type ("
                    + fParameters[index].getClass().getSimpleName()
                    + " instead of " + field.getType().getSimpleName()
                    + ").", iare);
        }
    }
    return testClassInstance;
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:30,代码来源:BlockJUnit4ClassRunnerWithParameters.java

示例5: validateFields

import org.junit.runners.Parameterized.Parameter; //导入依赖的package包/类
@Override
protected void validateFields(List<Throwable> errors) {
    super.validateFields(errors);
    if (fieldsAreAnnotated()) {
        List<FrameworkField> annotatedFieldsByParameter = getAnnotatedFieldsByParameter();
        int[] usedIndices = new int[annotatedFieldsByParameter.size()];
        for (FrameworkField each : annotatedFieldsByParameter) {
            int index = each.getField().getAnnotation(Parameter.class)
                    .value();
            if (index < 0 || index > annotatedFieldsByParameter.size() - 1) {
                errors.add(new Exception("Invalid @Parameter value: "
                        + index + ". @Parameter fields counted: "
                        + annotatedFieldsByParameter.size()
                        + ". Please use an index between 0 and "
                        + (annotatedFieldsByParameter.size() - 1) + "."));
            } else {
                usedIndices[index]++;
            }
        }
        for (int index = 0; index < usedIndices.length; index++) {
            int numberOfUse = usedIndices[index];
            if (numberOfUse == 0) {
                errors.add(new Exception("@Parameter(" + index
                        + ") is never used."));
            } else if (numberOfUse > 1) {
                errors.add(new Exception("@Parameter(" + index
                        + ") is used more than once (" + numberOfUse + ")."));
            }
        }
    }
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:32,代码来源:BlockJUnit4ClassRunnerWithParameters.java

示例6: createTestUsingFieldInjection

import org.junit.runners.Parameterized.Parameter; //导入依赖的package包/类
private Object createTestUsingFieldInjection() throws Exception {
	List<FrameworkField> annotatedFieldsByParameter = getAnnotatedFieldsByParameter();
	if (annotatedFieldsByParameter.size() != fParameters.length) {
		throw new Exception(String.format(
				"Wrong number of parameters and @Parameter fields. @Parameter fields counted: %s, available parameters: %s.",
				annotatedFieldsByParameter.size(), fParameters.length));
	}
	Object testClassInstance = getTestClass().getJavaClass().newInstance();
	if (getTestClass().getJavaClass() == JExUnitBase.class) {
		((JExUnitBase) testClassInstance).setTestType(testType);
	}
	for (FrameworkField each : annotatedFieldsByParameter) {
		Field field = each.getField();
		Parameter annotation = field.getAnnotation(Parameter.class);
		int index = annotation.value();
		try {
			if (field.isAccessible()) {
				field.set(testClassInstance, fParameters[index]);
			} else {
				field.setAccessible(true);
				field.set(testClassInstance, fParameters[index]);
				field.setAccessible(false);
			}
		} catch (IllegalArgumentException iare) {
			throw new Exception(
					String.format(
							"%s: Trying to set %s with the value %s that is not the right type (%s instead of %s).",
							getTestClass().getName(), field.getName(), fParameters[index],
							fParameters[index].getClass().getSimpleName(), field.getType().getSimpleName()),
					iare);
		}
	}
	return testClassInstance;
}
 
开发者ID:fhm84,项目名称:jexunit,代码行数:35,代码来源:Parameterized.java

示例7: validateFields

import org.junit.runners.Parameterized.Parameter; //导入依赖的package包/类
@Override
protected void validateFields(List<Throwable> errors) {
	super.validateFields(errors);
	if (fieldsAreAnnotated()) {
		List<FrameworkField> annotatedFieldsByParameter = getAnnotatedFieldsByParameter();
		int[] usedIndices = new int[annotatedFieldsByParameter.size()];
		for (FrameworkField each : annotatedFieldsByParameter) {
			int index = each.getField().getAnnotation(Parameter.class).value();
			if (index < 0 || index > annotatedFieldsByParameter.size() - 1) {
				errors.add(new Exception(String.format(
						"Invalid @Parameter value: %s. @Parameter fields counted: %s. Please use an index between 0 and %s.",
						index, annotatedFieldsByParameter.size(), annotatedFieldsByParameter.size() - 1)));
			} else {
				usedIndices[index]++;
			}
		}
		for (int index = 0; index < usedIndices.length; index++) {
			int numberOfUse = usedIndices[index];
			if (numberOfUse == 0) {
				errors.add(new Exception(String.format("@Parameter(%s) is never used.", index)));
			} else if (numberOfUse > 1) {
				errors.add(new Exception(
						String.format("@Parameter(%s) is used more than once (%s).", index, numberOfUse)));
			}
		}
	}
}
 
开发者ID:fhm84,项目名称:jexunit,代码行数:28,代码来源:Parameterized.java

示例8: getAnnotatedFieldsByParameter

import org.junit.runners.Parameterized.Parameter; //导入依赖的package包/类
private List<FrameworkField> getAnnotatedFieldsByParameter() {
    return getTestClass().getAnnotatedFields(Parameter.class);
}
 
开发者ID:hortonworks,项目名称:registry,代码行数:4,代码来源:CustomParameterizedBlockJUnit4Runner.java

示例9: getAnnotatedFieldsByParameter

import org.junit.runners.Parameterized.Parameter; //导入依赖的package包/类
private List<FrameworkField> getAnnotatedFieldsByParameter() {
	return getTestClass().getAnnotatedFields(Parameter.class);
}
 
开发者ID:fhm84,项目名称:jexunit,代码行数:4,代码来源:Parameterized.java


注:本文中的org.junit.runners.Parameterized.Parameter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。