org.junit.runners.model.FrameworkField Java Examples
The following examples show how to use
org.junit.runners.model.FrameworkField.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StandardsTestClass.java From htmlunit with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override protected void scanAnnotatedMembers(final Map<Class<? extends Annotation>, List<FrameworkMethod>> methodsForAnnotations, final Map<Class<? extends Annotation>, List<FrameworkField>> fieldsForAnnotations) { for (final Class<?> eachClass : getSuperClasses(getJavaClass())) { for (final Method eachMethod : MethodSorter.getDeclaredMethods(eachClass)) { addToAnnotationLists(new FrameworkMethod(eachMethod), methodsForAnnotations); } // Fields are ignored } for (final Map.Entry<Class<? extends Annotation>, List<FrameworkMethod>> methodsEntry : methodsForAnnotations.entrySet()) { final Class<? extends Annotation> key = methodsEntry.getKey(); if (key == Test.class) { final List<FrameworkMethod> methods = methodsEntry.getValue(); final List<FrameworkMethod> newMethods = new ArrayList<>(methods.size() * 2); for (final FrameworkMethod m : methods) { newMethods.add(new StandardsFrameworkMethod(m.getMethod(), false)); newMethods.add(new StandardsFrameworkMethod(m.getMethod(), true)); } methodsForAnnotations.put(key, newMethods); } } }
Example #2
Source File: BuckBlockJUnit4ClassRunner.java From buck with Apache License 2.0 | 6 votes |
/** * @return {@code true} if the test class has any fields annotated with {@code Rule} whose type is * {@link Timeout}. */ static boolean hasTimeoutRule(TestClass testClass) { // Many protected convenience methods in BlockJUnit4ClassRunner that are available in JUnit 4.11 // such as getTestRules(Object) were not public until // https://github.com/junit-team/junit/commit/8782efa08abf5d47afdc16740678661443706740, // which appears to be JUnit 4.9. Because we allow users to use JUnit 4.7, we need to include a // custom implementation that is backwards compatible to JUnit 4.7. List<FrameworkField> fields = testClass.getAnnotatedFields(Rule.class); for (FrameworkField field : fields) { if (field.getField().getType().equals(Timeout.class)) { return true; } } return false; }
Example #3
Source File: GeoWaveITRunner.java From geowave with Apache License 2.0 | 6 votes |
private static List<GeoWaveStoreRunnerConfig> addRunnerConfigsForField( final FrameworkField field, final List<GeoWaveStoreRunnerConfig> currentConfigs, final Set<GeoWaveStoreType> storeTypes) throws GeoWaveITException { final GeoWaveTestStore store = field.getField().getAnnotation(GeoWaveTestStore.class); final GeoWaveStoreType[] types = store.value(); if ((types == null) || (types.length == 0)) { throw new GeoWaveITException( MessageFormat.format("{0} must have at least one GeoWaveStoreType", field.getName())); } final List<GeoWaveStoreRunnerConfig> newConfigs = new ArrayList<>(); for (final GeoWaveStoreRunnerConfig config : currentConfigs) { for (final GeoWaveStoreType type : types) { newConfigs.add(new GeoWaveStoreRunnerConfig(config, field.getName(), type)); storeTypes.add(type); } } return newConfigs; }
Example #4
Source File: WildflyTestRunner.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Override protected List<FrameworkMethod> getChildren() { final List<FrameworkMethod> result = new ArrayList<>(); final TestClass testClass = getTestClass(); final Collection<Object> parameters = resolveParameters(testClass); // If there are no resolved parameters we can just use the default methods if (parameters.isEmpty()) { result.addAll(super.getChildren()); } else { final FrameworkField field = findParameterField(testClass); for (FrameworkMethod method : super.getChildren()) { for (Object value : parameters) { parameterDescriptions.add(method, field, value); // Add the same method for each parameter value result.add(method); } } } return result; }
Example #5
Source File: WildflyTestRunner.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
private void doInject(TestClass klass, Object instance) { try { for (FrameworkField frameworkField : klass.getAnnotatedFields(Inject.class)) { Field field = frameworkField.getField(); if ((instance == null && Modifier.isStatic(field.getModifiers()) || instance != null)) {//we want to do injection even on static fields before test run, so we make sure that client is correct for current state of server field.setAccessible(true); if (field.getType() == ManagementClient.class && controller.isStarted()) { field.set(instance, controller.getClient()); } else if (field.getType() == ModelControllerClient.class && controller.isStarted()) { field.set(instance, controller.getClient().getControllerClient()); } else if (field.getType() == ServerController.class) { field.set(instance, controller); } } } } catch (Exception e) { throw new RuntimeException("Failed to inject", e); } }
Example #6
Source File: KurentoTestListener.java From kurento-java with Apache License 2.0 | 6 votes |
public KurentoTestListener(List<FrameworkField> services) { this.serviceFields = services; for (FrameworkField service : serviceFields) { TestService serviceRunner = null; try { serviceRunner = (TestService) service.getField().get(null); if (!serviceRunners.contains(serviceRunner)) { serviceRunners.add(serviceRunner); if (serviceRunner.getScope() == TESTSUITE) { serviceRunner.start(); } } } catch (Throwable e) { log.warn("Exception instanting service in class {}", serviceRunner, e); } } }
Example #7
Source File: Injected.java From ion-java with Apache License 2.0 | 6 votes |
private static PropertyDescriptor findDescriptor(TestClass testClass, PropertyDescriptor[] descriptors, FrameworkField field, String name) throws Exception { for (PropertyDescriptor d : descriptors) { if (d.getName().equals(name)) { if (d.getWriteMethod() == null) break; // To throw error return d; } } throw new Exception("@Inject value '" + name + "' doesn't match a writeable property near " + testClass.getName() + '.' + field.getField().getName()); }
Example #8
Source File: BaseRunner.java From baratine with GNU General Public License v2.0 | 6 votes |
@Override protected void scanAnnotatedMembers(Map<Class<? extends Annotation>,List<FrameworkMethod>> methodsForAnnotations, Map<Class<? extends Annotation>,List<FrameworkField>> fieldsForAnnotations) { super.scanAnnotatedMembers(methodsForAnnotations, fieldsForAnnotations); for (Map.Entry<Class<? extends Annotation>,List<FrameworkMethod>> entry : methodsForAnnotations.entrySet()) { if (Test.class.equals(entry.getKey())) { List<FrameworkMethod> methods = new ArrayList<>(); for (FrameworkMethod method : entry.getValue()) { Method javaMethod = method.getMethod(); if (javaMethod.getParameterTypes().length > 0) { methods.add(new BaratineFrameworkMethod(javaMethod)); } else { methods.add(method); } } entry.setValue(methods); } } }
Example #9
Source File: BaseRunner.java From baratine with GNU General Public License v2.0 | 6 votes |
public List<T> getInjectionTestPoints() throws IllegalAccessException { List<T> result = new ArrayList<>(); List<FrameworkField> fields = getTestClass().getAnnotatedFields(); final MethodHandles.Lookup lookup = MethodHandles.lookup(); for (FrameworkField field : fields) { Field javaField = field.getField(); javaField.setAccessible(true); MethodHandle setter = lookup.unreflectSetter(javaField); T ip = createInjectionPoint(javaField.getType(), javaField.getAnnotations(), setter); result.add(ip); } return result; }
Example #10
Source File: AgentRunner.java From java-specialagent with Apache License 2.0 | 6 votes |
/** * Creates the {@link TestClass} object for this JUnit runner with the * specified test class. * <p> * This method has been overridden to retrofit the {@link FrameworkMethod} * objects. * * @param testClass The test class. * @return The {@link TestClass} object for this JUnit runner with the * specified test class. */ @Override protected TestClass createTestClass(final Class<?> testClass) { return new TestClass(testClass) { @Override public List<FrameworkMethod> getAnnotatedMethods(final Class<? extends Annotation> annotationClass) { final List<FrameworkMethod> retrofitted = new ArrayList<>(); for (final FrameworkMethod method : super.getAnnotatedMethods(annotationClass)) retrofitted.add(retrofitMethod(method)); return Collections.unmodifiableList(retrofitted); } @Override protected void scanAnnotatedMembers(final Map<Class<? extends Annotation>,List<FrameworkMethod>> methodsForAnnotations, final Map<Class<? extends Annotation>,List<FrameworkField>> fieldsForAnnotations) { super.scanAnnotatedMembers(methodsForAnnotations, fieldsForAnnotations); for (final Map.Entry<Class<? extends Annotation>,List<FrameworkMethod>> entry : methodsForAnnotations.entrySet()) { final ListIterator<FrameworkMethod> iterator = entry.getValue().listIterator(); while (iterator.hasNext()) iterator.set(retrofitMethod(iterator.next())); } } }; }
Example #11
Source File: XtextParametrizedRunner.java From n4js with Eclipse Public License 1.0 | 6 votes |
/** * Implements behavior from: org.junit.runners.Parameterized$TestClassRunnerForParameters */ 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().getConstructor().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; }
Example #12
Source File: ParameterStatement.java From neodymium-library with MIT License | 6 votes |
private void injectTestParameter() throws Exception { int parameterFieldCount = statementData.getParameterFrameworkFields().size(); Object[] parameter = statementData.getParameter(); if (parameterFieldCount != parameter.length) { throw new Exception("Number of parameters (" + parameter.length + ") and " + // "fields (" + parameterFieldCount + ") " + // "annotated with @Parameter must match!"); } for (FrameworkField parameterFrameworkField : statementData.getParameterFrameworkFields()) { Field field = parameterFrameworkField.getField(); int parameterIndex = field.getAnnotation(Parameter.class).value(); LOGGER.debug("Set parameter \"" + parameterFrameworkField.getName() + "\" to \"" + parameter[parameterIndex] + "\""); setField(field, parameter[parameterIndex]); } }
Example #13
Source File: VertxUnitRunnerWithParameters.java From vertx-unit with Apache License 2.0 | 5 votes |
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(); Parameterized.Parameter annotation = field.getAnnotation(Parameterized.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; }
Example #14
Source File: BrowserVersionClassRunnerWithParameters.java From htmlunit with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override protected void validateFields(final List<Throwable> errors) { super.validateFields(errors); if (fieldsAreAnnotated()) { final List<FrameworkField> annotatedFieldsByParameter = getAnnotatedFieldsByParameter(); final int[] usedIndices = new int[annotatedFieldsByParameter.size()]; for (final FrameworkField each : annotatedFieldsByParameter) { final 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++) { final 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 + ").")); } } } }
Example #15
Source File: GeoWaveITRunner.java From geowave with Apache License 2.0 | 5 votes |
@Override protected void validateFields(final List<Throwable> errors) { super.validateFields(errors); if (typeIsAnnotated()) { if (fieldsAreAnnotated()) { errors.add( new GeoWaveITException( "Only type or fields can be annotated with @GeoWaveTestStore, not both")); } try { getDataStoreOptionFieldsForTypeAnnotation(); } catch (final Exception e) { errors.add(e); } } else if (fieldsAreAnnotated()) { final List<FrameworkField> annotatedFields = getStoreAnnotatedFields(); for (final FrameworkField field : annotatedFields) { if (!field.getType().isAssignableFrom(DataStorePluginOptions.class)) { errors.add( new GeoWaveITException( "'" + field.getName() + "' must be of type '" + DataStorePluginOptions.class.getName() + "'")); } } } }
Example #16
Source File: WildflyTestRunner.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private FrameworkField findParameterField(final TestClass testClass) { final List<FrameworkField> fields = testClass.getAnnotatedFields(Parameter.class); if (fields.size() > 1) { throw new RuntimeException(String.format("More than one field was annotated with @%s: %s", Parameter.class.getSimpleName(), fields)); } else if (fields.isEmpty()) { throw new RuntimeException(String.format("If the @%s annotation is present on a method a field must be annotated with @%s", Parameters.class.getSimpleName(), Parameter.class.getSimpleName())); } return fields.get(0); }
Example #17
Source File: FrameworkMethodWithParameters.java From htmlunit with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public Object invokeExplosively(final Object target, final Object... params) throws Throwable { if (!parameters_.isEmpty()) { final List<FrameworkField> annotatedFieldsByParameter = testClass_.getAnnotatedFields(Parameter.class); if (annotatedFieldsByParameter.size() != parameters_.size()) { throw new Exception( "Wrong number of parameters and @Parameter fields." + " @Parameter fields counted: " + annotatedFieldsByParameter.size() + ", available parameters: " + parameters_.size() + "."); } for (final FrameworkField each : annotatedFieldsByParameter) { final Field field = each.getField(); final Parameter annotation = field.getAnnotation(Parameter.class); final int index = annotation.value(); try { field.set(target, parameters_.get(index)); } catch (final IllegalArgumentException iare) { throw new Exception(testClass_.getName() + ": Trying to set " + field.getName() + " with the value " + parameters_.get(index) + " that is not the right type (" + parameters_.get(index).getClass().getSimpleName() + " instead of " + field.getType().getSimpleName() + ").", iare); } } } return super.invokeExplosively(target, params); }
Example #18
Source File: KurentoTestRunner.java From kurento-java with Apache License 2.0 | 5 votes |
@Override public void run(RunNotifier notifier) { if (listener != null) { notifier.removeListener(listener); } List<FrameworkField> services = this.getTestClass().getAnnotatedFields(Service.class); ArrayList<FrameworkField> sortedServices = new ArrayList<>(services); Collections.sort(sortedServices, new Comparator<FrameworkField>() { @Override public int compare(FrameworkField o1, FrameworkField o2) { return Integer.compare(o1.getAnnotation(Service.class).value(), o2.getAnnotation(Service.class).value()); } }); listener = new KurentoTestListener(sortedServices); notifier.addListener(listener); listener.testRunStarted(getDescription()); if (!shutdownHook) { shutdownHook = true; Runtime.getRuntime().addShutdownHook(new Thread("app-shutdown-hook") { @Override public void run() { listener.testSuiteFinished(); } }); } // TODO Remove this if we change service management notifier = new KurentoRunNotifier(notifier); super.run(notifier); }
Example #19
Source File: PtlBlockJUnit4ClassRunnerWithParameters.java From hifive-pitalium with Apache License 2.0 | 5 votes |
/** * {@link ParameterizedClassRule}が設定されているフィールドまたはメソッドをチェックします。 * * @param errors エラーのリスト。チェックした結果エラーがあった場合、このリストに追加される */ protected void validateParameterizedClassRules(List<Throwable> errors) { for (FrameworkMethod method : getTestClass().getAnnotatedMethods(ParameterizedClassRule.class)) { if (!method.isStatic()) { errors.add(new Exception("Method " + method.getName() + "() should be static")); } if (!method.isPublic()) { errors.add(new Exception("Method " + method.getName() + "() should be public")); } if (method.getMethod().getParameterTypes().length != 0) { errors.add(new Exception("Method " + method.getName() + "() should have no parameters")); } if (!ParameterizedTestRule.class.isAssignableFrom(method.getType())) { errors.add(new Exception("Method " + method.getName() + "() must return an implementation of ParameterizedTestRule")); } } for (FrameworkField field : getTestClass().getAnnotatedFields(ParameterizedClassRule.class)) { if (!field.isStatic()) { errors.add(new Exception("Field " + field.getName() + " should be static")); } if (!field.isPublic()) { errors.add(new Exception("Field " + field.getName() + " should be public")); } if (!ParameterizedTestRule.class.isAssignableFrom(field.getType())) { errors.add(new Exception("Field " + field.getName() + " must implement ParameterizedTestRule")); } } }
Example #20
Source File: VertxUnitRunnerWithParameters.java From vertx-unit with Apache License 2.0 | 5 votes |
@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(Parameterized.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 + ").")); } } } }
Example #21
Source File: XtextParametrizedRunner.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Implements behavior from: org.junit.runners.Parameterized$TestClassRunnerForParameters */ @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 + ").")); } } } }
Example #22
Source File: Injected.java From ion-java with Apache License 2.0 | 5 votes |
private static Dimension[] findDimensions(TestClass testClass) throws Throwable { List<FrameworkField> fields = testClass.getAnnotatedFields(Inject.class); if (fields.isEmpty()) { throw new Exception("No fields of " + testClass.getName() + " have the @Inject annotation"); } BeanInfo beanInfo = Introspector.getBeanInfo(testClass.getJavaClass()); PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors(); Dimension[] dimensions = new Dimension[fields.size()]; int i = 0; for (FrameworkField field : fields) { int modifiers = field.getField().getModifiers(); if (! Modifier.isPublic(modifiers) || ! Modifier.isStatic(modifiers)) { throw new Exception("@Inject " + testClass.getName() + '.' + field.getField().getName() + " must be public static"); } Dimension dim = new Dimension(); dim.property = field.getField().getAnnotation(Inject.class).value(); dim.descriptor = findDescriptor(testClass, descriptors, field, dim.property); dim.values = (Object[]) field.get(null); dimensions[i++] = dim; } return dimensions; }
Example #23
Source File: JpaUnitRunner.java From jpa-unit with Apache License 2.0 | 5 votes |
public JpaUnitRunner(final Class<?> clazz) throws InitializationError { super(clazz); executor = new DecoratorExecutor(); final List<FrameworkField> ruleFields = getTestClass().getAnnotatedFields(Rule.class); if (ruleFields.stream().anyMatch(f -> f.getType().equals(JpaUnitRule.class))) { throw new InitializationError("JpaUnitRunner and JpaUnitRule exclude each other"); } }
Example #24
Source File: SharedBehaviorTesting.java From FreeBuilder with Apache License 2.0 | 5 votes |
public SharedBehaviorTesting( Function<RunNotifier, Statement> superChildrenInvoker, BiConsumer<FrameworkMethod, RunNotifier> superChildRunner, TestSupplier superCreateTest, Supplier<Description> superDescription, Supplier<TestClass> testClass, BiFunction<Class<?>, String, Description> descriptionFactory, FeatureSet features) throws InitializationError { this.superChildrenInvoker = superChildrenInvoker; this.superChildRunner = superChildRunner; this.superCreateTest = superCreateTest; this.superDescription = superDescription; this.features = features; List<FrameworkField> testerFields = testClass.get().getAnnotatedFields(Shared.class); if (testerFields.isEmpty()) { throw new InitializationError("No public @Shared field found"); } else if (testerFields.size() > 1) { throw new InitializationError("Multiple public @Shared fields found"); } FrameworkField frameworkField = getOnlyElement(testerFields); if (!frameworkField.isPublic()) { throw new InitializationError("@Shared field " + frameworkField + " must be public"); } if (!frameworkField.getType().isAssignableFrom(BehaviorTester.class)) { throw new InitializationError(String.format( "@Shared field %s must be of type %s", frameworkField, BehaviorTester.class.getSimpleName())); } testerField = frameworkField.getField(); introspection = descriptionFactory.apply(testClass.get().getJavaClass(), "Introspect"); }
Example #25
Source File: CustomParameterizedBlockJUnit4Runner.java From registry with Apache License 2.0 | 5 votes |
@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 + ").")); } } } }
Example #26
Source File: CustomParameterizedBlockJUnit4Runner.java From registry with Apache License 2.0 | 5 votes |
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; }
Example #27
Source File: ArchUnitRunner.java From ArchUnit with Apache License 2.0 | 5 votes |
private Collection<ArchTestExecution> findArchRuleFields() { List<ArchTestExecution> result = new ArrayList<>(); for (FrameworkField ruleField : getTestClass().getAnnotatedFields(ArchTest.class)) { result.addAll(findArchRulesIn(ruleField)); } return result; }
Example #28
Source File: ArchUnitRunner.java From ArchUnit with Apache License 2.0 | 5 votes |
private Set<ArchTestExecution> findArchRulesIn(FrameworkField ruleField) { boolean ignore = elementShouldBeIgnored(ruleField.getField()); if (ruleField.getType() == ArchRules.class) { return asTestExecutions(getArchRules(ruleField.getField()), ignore); } return Collections.<ArchTestExecution>singleton(new ArchRuleExecution(getTestClass().getJavaClass(), ruleField.getField(), ignore)); }
Example #29
Source File: ParameterStatementData.java From neodymium-library with MIT License | 4 votes |
public ParameterStatementData(int parameterIndex, Object[] parameter, List<FrameworkField> parameterFrameworkFields) { this.parameterIndex = parameterIndex; this.parameter = parameter; this.parameterFrameworkFields = parameterFrameworkFields; }
Example #30
Source File: GeoWaveITRunner.java From geowave with Apache License 2.0 | 4 votes |
private List<FrameworkField> getStoreAnnotatedFields() { return getTestClass().getAnnotatedFields(GeoWaveTestStore.class); }