EasyMock

Bridge methods are always mocked, regardless of partial mock

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 3.0
  • Fix Version/s: 3.1
  • Component/s: Class Extension
  • Labels:
    None

Description

EasyMock bridge method handling is wrong. It always forwards the invocation against a bridge method to the mock interceptor. For partial mocks, this is undesirable.

The following test case reproduces the bug (also included in the patch):

static abstract class GenericHolder<T> {
abstract void set(T value);

final void go(final T value) { set(value); }
}

static class StringHolder extends GenericHolder<String> {
String value;

@Override
void set(final String value) { this.value = value; }
}

@Test
public void testBridgeMethod() { final StringHolder holder = EasyMock.createMock(StringHolder.class, new Method[0]); holder.go("hello"); Assert.assertEquals("hello", holder.value); }

Cglib's CallbackFilter can already filter out all bridge methods so that they follow the original dispatching.
Attached patch (against the svn trunk) removes BridgeMethodResolver and uses cglib's CallbackFilter to handle bridge methods properly.

Activity

Hide
Henri Tremblay added a comment -

I couldn't apply the patch because of a failing test in one case. Seems to be a cglib issue. It doesn't call the interceptor of a bridge method in the particular case of a package scope bridge (see GenericTest)

Show
Henri Tremblay added a comment - I couldn't apply the patch because of a failing test in one case. Seems to be a cglib issue. It doesn't call the interceptor of a bridge method in the particular case of a package scope bridge (see GenericTest)

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: