Search in sources :

Example 11 with GwtTestException

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);
        }
    }
}
Also used : GwtTestUiBinderException(com.googlecode.gwt.test.exceptions.GwtTestUiBinderException) GwtTestException(com.googlecode.gwt.test.exceptions.GwtTestException) UIObject(com.google.gwt.user.client.ui.UIObject) GwtTestException(com.googlecode.gwt.test.exceptions.GwtTestException) GwtTestUiBinderException(com.googlecode.gwt.test.exceptions.GwtTestUiBinderException)

Example 12 with GwtTestException

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("");
        }
    });
}
Also used : Field(java.lang.reflect.Field) GwtTestException(com.googlecode.gwt.test.exceptions.GwtTestException)

Example 13 with 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);
    }
}
Also used : ReflectionException(com.googlecode.gwt.test.exceptions.ReflectionException) UmbrellaException(com.google.web.bindery.event.shared.UmbrellaException) GwtTestException(com.googlecode.gwt.test.exceptions.GwtTestException) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) ReflectionException(com.googlecode.gwt.test.exceptions.ReflectionException) GwtTestException(com.googlecode.gwt.test.exceptions.GwtTestException) UmbrellaException(com.google.web.bindery.event.shared.UmbrellaException)

Aggregations

GwtTestException (com.googlecode.gwt.test.exceptions.GwtTestException)13 IOException (java.io.IOException)4 GwtTestConfigurationException (com.googlecode.gwt.test.exceptions.GwtTestConfigurationException)3 GwtTestPatchException (com.googlecode.gwt.test.exceptions.GwtTestPatchException)3 Field (java.lang.reflect.Field)3 GwtTestJSONException (com.googlecode.gwt.test.exceptions.GwtTestJSONException)2 GwtTestUiBinderException (com.googlecode.gwt.test.exceptions.GwtTestUiBinderException)2 ReflectionException (com.googlecode.gwt.test.exceptions.ReflectionException)2 PatchMethod (com.googlecode.gwt.test.patchers.PatchMethod)2 JsonParseException (org.codehaus.jackson.JsonParseException)2 JsonParser (org.codehaus.jackson.JsonParser)2 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)1 Command (com.google.gwt.user.client.Command)1 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 StatusCodeException (com.google.gwt.user.client.rpc.StatusCodeException)1 UIObject (com.google.gwt.user.client.ui.UIObject)1 UmbrellaException (com.google.web.bindery.event.shared.UmbrellaException)1 GwtTestWithMockito (com.googlecode.gwt.test.GwtTestWithMockito)1 RemoteServiceExecutionHandler (com.googlecode.gwt.test.RemoteServiceExecutionHandler)1 GwtTestDomException (com.googlecode.gwt.test.exceptions.GwtTestDomException)1