|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
Imposteriser produces ClassCastException when JUnit tests are run with Ant.I am mocking Concrete classes using the standard Imposteriser.INSTANCE. The tests run fine under the Eclipse IDE. However when the same tests are run using the Ant JUnit task they fail with a ClassCastException. The condition required to reproduce this bug is to mock a concrete class (or its subclass) more than once over several test classes. Typically the first use of the Mock class succeeds, but subsequent Test classes using the same mocked concrete class fail. Commenting out the first usage will allow the second usage (which failed) to succeed. Debugging into the code seems to show CGLIBed instances of the expected class. The failure is in: public <T> T imposterise(final Invokable mockObject, Class<T> mockedType, Class<?>... ancilliaryTypes) { if (!mockedType.isInterface() && toStringMethodIsFinal(mockedType)) { throw new IllegalArgumentException(mockedType.getName() + " has a final toString method"); } try { setConstructorsAccessible(mockedType, true); Class<?> proxyClass = createProxyClass(mockedType, ancilliaryTypes); return mockedType.cast(createProxy(proxyClass, mockObject)); } finally { setConstructorsAccessible(mockedType, false); } } On this line: return mockedType.cast(createProxy(proxyClass, mockObject)); I have converted my own classes to use interfaces and removed imposteriser (using just interfaces with the imposteriser also fails). However I am now stuck because I am also mocking 3rd part classes. Any workarounds appreciated. P.S. I have upgraded from 2.5.1 to 2.6.o without improvement. |
|
|
Re: Imposteriser produces ClassCastException when JUnit tests are run with Ant.Sorry to be a pain, would you mind filing an issue for this.
Thanks S On 11 May 2009, at 08:26, Work wrote: > Hi All, just wasted a day on this. > > I am mocking Concrete classes using the standard > Imposteriser.INSTANCE. > > The tests run fine under the Eclipse IDE. > > However when the same tests are run using the Ant JUnit task they > fail with > a ClassCastException. > > The condition required to reproduce this bug is to mock a concrete > class (or > its subclass) more than > once over several test classes. Typically the first use of the Mock > class > succeeds, but subsequent > Test classes using the same mocked concrete class fail. Commenting > out the > first usage > will allow the second usage (which failed) to succeed. > > Debugging into the code seems to show CGLIBed instances of the > expected > class. > > The failure is in: > > public <T> T imposterise(final Invokable mockObject, Class<T> > mockedType, Class<?>... ancilliaryTypes) { if > (!mockedType.isInterface() && toStringMethodIsFinal(mockedType)) { > throw new IllegalArgumentException(mockedType.getName() + " has a > final > toString method"); } try { > setConstructorsAccessible(mockedType, true); Class<?> > proxyClass > = createProxyClass(mockedType, ancilliaryTypes); return > mockedType.cast(createProxy(proxyClass, mockObject)); } > finally { setConstructorsAccessible(mockedType, > false); } > } > > > On this line: > > return mockedType.cast(createProxy(proxyClass, > mockObject)); > I have converted my own classes to use interfaces and removed > imposteriser > (using just interfaces with the imposteriser also fails). > However I am now stuck because I am also mocking 3rd part classes. > Any workarounds appreciated. > > P.S. I have upgraded from 2.5.1 to 2.6.o without improvement. > 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 |
|
|
Re: Imposteriser produces ClassCastException when JUnit tests are run with Ant.How are you running the tests from ant? In a forked JVM? Or in Ant's JVM?
--Nat 2009/5/11 Work <richard.rothwell@...>: > Hi All, just wasted a day on this. > > I am mocking Concrete classes using the standard Imposteriser.INSTANCE. > > The tests run fine under the Eclipse IDE. > > However when the same tests are run using the Ant JUnit task they fail with > a ClassCastException. > > The condition required to reproduce this bug is to mock a concrete class (or > its subclass) more than > once over several test classes. Typically the first use of the Mock class > succeeds, but subsequent > Test classes using the same mocked concrete class fail. Commenting out the > first usage > will allow the second usage (which failed) to succeed. > > Debugging into the code seems to show CGLIBed instances of the expected > class. > > The failure is in: > > public <T> T imposterise(final Invokable mockObject, Class<T> > mockedType, Class<?>... ancilliaryTypes) { if > (!mockedType.isInterface() && toStringMethodIsFinal(mockedType)) { > throw new IllegalArgumentException(mockedType.getName() + " has a > final toString method"); } try { > setConstructorsAccessible(mockedType, true); Class<?> > proxyClass = createProxyClass(mockedType, ancilliaryTypes); > return mockedType.cast(createProxy(proxyClass, mockObject)); > } finally { setConstructorsAccessible(mockedType, > false); } } > > > On this line: > > return mockedType.cast(createProxy(proxyClass, mockObject)); > I have converted my own classes to use interfaces and removed imposteriser > (using just interfaces with the imposteriser also fails). > However I am now stuck because I am also mocking 3rd part classes. > Any workarounds appreciated. > > P.S. I have upgraded from 2.5.1 to 2.6.o without improvement. > -- http://www.natpryce.com --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: Imposteriser produces ClassCastException when JUnit tests are run with Ant.Steve its in JIRA now.
On 11/05/09 6:39 PM, "Steve Freeman" <steve@...> wrote: > Sorry to be a pain, would you mind filing an issue for this. > > Thanks > > S > > On 11 May 2009, at 08:26, Work wrote: > >> Hi All, just wasted a day on this. >> >> I am mocking Concrete classes using the standard >> Imposteriser.INSTANCE. >> >> The tests run fine under the Eclipse IDE. >> >> However when the same tests are run using the Ant JUnit task they >> fail with >> a ClassCastException. >> >> The condition required to reproduce this bug is to mock a concrete >> class (or >> its subclass) more than >> once over several test classes. Typically the first use of the Mock >> class >> succeeds, but subsequent >> Test classes using the same mocked concrete class fail. Commenting >> out the >> first usage >> will allow the second usage (which failed) to succeed. >> >> Debugging into the code seems to show CGLIBed instances of the >> expected >> class. >> >> The failure is in: >> >> public <T> T imposterise(final Invokable mockObject, Class<T> >> mockedType, Class<?>... ancilliaryTypes) { if >> (!mockedType.isInterface() && toStringMethodIsFinal(mockedType)) { >> throw new IllegalArgumentException(mockedType.getName() + " has a >> final >> toString method"); } try { >> setConstructorsAccessible(mockedType, true); Class<?> >> proxyClass >> = createProxyClass(mockedType, ancilliaryTypes); return >> mockedType.cast(createProxy(proxyClass, mockObject)); } >> finally { setConstructorsAccessible(mockedType, >> false); } >> } >> >> >> On this line: >> >> return mockedType.cast(createProxy(proxyClass, >> mockObject)); >> I have converted my own classes to use interfaces and removed >> imposteriser >> (using just interfaces with the imposteriser also fails). >> However I am now stuck because I am also mocking 3rd part classes. >> Any workarounds appreciated. >> >> P.S. I have upgraded from 2.5.1 to 2.6.o without improvement. >> > > 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 > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: Imposteriser produces ClassCastException when JUnit tests are run with Ant.I believe its in the Ant JVM. Ant is running within Eclipse.
On 12/05/09 4:39 AM, "Nat Pryce" <nat.pryce@...> wrote: > How are you running the tests from ant? In a forked JVM? Or in Ant's JVM? > > --Nat > > 2009/5/11 Work <richard.rothwell@...>: >> Hi All, just wasted a day on this. >> >> I am mocking Concrete classes using the standard Imposteriser.INSTANCE. >> >> The tests run fine under the Eclipse IDE. >> >> However when the same tests are run using the Ant JUnit task they fail with >> a ClassCastException. >> >> The condition required to reproduce this bug is to mock a concrete class (or >> its subclass) more than >> once over several test classes. Typically the first use of the Mock class >> succeeds, but subsequent >> Test classes using the same mocked concrete class fail. Commenting out the >> first usage >> will allow the second usage (which failed) to succeed. >> >> Debugging into the code seems to show CGLIBed instances of the expected >> class. >> >> The failure is in: >> >> public <T> T imposterise(final Invokable mockObject, Class<T> >> mockedType, Class<?>... ancilliaryTypes) { if >> (!mockedType.isInterface() && toStringMethodIsFinal(mockedType)) { >> throw new IllegalArgumentException(mockedType.getName() + " has a >> final toString method"); } try { >> setConstructorsAccessible(mockedType, true); Class<?> >> proxyClass = createProxyClass(mockedType, ancilliaryTypes); >> return mockedType.cast(createProxy(proxyClass, mockObject)); >> } finally { setConstructorsAccessible(mockedType, >> false); } } >> >> >> On this line: >> >> return mockedType.cast(createProxy(proxyClass, mockObject)); >> I have converted my own classes to use interfaces and removed imposteriser >> (using just interfaces with the imposteriser also fails). >> However I am now stuck because I am also mocking 3rd part classes. >> Any workarounds appreciated. >> >> P.S. I have upgraded from 2.5.1 to 2.6.o without improvement. >> > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
| Free embeddable forum powered by Nabble | Forum Help |