use of com.googlecode.gwt.test.exceptions.GwtTestException in project gwt-test-utils by gwt-test-utils.
the class UiTagBuilder method extractResource.
private Object extractResource(String group, UiResourceManager resourceManager, Object owner) {
String[] splitted = group.split("\\.");
String resourceAlias = splitted[0];
Object resource = resourceManager.getUiResource(resourceAlias);
if (resource == null) {
throw new GwtTestUiBinderException("Error in file '" + owner.getClass().getSimpleName() + ".ui.xml' : no resource declared for alias '" + resourceAlias + "'");
}
if (splitted.length == 1) {
return resource;
}
// handle "alias.myDataResource.getUrl"
try {
for (int i = 1; i < splitted.length; i++) {
if (CssResource.class.isInstance(resource)) {
// special case of css styles
return splitted[i];
} else {
resource = GwtReflectionUtils.callPrivateMethod(resource, splitted[i]);
}
}
return resource;
} catch (Exception e) {
if (GwtTestException.class.isInstance(e)) {
throw (GwtTestException) e;
} else {
throw new GwtTestUiBinderException("Error while calling property '" + group.substring(group.indexOf('.') + 1) + "' on object of type '" + resourceManager.getUiResource(resourceAlias).getClass().getName() + "'", e);
}
}
}
use of com.googlecode.gwt.test.exceptions.GwtTestException in project gwt-test-utils by gwt-test-utils.
the class GwtMockitoAnnotations method registerMocks.
private static void registerMocks(GwtTestWithMockito testInstance, Class<? extends Annotation> mockClass) {
Set<Field> fields = GwtMockitoUtils.getMockFields(testInstance.getClass(), mockClass);
fields.forEach(field -> {
try {
GwtReflectionUtils.makeAccessible(field);
testInstance.addMockedObject(field.getType(), field.get(testInstance));
} catch (IllegalAccessException e) {
// should never append
throw new GwtTestException("");
}
});
}
use of com.googlecode.gwt.test.exceptions.GwtTestException 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