Share

Mock Objects

Tracker: Patches

5 Patch to allow mocking of any non-final class - ID: 761544
Last Update: Comment added ( danshep )

The Proxy from cglib.sourceforge.net is a drop-in
replacement for the java.lang.reflect.Proxy class with
two important extra features:
- It can proxy concrete classes, not just interfaces.
- It can operate under JDK 1.2.2

The attached patch replaces references to the reflect
Proxy with the cglib Proxy.

This does add extra dependencies to mockobjects, in the
form of cglib and the underlying asm code.

CGLib is released under the Apache License. It's
available from http://cglib.sourceforge.net/

ASM is released under LGPL. It's available from
http://asm.objectweb.org/


Daniel Sheppard ( danshep ) - 2003-06-27 00:13

5

Open

Later

Nobody/Anonymous

None

None

Public


Comments ( 9 )




Date: 2003-09-09 01:08
Sender: danshep

Logged In: YES
user_id=694803

It's been two months since the last update on this. Any
progress? Do you want a patch made up against the current cvs?


Date: 2003-07-09 23:44
Sender: smgfProject Admin

Logged In: YES
user_id=123464

we would like to do this, but the dynamic mocks are a bit of
a moving target right now. As soon as we can, we'll get back
to this patch.

Steve


Date: 2003-07-09 20:08
Sender: steve_molitor

Logged In: YES
user_id=646960

I just did essentially the same patch using CGLib; glad I
checked here first before submitting it! I really hope this
patch gets submitted; it's extremely handy.

Depending on an external library doesn't seem like that big of
a deal to me. (Reuse is good!) But even if the reflection
option has to be used to load CGLib, I sure hope this patch
gets included!







Date: 2003-07-07 08:16
Sender: danshep

Logged In: YES
user_id=694803

Appears the file didn't go through last time.

Fixed it up to match current cvs. Enjoy.

There's still going to be compile-time dependencies on
cglib. Is this a problem? I could probably do some dodgy
work with reflection to make that go away. I could also make
it driven by a system property, but I think that'd just
confuse users.


Date: 2003-07-07 08:14
Sender: danshep

Logged In: YES
user_id=694803

Hmmm... seems the file didn't attach last time. I've updated
it to match the latest cvs now.

There's going to be a compile-time dependency on cglib for
core as it stands.

Options for removing that are:
- Make the cglib proxy implementation an extension and
trigger it using a system property. I don't want to do this,
as it makes it pretty hard for people to use.
- Make the calling to Proxy happen via reflection. Slower,
seems a bit silly, but it'd work.
- ???


Date: 2003-07-02 07:51
Sender: danshep

Logged In: YES
user_id=694803

It's a bit rushed and messy, but heres another patch that
will use CgLib if available, otherwise it'll fall back on
the java.reflect code.



Date: 2003-07-02 04:15
Sender: danshep

Logged In: YES
user_id=694803

If you really wanted to have no external dependencies, you
COULD inline the cglib code, but I'd advise against it.

It would be fairly simple to abstract away which proxy you
are using. If you want I can whip up another patch that
selects cglib if it is available and otherwise falls back on
the java.lang.reflect proxy.


Date: 2003-07-02 04:12
Sender: danshep

Logged In: YES
user_id=694803

CGLib comes in an ASM or BCEL version - I'm not sure if it's
switchable... I'm pretty sure they just removed BCEL support
and replaced it with ASM. Abstracting away the library that
is extracting away the bytecode for you wouldn't be a cup of
tea.

Oops - I was wrong -just looked through the sourcecode, and
it looks like it detects whichever one is available
(favouring ASM).

You'd be putting a dependency on cglib - with the option to
depend on either ASM of BCEL.




Date: 2003-07-02 03:51
Sender: smgfProject Admin

Logged In: YES
user_id=123464

This is interesting. We've discussed using bcel to do this,
but I'm wary of adding dependencies. At present, the core
library is completely independant. Maybe we could provide a
hook for multiple implementations.


Log in to comment.




Attached Files ( 2 )

Filename Description Download
cglib-patch2.txt Patch to OPTIONALLY use the cglib proxy Download
cglib-patch.txt Patch to use the cglib proxy Download

Changes ( 6 )

Field Old Value Date By
File Added 55118: cglib-patch2.txt 2003-07-07 08:16 danshep
status_id Pending 2003-07-02 04:12 danshep
status_id Open 2003-07-02 03:51 smgf
resolution_id None 2003-07-02 03:51 smgf
close_date - 2003-07-02 03:51 smgf
File Added 54230: cglib-patch.txt 2003-06-27 00:13 danshep