Here is the exception.

-------------------------------------------------------------------------------
Test set: org.appfuse.tutorial.service.impl.PersonManagerImplTest
-------------------------------------------------------------------------------
Tests run: 4, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.25 sec <<<
FAILURE!
testSavePerson(org.appfuse.tutorial.service.impl.PersonManagerImplTest) 
Time elapsed: 0.01 sec  <<< ERROR!
java.lang.ClassCastException: java.lang.Object cannot be cast to
org.appfuse.tutorial.model.Person
        at
org.appfuse.tutorial.service.impl.PersonManagerImpl.save(PersonManagerImpl.java:28)
        at
org.appfuse.tutorial.service.impl.PersonManagerImplTest.testSavePerson(PersonManagerImplTest.java:76)
        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:597)
        at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
        at org.jmock.integration.junit4.JMock$1.invoke(JMock.java:36)
        at
org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
        at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
        at
org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
        at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
        at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
        at
org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
        at
org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
        at
org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
        at
org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
        at 
org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
        at
org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
        at
org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
        at
org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:138)
        at
org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:125)
        at org.apache.maven.surefire.Surefire.run(Surefire.java:132)
        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:597)
        at
org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:290)
        at
org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:818)



mraible wrote:
> 
> Can you post the full stack trace?
> 
> Matt
> 
> On Tue, Jun 17, 2008 at 6:13 AM, Martin Homik <[EMAIL PROTECTED]> wrote:
> 
>>
>> Reproduced on the Person tutorial. Just add the following method to
>> PersonManagerImpl.java:
>>    @Override
>>    @Transactional
>>    public Person save(Person person) {
>>        /* do something else */
>>
>>        return super.save(person);
>>    }
>>
>>
>> Any ideas, how to overcome this obstacle? What's the proper way to
>> override
>> a save method in the manager?
>>
>> MH
>>
>>
>>
>>
>> Martin Homik wrote:
>> >
>> > In my managers, I override the save method. There is no problem in
>> > production state, that is jetty:run-war runs perfectly well. But in the
>> > test-cycle,  I get a ClassCastException. So, the problem must be
>> related
>> > to the mocks in the test classes.
>> >
>> > Here is my manager class:
>> > public class SurveyValueManagerImpl
>> >          extends GenericManagerImpl<SurveyValue, Long>
>> >        implements SurveyValueManager {
>> >
>> >         [... some other methods ...]
>> >
>> >
>> >         @Override
>> >       @Transactional
>> >       public SurveyValue save(SurveyValue surveyValue) {
>> >
>> >            [... do something else ...]
>> >
>> >            Object o = super.save(surveyValue);
>> >
>> >            return (SurveyValue) o;
>> >       }
>> > }
>> >
>> > The super save method returns successfully, but because I have to
>> return
>> > something of type SurveyValue, I need to cast the object to the
>> > SurveyValue type. And that's the problem.
>> >
>> > The test method is no surprise:
>> >
>> >       @Test
>> >       public void testSaveSurveyValue() {
>> >               log.debug("testing saveSurveyValue");
>> >
>> >               final SurveyValue surveyValue = new SurveyValue();
>> >               // enter all required fields
>> >
>> >               // set expected behavior on dao
>> >               context.checking(new Expectations() {
>> >                       {
>> >                               one(dao).save(with(same(surveyValue)));
>> >                       }
>> >               });
>> >
>> >               manager.save(surveyValue);
>> >       }
>> >
>> > Any ideas?
>> >
>> > PS: You should be able to reproduce the exception in the tutorial by
>> > overriding 'save' in  PersonManagerImpl.java (I have not tested it,
>> > sorry):
>> >
>> >         @Override
>> >       @Transactional
>> >       public Person save(Person person) {
>> >            return (Person) super.save(person);
>> >       }
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/ClassCastException-when-testing-overriden-save-method-in-*Manager-tp17748663s2369p17900484.html
>> Sent from the AppFuse - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
> 
> 

-- 
View this message in context: 
http://www.nabble.com/ClassCastException-when-testing-overriden-save-method-in-*Manager-tp17748663s2369p17960568.html
Sent from the AppFuse - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to