Jonathan
Jonathan

Reputation: 705

GWTMockito: How to mock AutoBeanCodex?

I have tests which I am writing that use AutoBeanCodex to encode and decode AutoBeans. When I try to test methods which use AutoBeanCodex.decode(...), I get errors like the following:

java.lang.ClassCastException:     com.google.web.bindery.autobean.shared.AutoBean$$EnhancerByMockitoWithCGLIB$$78caf05b cannot be cast to com.google.web.bindery.autobean.shared.impl.AbstractAutoBean
at com.google.web.bindery.autobean.shared.impl.AutoBeanCodexImpl.doDecode(AutoBeanCodexImpl.java:549)
at com.google.web.bindery.autobean.shared.AutoBeanCodex.decode(AutoBeanCodex.java:39)
at ...

First question is how do I deal with AutoBeanCodex in my gwtmockito tests?

Do I have to use a fake provider like so, GwtMockito.useProviderForType(Class, FakeProvider)?

If there are multiple ways to deal with AutoBeanCodex, what is the best approach?

Upvotes: 0

Views: 213

Answers (2)

adoalonso
adoalonso

Reputation: 325

You can also use powermock for testing with statics. I've used it with gwtmockito both in a same test

Upvotes: 0

Thomas Broyer
Thomas Broyer

Reputation: 64541

A priori (I haven't used GwtMockito, yet), you should configure a FakeProvider for AutoBeanFactory.class to delegate to AutoBeanFactorySource.create() so that you get real AutoBean instances, that AutoBeanCodex should be able to serialize and deserialize.

You should probably raise an issue to GwtMockito so that this behavior is built-in, like for UiBinder et al.

Upvotes: 0

Related Questions