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.
JUnit support - disable observers declared on mocked beans
- also rename MockableProxy to Mockable and remove it from the public API - resolves quarkusio#11079
- Loading branch information
Showing
11 changed files
with
186 additions
and
27 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
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
13 changes: 0 additions & 13 deletions
13
independent-projects/arc/runtime/src/main/java/io/quarkus/arc/MockableProxy.java
This file was deleted.
Oops, something went wrong.
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
13 changes: 13 additions & 0 deletions
13
independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/Mockable.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,13 @@ | ||
package io.quarkus.arc.impl; | ||
|
||
/** | ||
* An interface implemented by mockable components when running in test mode. | ||
* <p> | ||
* This allows normal scoped beans to be easily mocked for tests. | ||
*/ | ||
public interface Mockable { | ||
|
||
void arc$setMock(Object instance); | ||
|
||
void arc$clearMock(); | ||
} |
20 changes: 20 additions & 0 deletions
20
integration-tests/injectmock/src/main/java/io/quarkus/it/mockbean/AlphaObserver.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,20 @@ | ||
package io.quarkus.it.mockbean; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.event.Observes; | ||
|
||
@ApplicationScoped | ||
public class AlphaObserver { | ||
|
||
boolean test() { | ||
return true; | ||
} | ||
|
||
void onBigDecimal(@Observes AtomicReference<BigDecimal> event) { | ||
event.set(event.get().add(BigDecimal.ONE)); | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
integration-tests/injectmock/src/main/java/io/quarkus/it/mockbean/BravoObserver.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,16 @@ | ||
package io.quarkus.it.mockbean; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.event.Observes; | ||
|
||
@ApplicationScoped | ||
public class BravoObserver { | ||
|
||
void onBigDecimal(@Observes AtomicReference<BigDecimal> event) { | ||
event.set(event.get().add(BigDecimal.ONE)); | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
integration-tests/injectmock/src/test/java/io/quarkus/it/mockbean/MockedObserverTest.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,37 @@ | ||
package io.quarkus.it.mockbean; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
|
||
import javax.enterprise.event.Event; | ||
import javax.inject.Inject; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.quarkus.test.junit.mockito.InjectMock; | ||
|
||
@QuarkusTest | ||
class MockedObserverTest { | ||
|
||
@InjectMock | ||
AlphaObserver observer; | ||
|
||
@Inject | ||
Event<AtomicReference<BigDecimal>> event; | ||
|
||
@Test | ||
public void testMockedObserverNotNotified() { | ||
Mockito.when(observer.test()).thenReturn(false); | ||
assertFalse(observer.test()); | ||
AtomicReference<BigDecimal> payload = new AtomicReference<BigDecimal>(BigDecimal.ZERO); | ||
event.fire(payload); | ||
// BravoObserver is not mocked | ||
assertEquals(BigDecimal.ONE, payload.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