From 5630e9d5fc4f930b7ec90bf28f6a3fff6b929c84 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Manuel=20Carrasco=20Mo=C3=B1ino?= Date: Fri, 15 Mar 2013 12:38:04 +0100 Subject: [PATCH] Add a couple of missing methods --- .../java/com/google/gwt/query/client/Function.java | 10 ++++++++++ .../java/com/google/gwt/query/client/Properties.java | 4 ++++ .../google/gwt/query/client/GQueryDeferredTestGwt.java | 9 ++++----- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/Function.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/Function.java index 8a1d0751..8c170b8c 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/Function.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/Function.java @@ -139,6 +139,16 @@ public abstract class Function { return getArgument(-1, idx, null); } + /** + * Safety return the argument in the position idx. + * + * If the element class is not of the requested type it returns null and + * you don't get casting exeption. + */ + public T getArgument(int argIdx, int pos) { + return getArgument(argIdx, pos, null); + } + /** * Safety return the argument in the position idx. * diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/Properties.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/Properties.java index 090089f5..3651861b 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/Properties.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/Properties.java @@ -129,6 +129,10 @@ public class Properties extends JavaScriptObject { public final Object getObject(Object name) { return c().get(String.valueOf(name)); } + + public final Properties getProperties(Object name) { + return getJavaScriptObject(name); + } @SuppressWarnings("unchecked") public final T getJavaScriptObject(Object name) { diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryDeferredTestGwt.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryDeferredTestGwt.java index 898b3576..4c695bc5 100644 --- a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryDeferredTestGwt.java +++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryDeferredTestGwt.java @@ -152,12 +152,11 @@ public class GQueryDeferredTestGwt extends GWTTestCase { String url = "https://www.googleapis.com/blogger/v2/blogs/user_id/posts/post_id?callback=?&key=NO-KEY"; delayTestFinish(5000); - - when(Ajax.getJSONP(url, null, null, 1000)) + GQuery.when(Ajax.getJSONP(url, null, null, 1000)) .done(new Function() { public void f() { - Properties p = getArgumentJSO(0, 0); - assertEquals(400, p.getJavaScriptObject("error").cast().getInt("code")); + Properties p = getArgument(0, 0); + assertEquals(400, p.getProperties("error").getInt("code")); finishTest(); } }); @@ -169,7 +168,7 @@ public class GQueryDeferredTestGwt extends GWTTestCase { delayTestFinish(5000); - when( + GQuery.when( Ajax.getJSONP(url1), Ajax.getJSONP(url2, null, null, 1000)) .done(new Function() { -- 2.39.5