forked from mockito/mockito
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Harald Fassler <harald.fassler+9974@gmail.com>
- Loading branch information
1 parent
db0e6c0
commit cee40e0
Showing
1 changed file
with
84 additions
and
0 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
subprojects/junit-jupiter/src/test/java/org/mockitousage/regression/Regression3000Test.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,84 @@ | ||
package org.mockitousage.regression; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestInstance; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.Spy; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
@TestInstance(TestInstance.Lifecycle.PER_CLASS) | ||
@SuppressWarnings({ "unused", "rawtypes" }) | ||
public class Regression3000Test { | ||
|
||
@Target(ElementType.TYPE) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface Dependent { | ||
} | ||
|
||
@Target(ElementType.FIELD) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface Inject { | ||
} | ||
|
||
public interface Instance<T> { | ||
T get(); | ||
} | ||
|
||
public interface ObjectMapper { | ||
} | ||
|
||
public interface EntityManager { | ||
} | ||
|
||
public interface Storable<T> { | ||
} | ||
|
||
public interface StorageMessage { | ||
} | ||
|
||
public interface AbstractEntityController<T, U> { | ||
} | ||
|
||
public static class MessageControllerBase<T extends StorageMessage, U extends Storable> { | ||
} | ||
|
||
@Dependent | ||
public static class StorageMessageBaseController extends MessageControllerBase<StorageMessage, Storable> { | ||
|
||
@Inject | ||
Instance<AbstractEntityController<? extends Storable, ?>> controllerInstance; | ||
@Inject | ||
Instance<Storable<?>> storableInstance; | ||
@Inject | ||
ObjectMapper objectMapper; | ||
} | ||
|
||
@Mock | ||
Instance<Storable<?>> storableInstance; | ||
@Mock | ||
EntityManager em; | ||
@Spy | ||
@InjectMocks | ||
StorageMessageBaseController testee; | ||
|
||
/** | ||
* Verify regression <a href="https://github.com/mockito/mockito/issues/3000">issue #3000</a> is fixed. | ||
*/ | ||
@Test | ||
public void testNoArrayIndexOutOfBoundsExceptionAndMockInjected() { | ||
assertNotNull(testee); | ||
assertNotNull(testee.storableInstance); | ||
assertEquals(storableInstance, testee.storableInstance); | ||
} | ||
} |