From f49a40e0ffb6de4e13457b128d63857b72e45f88 Mon Sep 17 00:00:00 2001 From: Kaushal Rohit Date: Sun, 16 Aug 2020 19:46:37 +0530 Subject: [PATCH 1/2] Added Factory Replacement to Mockito Mocks --- src/main/docs/guide/junit5.adoc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/docs/guide/junit5.adoc b/src/main/docs/guide/junit5.adoc index 3ae9f676b..40cc53305 100644 --- a/src/main/docs/guide/junit5.adoc +++ b/src/main/docs/guide/junit5.adoc @@ -155,6 +155,8 @@ include::{junit5tests}/MathCollaboratorTest.java[] The way this works is that `@MicronautTest` will inject the `Mock(..)` instance into the test, but the controller will have a proxy that points to the `Mock(..)` instance injected. For each iteration of the test the mock is refreshed (in fact it uses Micronaut's built in `RefreshScope`). +For Factory injected beans, we can use Factory Replacement to inject Mocks. Refer https://docs.micronaut.io/latest/guide/ioc.html#_factory_replacement[Factory Replacement]. + === Using `@Requires` on Tests Since `@MicronautTest` turns tests into beans themselves, it means you can use the `@Requires` annotation on the test to enable/disable tests. For example: @@ -223,4 +225,4 @@ For example: [source,java] ---- include::{junit5tests}/PropertyValueRequiresTest.java[] ----- \ No newline at end of file +---- From 32b4c199916c533e50ce2b16164a09b1edc70b09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20S=C3=A1nchez-Mariscal?= Date: Tue, 18 Aug 2020 10:04:02 +0200 Subject: [PATCH 2/2] Update junit5.adoc --- src/main/docs/guide/junit5.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/docs/guide/junit5.adoc b/src/main/docs/guide/junit5.adoc index 40cc53305..f3bf44c1c 100644 --- a/src/main/docs/guide/junit5.adoc +++ b/src/main/docs/guide/junit5.adoc @@ -155,7 +155,7 @@ include::{junit5tests}/MathCollaboratorTest.java[] The way this works is that `@MicronautTest` will inject the `Mock(..)` instance into the test, but the controller will have a proxy that points to the `Mock(..)` instance injected. For each iteration of the test the mock is refreshed (in fact it uses Micronaut's built in `RefreshScope`). -For Factory injected beans, we can use Factory Replacement to inject Mocks. Refer https://docs.micronaut.io/latest/guide/ioc.html#_factory_replacement[Factory Replacement]. +For Factory injected beans, you can use Factory Replacement to inject Mocks. Refer to the https://docs.micronaut.io/latest/guide/index.html#_factory_replacement[factory replacement documentation] for more information. === Using `@Requires` on Tests