Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@Mock and MockedConstruction #3289

Open
sergey-morenets opened this issue Mar 4, 2024 · 0 comments
Open

@Mock and MockedConstruction #3289

sergey-morenets opened this issue Mar 4, 2024 · 0 comments

Comments

@sergey-morenets
Copy link

Hi

I know that @mock and MockedStatic can be used together. However there's no mentioning in the official documentation about MockedConstruction injection via @mock.

Let's say I tried to inject that:

	@Mock
	MockedConstruction<DefaultOrderRepository> repository; 

DefaultOrderRepository is used in the OrderService:

@RequiredArgsConstructor
public class OrderService {
	
	private final OrderRepository orderRepository = new DefaultOrderRepository();
	
	public List<Order> findAll() {
		return orderRepository.findAll();
	}

And after that I tried to mock some of DefaultOrderRepository methods:

		OrderService service = new OrderService();
		DefaultOrderRepository repository2 = repository.constructed().get(0);
		when(repository2.findAll()).thenReturn(List.of());

and discovered that repository2 is not a mock but just a usual object. And when-thenReturn does nothing. So is this feature supported or not?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant