File tree Expand file tree Collapse file tree 2 files changed +37
-2
lines changed
main/java/org/mockito/internal/creation/bytebuddy
test/java/org/mockito/internal/creation/bytebuddy Expand file tree Collapse file tree 2 files changed +37
-2
lines changed Original file line number Diff line number Diff line change 4
4
*/
5
5
package org .mockito .internal .creation .bytebuddy ;
6
6
7
+ import static net .bytebuddy .matcher .ElementMatchers .isAccessibleTo ;
7
8
import static net .bytebuddy .matcher .ElementMatchers .isConstructor ;
8
- import static net .bytebuddy .matcher .ElementMatchers .isPrivate ;
9
9
import static net .bytebuddy .matcher .ElementMatchers .isStatic ;
10
10
import static net .bytebuddy .matcher .ElementMatchers .not ;
11
11
@@ -398,7 +398,7 @@ public MethodVisitor wrap(
398
398
.getSuperClass ()
399
399
.asErasure ()
400
400
.getDeclaredMethods ()
401
- .filter (isConstructor ().and (not ( isPrivate () )));
401
+ .filter (isConstructor ().and (isAccessibleTo ( instrumentedType )));
402
402
int arguments = Integer .MAX_VALUE ;
403
403
boolean packagePrivate = true ;
404
404
MethodDescription .InDefinedShape current = null ;
Original file line number Diff line number Diff line change @@ -80,6 +80,22 @@ public void should_create_mock_from_final_spy() throws Exception {
80
80
});
81
81
}
82
82
83
+ @ Test
84
+ public void should_create_mock_from_accessible_inner_spy () throws Exception {
85
+ MockCreationSettings <Outer .Inner > settings = settingsFor (Outer .Inner .class );
86
+ Optional <Outer .Inner > proxy =
87
+ mockMaker .createSpy (
88
+ settings ,
89
+ new MockHandlerImpl <>(settings ),
90
+ new Outer .Inner (new Object (), new Object ()));
91
+ assertThat (proxy )
92
+ .hasValueSatisfying (
93
+ spy -> {
94
+ assertThat (spy .p1 ).isNotNull ();
95
+ assertThat (spy .p2 ).isNotNull ();
96
+ });
97
+ }
98
+
83
99
@ Test
84
100
public void should_create_mock_from_non_constructable_class () throws Exception {
85
101
MockCreationSettings <NonConstructableClass > settings =
@@ -646,4 +662,23 @@ void internalThrowException(int test) throws IOException {
646
662
}
647
663
}
648
664
}
665
+
666
+ static class Outer {
667
+
668
+ final Object p1 ;
669
+
670
+ private Outer (final Object p1 ) {
671
+ this .p1 = p1 ;
672
+ }
673
+
674
+ private static class Inner extends Outer {
675
+
676
+ final Object p2 ;
677
+
678
+ Inner (final Object p1 , final Object p2 ) {
679
+ super (p1 );
680
+ this .p2 = p2 ;
681
+ }
682
+ }
683
+ }
649
684
}
You can’t perform that action at this time.
0 commit comments