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.
Allows Spies with @Injectmocks to be injected into other @Injectmocks
- Loading branch information
Showing
29 changed files
with
1,866 additions
and
515 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
27 changes: 27 additions & 0 deletions
27
.../java/org/mockito/internal/configuration/injection/LenientPropertyAndSetterInjection.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,27 @@ | ||
/* | ||
* Copyright (c) 2019 Mockito contributors | ||
* This program is made available under the terms of the MIT License. | ||
*/ | ||
package org.mockito.internal.configuration.injection; | ||
|
||
import org.mockito.internal.util.reflection.ConstructorResolver; | ||
import org.mockito.internal.util.reflection.ConstructorResolver.LenientNoArgsConstructorResolver; | ||
|
||
/** | ||
* Inject mocks using setters then fields, if no setters available, see | ||
* {@link PropertyAndSetterInjection parent class} for more information on algorithm. | ||
* <p> | ||
* The strategy to instantiate field (if needed) is to try to find no-args constructor on field type | ||
* and skip the field otherwise. | ||
* </p> | ||
* | ||
* @see org.mockito.internal.configuration.injection.PropertyAndSetterInjection | ||
*/ | ||
public class LenientPropertyAndSetterInjection extends PropertyAndSetterInjection { | ||
|
||
@Override | ||
protected ConstructorResolver createConstructorResolver(Class<?> fieldType) { | ||
return new LenientNoArgsConstructorResolver(fieldType); | ||
} | ||
|
||
} |
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
26 changes: 26 additions & 0 deletions
26
src/main/java/org/mockito/internal/configuration/injection/StrictConstructorInjection.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 @@ | ||
/* | ||
* Copyright (c) 2020 Mockito contributors | ||
* This program is made available under the terms of the MIT License. | ||
*/ | ||
package org.mockito.internal.configuration.injection; | ||
|
||
import java.util.Set; | ||
|
||
import org.mockito.internal.util.reflection.ConstructorResolver; | ||
import org.mockito.internal.util.reflection.ConstructorResolver.StrictBiggestConstructorResolver; | ||
|
||
/** | ||
* Injection strategy based on constructor. | ||
* <p> | ||
* The strategy will search for the constructor with most parameters and try to resolve mocks by | ||
* type or skip the field if there is no mocks matching a parameter. | ||
* </p> | ||
*/ | ||
public class StrictConstructorInjection extends ConstructorInjection { | ||
|
||
@Override | ||
protected ConstructorResolver createConstructorResolver(Class<?> fieldType, Set<Object> mockCandidates) { | ||
return new StrictBiggestConstructorResolver(fieldType, mockCandidates); | ||
} | ||
|
||
} |
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
Oops, something went wrong.