Issue #11 resolved

An ability to define a name of the original bean in @ReplaceWithMock and @WrapWithSpy

szpak
created an issue

It could be useful to have an optional property name ("beanName"?) in @ReplaceWithMock and @WrapWithSpy to determine a name of a bean which should be replaces/wrapped. This would allow to use other field names (e.g. fooMock, barSpy). By default (the property is not set) a field name should be used (to be backward compatible).

Comments (5)

  1. azerole

    I also vote for this improvement. With annotation-based bean configuration beans get name after class name by default, so if a service implements some interface and is named SomeVeryUsefulServiceImpl, then corresponding bean name will be "someVeryUsefulServiceImpl", so to replace it with a mock it would be necessary to use the following syntax:

    @ReplaceWithMock private SomeVeryUsefulService someVeryUsefulServiceImpl;

    Which is not nice. In fact Springockito could be improved in a more interesting way -- to have it infer bean name by its type.If it were done, then local variable name would no longer matter at all.

  2. Log in to comment