« Return to Thread: ClassCastException with generic method

Re: ClassCastException with generic method

by Steve Freeman-2 :: Rate this Message:

Reply to Author | View in Thread

Before we go any further, you're expecting a string but the interface  
says InputStream.

Is that correct?

S.


On 6 May 2009, at 20:11, Jeudy, Guillaume wrote:

> Hi,
>
> I'm trying to test a generic method. Is that possible with jmock2? I  
> tried  one(jaxbUnmarshaller).unmarshal(with(any(Class.class),  
> with(any(String.class))) but that also fails.
>
> expectations code:
>
> this.mockContext.checking(new Expectations() {{
>   one(jaxbUnmarshaller).unmarshal(with(Issue.class),  
> with(any(String.class)));
>  }});
>
> interface:
>
> public interface JAXBUnmarshaller {
> <T> T unmarshal(Class<T> expectedType, InputStream inputStream)  
> throws JAXBException;
> }
>
> throws:
>
> java.lang.ClassCastException: java.lang.Object
> at a.b.msdmi.mdb.AJSubscriber.onMessage(AJSubscriber.java:65)
> at  
> a
> .b
> .msdmi
> .mdb.AJSubscriberTest.testOnMessage_Success(AJSubscriberTest.java:41)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at  
> sun
> .reflect
> .NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> at  
> sun
> .reflect
> .DelegatingMethodAccessorImpl
> .invoke(DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:585)
> at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:
> 580)
> at org.testng.internal.Invoker.invokeMethod(Invoker.java:478)
> at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:617)
> at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:885)
> at  
> org
> .testng
> .internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:
> 126)
> at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:110)
> at org.testng.TestRunner.runWorkers(TestRunner.java:712)
> at org.testng.TestRunner.privateRun(TestRunner.java:582)
> at org.testng.TestRunner.run(TestRunner.java:477)
> at org.testng.SuiteRunner.runTest(SuiteRunner.java:324)
> at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:319)
> at org.testng.SuiteRunner.privateRun(SuiteRunner.java:292)
> at org.testng.SuiteRunner.run(SuiteRunner.java:198)
> at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:823)
> at org.testng.TestNG.runSuitesLocally(TestNG.java:790)
> at org.testng.TestNG.run(TestNG.java:708)
> at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:73)
> at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:124)
>
> Thanks,
> -Guillaume
>
>
> ____________________________________________________________________________________________________
> This electronic mail (including any attachments) may contain  
> information that is privileged, confidential, and/or otherwise  
> protected from disclosure to anyone other than its intended  
> recipient(s). Any dissemination or use of this electronic email or  
> its contents (including any attachments) by persons other than the  
> intended recipient(s) is strictly prohibited. If you have received  
> this message in error, please notify us immediately by reply email  
> so that we may correct our internal records. Please then delete the  
> original message (including any attachments) in its entirety. Thank  
> you.

Steve Freeman
Winner of the Agile Alliance Gordon Pask award 2006

http://www.m3p.co.uk

M3P Limited.
Registered office. 2 Church Street, Burnham, Bucks, SL1 7HZ.
Company registered in England & Wales. Number 03689627



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


 « Return to Thread: ClassCastException with generic method