|
View:
New views
6 Messages
—
Rating Filter:
Alert me
|
|
|
[jira] Created: (JMOCK-201) Allow ClassImposteriser to be extendedAllow ClassImposteriser to be extended
-------------------------------------- Key: JMOCK-201 URL: http://jira.codehaus.org/browse/JMOCK-201 Project: jMock Issue Type: Improvement Components: Library Affects Versions: 2.5.1 Reporter: Corporate Gadfly I had a need to imposterise concrete classes (from 3rd-party jars) with final toString() method. For background, please see discussion at: http://www.nabble.com/Re%3A-mocking-concrete-classes-with-final-toString-method-p18509146.html In that thread, Nat had advised one of the options as being "write your own Imposteriser". So, for my needs I ended up writing ClassImposteriserAllowingFinalToString. It would be great if ClassImposteriser could be made easier to extend. As it is, it has a lot of private methods and properties and I pretty much had to rewrite my own imposteriser from scratch (essentially duplicating the private pieces of ClassImposteriser). If ClassImposteriser was extension friendly, I would probably need to do minimal work by writing my own imposterise() and canImposterise() methods. This way I would also be safeguarded against future bug-fixes that may happen in ClassImposteriser. Cheers and thanks in advance. -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
[jira] Updated: (JMOCK-201) Allow ClassImposteriser to be extended[ http://jira.codehaus.org/browse/JMOCK-201?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Corporate Gadfly updated JMOCK-201: ----------------------------------- Attachment: JMOCK-201.patch Patch against trunk allowing {{ClassImposteriser}} to be extended. > Allow ClassImposteriser to be extended > -------------------------------------- > > Key: JMOCK-201 > URL: http://jira.codehaus.org/browse/JMOCK-201 > Project: jMock > Issue Type: Improvement > Components: Library > Affects Versions: 2.5.1 > Reporter: Corporate Gadfly > Attachments: JMOCK-201.patch > > > I had a need to imposterise concrete classes (from 3rd-party jars) with final toString() method. > For background, please see discussion at: > http://www.nabble.com/Re%3A-mocking-concrete-classes-with-final-toString-method-p18509146.html > In that thread, Nat had advised one of the options as being "write your own Imposteriser". > So, for my needs I ended up writing ClassImposteriserAllowingFinalToString. It would be great if ClassImposteriser could be made easier to extend. As it is, it has a lot of private methods and properties and I pretty much had to rewrite my own imposteriser from scratch (essentially duplicating the private pieces of ClassImposteriser). If ClassImposteriser was extension friendly, I would probably need to do minimal work by writing my own imposterise() and canImposterise() methods. This way I would also be safeguarded against future bug-fixes that may happen in ClassImposteriser. > Cheers and thanks in advance. -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
[jira] Commented: (JMOCK-201) Allow ClassImposteriser to be extended[ http://jira.codehaus.org/browse/JMOCK-201?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=171138#action_171138 ] Nat Pryce commented on JMOCK-201: --------------------------------- That patch just makes all members protected. Making a class extensible needs a bit more design than that if it is going to be easy to maintain in the long run and ensure backward compatibility as we maintain it. What exactly do you need to change in the ClassImposteriser? Can that be done by passing policies to the ClassImposteriser instead of by inheritance? > Allow ClassImposteriser to be extended > -------------------------------------- > > Key: JMOCK-201 > URL: http://jira.codehaus.org/browse/JMOCK-201 > Project: jMock > Issue Type: Improvement > Components: Library > Affects Versions: 2.5.1 > Reporter: Corporate Gadfly > Attachments: JMOCK-201.patch > > > I had a need to imposterise concrete classes (from 3rd-party jars) with final toString() method. > For background, please see discussion at: > http://www.nabble.com/Re%3A-mocking-concrete-classes-with-final-toString-method-p18509146.html > In that thread, Nat had advised one of the options as being "write your own Imposteriser". > So, for my needs I ended up writing ClassImposteriserAllowingFinalToString. It would be great if ClassImposteriser could be made easier to extend. As it is, it has a lot of private methods and properties and I pretty much had to rewrite my own imposteriser from scratch (essentially duplicating the private pieces of ClassImposteriser). If ClassImposteriser was extension friendly, I would probably need to do minimal work by writing my own imposterise() and canImposterise() methods. This way I would also be safeguarded against future bug-fixes that may happen in ClassImposteriser. > Cheers and thanks in advance. -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
[jira] Commented: (JMOCK-201) Allow ClassImposteriser to be extended[ http://jira.codehaus.org/browse/JMOCK-201?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=171198#action_171198 ] Corporate Gadfly commented on JMOCK-201: ---------------------------------------- Hi Nat, I needed to override the methods canImposterise() and imposterise(). Here is my canImposterise() method: {code:title=Mine} public boolean canImposterise(Class<?> type) { return !type.isPrimitive() && !Modifier.isFinal(type.getModifiers()) && type.isInterface(); } {code} as compared to the original: {code:title=Original} public boolean canImposterise(Class<?> type) { return !type.isPrimitive() && !Modifier.isFinal(type.getModifiers()) && (type.isInterface() || !toStringMethodIsFinal(type)); } {code} Notice the extra call to toStringMethodIsFinal. So overriding this one is easy. When I tried to override the imposterise() method, it had calls to private methods. Here's mine: {code:title=Mine} public <T> T imposterise(final Invokable mockObject, Class<T> mockedType, Class<?>... ancilliaryTypes) { try { setConstructorsAccessible(mockedType, true); Class<?> proxyClass = createProxyClass(mockedType, ancilliaryTypes); return mockedType.cast(createProxy(proxyClass, mockObject)); } finally { setConstructorsAccessible(mockedType, false); } } {code} compared to original: {code:title=Original} 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); } } {code} Overriding this one was a little bit more difficult as it has calls to 3 private methods (createProxyClass, createProxy, setConstructorsAccessible). Hope the situation is a little bit clearer. > Allow ClassImposteriser to be extended > -------------------------------------- > > Key: JMOCK-201 > URL: http://jira.codehaus.org/browse/JMOCK-201 > Project: jMock > Issue Type: Improvement > Components: Library > Affects Versions: 2.5.1 > Reporter: Corporate Gadfly > Attachments: JMOCK-201.patch > > > I had a need to imposterise concrete classes (from 3rd-party jars) with final toString() method. > For background, please see discussion at: > http://www.nabble.com/Re%3A-mocking-concrete-classes-with-final-toString-method-p18509146.html > In that thread, Nat had advised one of the options as being "write your own Imposteriser". > So, for my needs I ended up writing ClassImposteriserAllowingFinalToString. It would be great if ClassImposteriser could be made easier to extend. As it is, it has a lot of private methods and properties and I pretty much had to rewrite my own imposteriser from scratch (essentially duplicating the private pieces of ClassImposteriser). If ClassImposteriser was extension friendly, I would probably need to do minimal work by writing my own imposterise() and canImposterise() methods. This way I would also be safeguarded against future bug-fixes that may happen in ClassImposteriser. > Cheers and thanks in advance. -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
[jira] Commented: (JMOCK-201) Allow ClassImposteriser to be extended[ http://jira.codehaus.org/browse/JMOCK-201?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=171277#action_171277 ] Nat Pryce commented on JMOCK-201: --------------------------------- So the only thing you need to change is the check for final toString methods, is that right? > Allow ClassImposteriser to be extended > -------------------------------------- > > Key: JMOCK-201 > URL: http://jira.codehaus.org/browse/JMOCK-201 > Project: jMock > Issue Type: Improvement > Components: Library > Affects Versions: 2.5.1 > Reporter: Corporate Gadfly > Attachments: JMOCK-201.patch > > > I had a need to imposterise concrete classes (from 3rd-party jars) with final toString() method. > For background, please see discussion at: > http://www.nabble.com/Re%3A-mocking-concrete-classes-with-final-toString-method-p18509146.html > In that thread, Nat had advised one of the options as being "write your own Imposteriser". > So, for my needs I ended up writing ClassImposteriserAllowingFinalToString. It would be great if ClassImposteriser could be made easier to extend. As it is, it has a lot of private methods and properties and I pretty much had to rewrite my own imposteriser from scratch (essentially duplicating the private pieces of ClassImposteriser). If ClassImposteriser was extension friendly, I would probably need to do minimal work by writing my own imposterise() and canImposterise() methods. This way I would also be safeguarded against future bug-fixes that may happen in ClassImposteriser. > Cheers and thanks in advance. -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
[jira] Commented: (JMOCK-201) Allow ClassImposteriser to be extended[ http://jira.codehaus.org/browse/JMOCK-201?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=171298#action_171298 ] Corporate Gadfly commented on JMOCK-201: ---------------------------------------- That's correct. > Allow ClassImposteriser to be extended > -------------------------------------- > > Key: JMOCK-201 > URL: http://jira.codehaus.org/browse/JMOCK-201 > Project: jMock > Issue Type: Improvement > Components: Library > Affects Versions: 2.5.1 > Reporter: Corporate Gadfly > Attachments: JMOCK-201.patch > > > I had a need to imposterise concrete classes (from 3rd-party jars) with final toString() method. > For background, please see discussion at: > http://www.nabble.com/Re%3A-mocking-concrete-classes-with-final-toString-method-p18509146.html > In that thread, Nat had advised one of the options as being "write your own Imposteriser". > So, for my needs I ended up writing ClassImposteriserAllowingFinalToString. It would be great if ClassImposteriser could be made easier to extend. As it is, it has a lot of private methods and properties and I pretty much had to rewrite my own imposteriser from scratch (essentially duplicating the private pieces of ClassImposteriser). If ClassImposteriser was extension friendly, I would probably need to do minimal work by writing my own imposterise() and canImposterise() methods. This way I would also be safeguarded against future bug-fixes that may happen in ClassImposteriser. > Cheers and thanks in advance. -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
| Free embeddable forum powered by Nabble | Forum Help |