use of com.googlecode.gwt.test.exceptions.ReflectionException in project gwt-test-utils by gwt-test-utils.
the class GwtReflectionUtils method callPrivateMethod.
public static <T> T callPrivateMethod(JavaScriptObject target, String methodName, String overlayOriginalType, Object... args) {
if (overlayOriginalType == null) {
throw new IllegalArgumentException("The specified overlay type should not be null");
}
overlayOriginalType = overlayOriginalType.trim();
if (overlayOriginalType.equals("")) {
throw new IllegalArgumentException("The specified overlay type should not be blank");
}
if (overlayOriginalType.endsWith("$")) {
throw new IllegalArgumentException("The specified overlay type should not be a rewritten type : " + overlayOriginalType);
}
Class<?> rewrittenOverlayType = null;
try {
rewrittenOverlayType = Class.forName(overlayOriginalType + "$");
} catch (ClassNotFoundException e) {
throw new ReflectionException("Error while calling overlay rewritten method " + overlayOriginalType + "$." + methodName + "$(..) :", e);
}
Object[] newArgs = new Object[args.length + 1];
newArgs[0] = target;
System.arraycopy(args, 0, newArgs, 1, args.length);
return callStaticMethod(rewrittenOverlayType, methodName + "$", newArgs);
}
use of com.googlecode.gwt.test.exceptions.ReflectionException in project gwt-test-utils by gwt-test-utils.
the class GwtTestWithEasyMock method beforeGwtTestWithEasyMock.
@Before
public void beforeGwtTestWithEasyMock() {
mockedClasses.forEach(clazz -> getMockManager().registerMock(clazz, createMock(clazz)));
try {
for (Field f : mockFields) {
Object mock = getMockManager().getMock(f.getType());
GwtReflectionUtils.makeAccessible(f);
f.set(this, mock);
}
} catch (Exception e) {
if (GwtTestException.class.isInstance(e)) {
throw (GwtTestException) e;
} else {
throw new ReflectionException("Error during gwt-test-utils @Mock creation", e);
}
}
}
use of com.googlecode.gwt.test.exceptions.ReflectionException in project gwt-test-utils by gwt-test-utils.
the class UiBinderBeanUtils method populateObject.
/**
* @param o
* @param properties
* @see BeanUtilsBean#populate(Object, Map)
*/
public static void populateObject(Object o, Map<String, Object> properties) {
try {
Map<String, Object> filteredProperties = new HashMap<>();
for (String key : properties.keySet()) {
if (PropertyUtils.isWriteable(o, key)) {
filteredProperties.put(key, properties.get(key));
}
}
UIBINDER_BEANUTILS.populate(o, filteredProperties);
} catch (Exception e) {
throw new ReflectionException("UiBinder error while setting properties for '" + o.getClass().getSimpleName() + "'", e);
}
// handle specifics
String[] styles = (String[]) properties.get("addStyleNames");
if (styles != null) {
for (String style : styles) {
if (o instanceof IsWidget) {
((IsWidget) o).asWidget().addStyleName(style);
} else if (o instanceof UIObject) {
((UIObject) o).addStyleName(style);
}
}
}
}
use of com.googlecode.gwt.test.exceptions.ReflectionException in project gwt-test-utils by gwt-test-utils.
the class GwtReflectionUtils method callStaticMethod.
public static <T> T callStaticMethod(Class<?> clazz, String methodName, Object... args) {
Method m = findMethod(clazz, methodName, args);
if (m == null) {
throw new ReflectionException("Cannot find method '" + clazz.getName() + "." + methodName + "(..)'");
}
try {
m.setAccessible(true);
Object res = m.invoke(null, args);
return (T) res;
} catch (Exception e) {
throw new ReflectionException("Unable to call static method '" + m.toString() + "'", e);
}
}
use of com.googlecode.gwt.test.exceptions.ReflectionException in project gwt-test-utils by gwt-test-utils.
the class GwtReflectionUtils method callPrivateMethod.
public static <T> T callPrivateMethod(Object target, Method method, Object... args) {
try {
method.setAccessible(true);
Object res = method.invoke(target, args);
return (T) res;
} catch (InvocationTargetException e) {
if (e.getCause() instanceof GwtTestException) {
throw (GwtTestException) e.getCause();
} else if (e.getCause() instanceof AssertionError) {
throw (AssertionError) e.getCause();
} else if (e.getCause() instanceof UmbrellaException) {
throw new ReflectionException("Error while calling method '" + method.toString() + "'", e.getCause().getCause());
}
throw new ReflectionException("Error while calling method '" + method.toString() + "'", e.getCause());
} catch (Exception e) {
throw new ReflectionException("Unable to call method '" + target.getClass().getSimpleName() + "." + method.getName() + "(..)'", e);
}
}
Aggregations