org.junit.runners.model.FrameworkField Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of reactor-junit4 Show documentation
Show all versions of reactor-junit4 Show documentation
JUnit is a unit testing framework for Java, created by Erich Gamma and Kent Beck.
The newest version!
package org.junit.runners.model;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import org.junit.runners.BlockJUnit4ClassRunner;
/**
* Represents a field on a test class (currently used only for Rules in
* {@link BlockJUnit4ClassRunner}, but custom runners can make other uses)
*
* @since 4.7
*/
public class FrameworkField extends FrameworkMember {
private final Field field;
FrameworkField(Field field) {
if (field == null) {
throw new NullPointerException(
"FrameworkField cannot be created without an underlying field.");
}
this.field = field;
}
@Override
public String getName() {
return getField().getName();
}
public Annotation[] getAnnotations() {
return field.getAnnotations();
}
public T getAnnotation(Class annotationType) {
return field.getAnnotation(annotationType);
}
@Override
public boolean isShadowedBy(FrameworkField otherMember) {
return otherMember.getName().equals(getName());
}
@Override
protected int getModifiers() {
return field.getModifiers();
}
/**
* @return the underlying java Field
*/
public Field getField() {
return field;
}
/**
* @return the underlying Java Field type
* @see java.lang.reflect.Field#getType()
*/
@Override
public Class> getType() {
return field.getType();
}
@Override
public Class> getDeclaringClass() {
return field.getDeclaringClass();
}
/**
* Attempts to retrieve the value of this field on {@code target}
*/
public Object get(Object target) throws IllegalArgumentException, IllegalAccessException {
return field.get(target);
}
@Override
public String toString() {
return field.toString();
}
}