这是indexloc提供的服务,不要输入任何密码
Skip to content

Allow @Mock to get a default name from the variable being mocked #260

@sazzer

Description

@sazzer

Currently, if I'm using EasyMockRunner / EasyMockRule and the @Mock annotation, I have the choice of using @Mock(name = "xxx") or else having an unnamed mock.

This works, but it means that if I'm mocking two different fields with the same type then I have to explicitly give them names or else the logs get confusing.

It would be relatively easy for this to instead use the field name as the default name for the mock, so that the only time you need to specify the name="xxx" is if you actually want a different value - which is probably rare.

Effectively it means that:

@Mock(name = "mockService")
private Service mockService;

just becomes:

@Mock
private Service mockService;

but still does the exact same thing.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions