Skip to content

Create an AspectJ Proxy wrapper #18

Description

@samuelgrigolato

Commit a6181d7 clearly shows the burden one has to face when trying to use this library outside a Spring Context test environment.

I think we can ease this process by providing this block of code as an API method with appropriate documentation for its usage:

AspectJProxyFactory componentFactory = new AspectJProxyFactory(component);
componentFactory.addAspect(aspect);
component = componentFactory.getProxy();

Example:

@InjectMocks private MyComponent component;
@InjectMocks private MyService service;
@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    component = ServiceValidationWrapper.wrap(component);
    service = ServiceValidationWrapper.wrap(service);
}

An even simpler case would be (I think we can support both scenarios):

private MyComponent component;
private MyService service;
@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    component = ServiceValidationWrapper.wrap(MyComponent.class);
    service = ServiceValidationWrapper.wrap(MyService.class);
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions