forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use single mock when backing bean is the same instance
Fixes: quarkusio#15411
- Loading branch information
Showing
4 changed files
with
130 additions
and
5 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
integration-tests/injectmock/src/main/java/io/quarkus/it/mockbean/SameBeanInstance.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,63 @@ | ||
package io.quarkus.it.mockbean; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.inject.Inject; | ||
|
||
public class SameBeanInstance { | ||
|
||
public interface UnderTest { | ||
void method1(); | ||
} | ||
|
||
public interface I3 { | ||
void method3(); | ||
} | ||
|
||
public interface I2 { | ||
void method2(); | ||
} | ||
|
||
public interface I4 { | ||
void method4(); | ||
} | ||
|
||
@ApplicationScoped | ||
public static class C1 implements UnderTest { | ||
@Inject | ||
I2 i2; | ||
|
||
@Inject | ||
I3 i3; | ||
|
||
@Inject | ||
I4 i4; | ||
|
||
@Override | ||
public void method1() { | ||
i2.method2(); | ||
i3.method3(); | ||
} | ||
} | ||
|
||
@ApplicationScoped | ||
public static class C2 implements I2, I3 { | ||
@Override | ||
public void method2() { | ||
|
||
} | ||
|
||
@Override | ||
public void method3() { | ||
|
||
} | ||
} | ||
|
||
@ApplicationScoped | ||
public static class C3 implements I4 { | ||
|
||
@Override | ||
public void method4() { | ||
|
||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
integration-tests/injectmock/src/test/java/io/quarkus/it/mockbean/SameBeanInstanceTest.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,35 @@ | ||
package io.quarkus.it.mockbean; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.quarkus.test.junit.mockito.InjectMock; | ||
|
||
@QuarkusTest | ||
public class SameBeanInstanceTest { | ||
|
||
@Inject | ||
SameBeanInstance.UnderTest underTest; | ||
|
||
@InjectMock | ||
SameBeanInstance.I2 i2; | ||
|
||
@InjectMock | ||
SameBeanInstance.I3 i3; | ||
|
||
@InjectMock | ||
SameBeanInstance.I4 i4; | ||
|
||
@Test | ||
public void sample() { | ||
underTest.method1(); | ||
|
||
verify(i2).method2(); | ||
verify(i3).method3(); | ||
verify(i4, never()).method4(); | ||
} | ||
} |
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