Skip to content

Commit 51a95c0

Browse files
zbynekekuefler
authored andcommitted
Allow ResourcePrototype methods in fake ClientBundle (#83)
1 parent f9829ac commit 51a95c0

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

gwtmockito/src/main/java/com/google/gwtmockito/fakes/FakeClientBundleProvider.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Exceptio
8787
return false;
8888
} else if (returnType == int.class) {
8989
return 0;
90-
} else if (method.getParameterTypes()[0] == ResourceCallback.class) {
90+
} else if (method.getParameterTypes().length > 0
91+
&& method.getParameterTypes()[0] == ResourceCallback.class) {
9192
// Read the underlying resource type out of the generic parameter
9293
// in the method's argument
9394
Class<?> resourceType =
@@ -97,6 +98,9 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Exceptio
9798
((ResourceCallback<ResourcePrototype>) args[0]).onSuccess(
9899
(ResourcePrototype) createFakeResource(resourceType, name));
99100
return null;
101+
} else if (returnType.isInstance(proxy)) {
102+
// for custom methods producing ResourcePrototype
103+
return proxy;
100104
} else {
101105
throw new IllegalArgumentException(
102106
"Unexpected return type for method " + method.getName());

gwtmockito/src/test/java/com/google/gwtmockito/GwtMockitoTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,12 @@ public void onError(ResourceException e) {
412412
assertEquals("externalText", result.toString());
413413
}
414414

415+
@Test
416+
public void shouldMockCustomClientBundles() throws Exception {
417+
SvgClientBundle clientBundle = GWT.create(SvgClientBundle.class);
418+
assertTrue(clientBundle.icon().transform() instanceof DataResource);
419+
}
420+
415421
/**
416422
* This would fail if we didn't stub the create methods from DOM. See
417423
* https://github.com/google/gwtmockito/issues/4.
@@ -746,6 +752,14 @@ interface SomeClientBundle extends ClientBundle {
746752
TextResource text();
747753
}
748754

755+
interface SvgResource extends DataResource {
756+
SvgResource transform();
757+
}
758+
759+
interface SvgClientBundle extends ClientBundle {
760+
SvgResource icon();
761+
}
762+
749763
enum SomeEnum {
750764
ONE, TWO
751765
}

0 commit comments

Comments
 (0)