
com.jparams.junit4.data.reader.DataMethodReader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jparams-junit4 Show documentation
Show all versions of jparams-junit4 Show documentation
Parameterized JUnit4 Tests
package com.jparams.junit4.data.reader;
import com.jparams.junit4.data.DataMethod;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
public class DataMethodReader implements Reader {
@Override
public Object[][] readData(DataMethod annotation) {
try {
Method method = annotation.source().getDeclaredMethod(annotation.method());
int modifiers = method.getModifiers();
if (!Modifier.isPublic(modifiers) || !Modifier.isStatic(modifiers) || !method.getReturnType().equals(Object[][].class)) {
throw new ReaderException("Method must have the signature public static Object[][]");
}
return (Object[][]) method.invoke(null);
} catch (NoSuchMethodException e) {
throw new ReaderException("Unable to find method with name " + annotation.method(), e);
} catch (InvocationTargetException | IllegalAccessException e) {
throw new ReaderException("Error invoking data method", e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy