forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request quarkusio#32949 from mkouba/issue-32944
InjectMock should not create a new contextual instance
- Loading branch information
Showing
6 changed files
with
93 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
integration-tests/injectmock/src/main/java/io/quarkus/it/mockbean/RequestScopedFoo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.quarkus.it.mockbean; | ||
|
||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
import jakarta.annotation.PostConstruct; | ||
import jakarta.enterprise.context.RequestScoped; | ||
|
||
import io.quarkus.arc.Unremovable; | ||
|
||
@Unremovable | ||
@RequestScoped | ||
public class RequestScopedFoo { | ||
|
||
static final AtomicBoolean CONSTRUCTED = new AtomicBoolean(); | ||
|
||
public String ping() { | ||
return "bar"; | ||
} | ||
|
||
@PostConstruct | ||
void init() { | ||
CONSTRUCTED.set(true); | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
...ation-tests/injectmock/src/test/java/io/quarkus/it/mockbean/RequestScopedFooMockTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.quarkus.it.mockbean; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.mockito.Mockito.when; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.quarkus.test.junit.mockito.InjectMock; | ||
|
||
@QuarkusTest | ||
class RequestScopedFooMockTest { | ||
|
||
@InjectMock | ||
RequestScopedFoo foo; | ||
|
||
@Test | ||
void testMock() { | ||
when(foo.ping()).thenReturn("pong"); | ||
assertEquals("pong", foo.ping()); | ||
assertFalse(RequestScopedFoo.CONSTRUCTED.get()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters