1616
1717import static org .assertj .core .api .Assertions .assertThat ;
1818import static org .junit .jupiter .api .Assertions .assertNotNull ;
19+ import static org .mockito .Mockito .mock ;
20+ import static org .mockito .Mockito .when ;
1921
22+ import java .io .InputStream ;
23+ import java .io .OutputStream ;
2024import java .util .Optional ;
2125
2226import org .aspectj .lang .ProceedingJoinPoint ;
27+ import org .aspectj .lang .Signature ;
2328import org .junit .jupiter .api .Test ;
2429import org .junitpioneer .jupiter .ClearEnvironmentVariable ;
2530import org .junitpioneer .jupiter .SetEnvironmentVariable ;
2934import com .amazonaws .services .lambda .runtime .RequestStreamHandler ;
3035
3136import software .amazon .lambda .powertools .common .stubs .TestLambdaContext ;
32- import software .amazon .lambda .powertools .common .stubs .TestInputStream ;
33- import software .amazon .lambda .powertools .common .stubs .TestOutputStream ;
34- import software .amazon .lambda .powertools .common .stubs .TestProceedingJoinPoint ;
35- import software .amazon .lambda .powertools .common .stubs .TestSignature ;
3637
3738class LambdaHandlerProcessorTest {
3839
@@ -47,7 +48,7 @@ void isHandlerMethod_shouldRecognizeRequestHandler() {
4748
4849 @ Test
4950 void isHandlerMethod_shouldRecognizeRequestStreamHandler () {
50- Object [] args = { new TestInputStream ( ), new TestOutputStream ( ), new TestLambdaContext () };
51+ Object [] args = { mock ( InputStream . class ), mock ( OutputStream . class ), new TestLambdaContext () };
5152 ProceedingJoinPoint pjpMock = mockRequestHandlerPjp (RequestStreamHandler .class , args );
5253
5354 assertThat (LambdaHandlerProcessor .isHandlerMethod (pjpMock )).isTrue ();
@@ -72,7 +73,7 @@ void placedOnRequestHandler_shouldRecognizeRequestHandler() {
7273
7374 @ Test
7475 void placedOnStreamHandler_shouldRecognizeRequestStreamHandler () {
75- Object [] args = { new TestInputStream ( ), new TestOutputStream ( ), new TestLambdaContext () };
76+ Object [] args = { mock ( InputStream . class ), mock ( OutputStream . class ), new TestLambdaContext () };
7677 ProceedingJoinPoint pjpMock = mockRequestHandlerPjp (RequestStreamHandler .class , args );
7778
7879 assertThat (LambdaHandlerProcessor .placedOnStreamHandler (pjpMock )).isTrue ();
@@ -120,7 +121,7 @@ void placedOnStreamHandler_shouldInvalidateOnWrongTypeOfArgs() {
120121
121122 @ Test
122123 void placedOnStreamHandler_shouldInvalidateOnTypeOfArgs_invalidOutputStreamArg () {
123- Object [] args = { new TestInputStream ( ), new Object (), new TestLambdaContext () };
124+ Object [] args = { mock ( InputStream . class ), new Object (), new TestLambdaContext () };
124125 ProceedingJoinPoint pjpMock = mockRequestHandlerPjp (RequestStreamHandler .class , args );
125126
126127 boolean isPlacedOnStreamHandler = LambdaHandlerProcessor .placedOnStreamHandler (pjpMock );
@@ -130,7 +131,7 @@ void placedOnStreamHandler_shouldInvalidateOnTypeOfArgs_invalidOutputStreamArg()
130131
131132 @ Test
132133 void placedOnStreamHandler_shouldInvalidateOnTypeOfArgs_invalidContextArg () {
133- Object [] args = { new TestInputStream ( ), new TestOutputStream ( ), new Object () };
134+ Object [] args = { mock ( InputStream . class ), mock ( OutputStream . class ), new Object () };
134135 ProceedingJoinPoint pjpMock = mockRequestHandlerPjp (RequestStreamHandler .class , args );
135136
136137 boolean isPlacedOnStreamHandler = LambdaHandlerProcessor .placedOnStreamHandler (pjpMock );
@@ -170,7 +171,7 @@ void extractContext_fromRequestHandler() {
170171
171172 @ Test
172173 void extractContext_fromStreamRequestHandler () {
173- Object [] args = { new TestInputStream ( ), new TestOutputStream ( ), new TestLambdaContext () };
174+ Object [] args = { mock ( InputStream . class ), mock ( OutputStream . class ), new TestLambdaContext () };
174175 ProceedingJoinPoint pjpMock = mockRequestHandlerPjp (RequestStreamHandler .class , args );
175176
176177 Context context = LambdaHandlerProcessor .extractContext (pjpMock );
@@ -230,7 +231,14 @@ void serviceName_Undefined() {
230231 }
231232
232233 private ProceedingJoinPoint mockRequestHandlerPjp (Class <?> handlerClass , Object [] handlerArgs ) {
233- TestSignature signature = new TestSignature (handlerClass );
234- return new TestProceedingJoinPoint (signature , handlerArgs );
234+ ProceedingJoinPoint pjp = mock (ProceedingJoinPoint .class );
235+ Signature signature = mock (Signature .class );
236+
237+ when (signature .getDeclaringType ()).thenReturn (handlerClass );
238+ when (signature .getName ()).thenReturn ("handleRequest" );
239+ when (pjp .getSignature ()).thenReturn (signature );
240+ when (pjp .getArgs ()).thenReturn (handlerArgs );
241+
242+ return pjp ;
235243 }
236244}
0 commit comments