-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add test for generics field usage of @InjectMock
- Loading branch information
Showing
4 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
integration-tests/injectmock/src/test/java/io/quarkus/it/mockbean/GenericFieldsTest.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,30 @@ | ||
package io.quarkus.it.mockbean; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.quarkus.test.junit.mockito.InjectMock; | ||
|
||
@QuarkusTest | ||
public class GenericFieldsTest { | ||
|
||
@Inject | ||
MyContainerConsumer myContainerConsumer; | ||
|
||
@InjectMock | ||
MyContainer<String> stringContainer; | ||
|
||
@InjectMock | ||
MyContainer<Integer> integerContainer; | ||
|
||
@Test | ||
public void test() { | ||
Mockito.when(stringContainer.getValue()).thenReturn("hi"); | ||
Mockito.when(integerContainer.getValue()).thenReturn(2); | ||
Assertions.assertEquals("hi hi", myContainerConsumer.createString()); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
integration-tests/injectmock/src/test/java/io/quarkus/it/mockbean/MyContainer.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,6 @@ | ||
package io.quarkus.it.mockbean; | ||
|
||
public interface MyContainer<T> { | ||
|
||
T getValue(); | ||
} |
26 changes: 26 additions & 0 deletions
26
integration-tests/injectmock/src/test/java/io/quarkus/it/mockbean/MyContainerConsumer.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,26 @@ | ||
package io.quarkus.it.mockbean; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import javax.inject.Singleton; | ||
|
||
@Singleton | ||
public class MyContainerConsumer { | ||
|
||
private final MyContainer<String> stringContainer; | ||
private final MyContainer<Integer> integerContainer; | ||
|
||
public MyContainerConsumer(MyContainer<String> stringContainer, MyContainer<Integer> integerContainer) { | ||
this.stringContainer = stringContainer; | ||
this.integerContainer = integerContainer; | ||
} | ||
|
||
public String createString() { | ||
List<String> strings = new ArrayList<>(integerContainer.getValue()); | ||
for (int i = 0; i < integerContainer.getValue(); i++) { | ||
strings.add(stringContainer.getValue()); | ||
} | ||
return String.join(" ", strings); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
integration-tests/injectmock/src/test/java/io/quarkus/it/mockbean/MyContainerProducer.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,31 @@ | ||
package io.quarkus.it.mockbean; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.inject.Singleton; | ||
import javax.ws.rs.Produces; | ||
|
||
@Singleton | ||
public class MyContainerProducer { | ||
|
||
@ApplicationScoped | ||
@Produces | ||
public MyContainer<String> stringContainer() { | ||
return new MyContainer<>() { | ||
@Override | ||
public String getValue() { | ||
return "hello"; | ||
} | ||
}; | ||
} | ||
|
||
@ApplicationScoped | ||
@Produces | ||
public MyContainer<Integer> integerContainer() { | ||
return new MyContainer<>() { | ||
@Override | ||
public Integer getValue() { | ||
return 1; | ||
} | ||
}; | ||
} | ||
} |