@@ -123,7 +123,8 @@ public class RestServicesConvertPdfServiceAdapterTest {
123123// private static final MediaType APPLICATION_PS = new MediaType("application", "postscript");
124124
125125 @ Mock (stubOnly = true ) RestClientFactory mockClientFactory ;
126- @ Mock (stubOnly = true ) RestClient mockClient ;
126+ @ Mock (stubOnly = true ) RestClient mockClientToImage ;
127+ @ Mock (stubOnly = true ) RestClient mockClientToPs ;
127128 @ Mock (stubOnly = true ) MultipartPayload mockPayload ;
128129 @ Mock (stubOnly = true ) MultipartPayload .Builder mockPayloadBuilder ;
129130 @ Mock (stubOnly = true ) Response mockResponse ;
@@ -137,7 +138,8 @@ public class RestServicesConvertPdfServiceAdapterTest {
137138
138139 @ BeforeEach
139140 void setUp () throws Exception {
140- when (mockClientFactory .apply (aemConfig .capture (), servicePath .capture (), correlationIdFn .capture ())).thenReturn (mockClient );
141+ when (mockClientFactory .apply (aemConfig .capture (), Mockito .contains ("ToImage" ), correlationIdFn .capture ())).thenReturn (mockClientToImage );
142+ when (mockClientFactory .apply (aemConfig .capture (), Mockito .contains ("ToPS" ), correlationIdFn .capture ())).thenReturn (mockClientToPs );
141143 }
142144
143145 @ Test
@@ -167,7 +169,7 @@ void testToPS_NullArguments() throws Exception {
167169 @ Test
168170 void testToImage_HappyPath () throws Exception {
169171 byte [] responseData = "response Document Data" .getBytes ();
170- setupMocks (setupMockResponse (responseData , ContentType .IMAGE_JPEG ));
172+ setupMocks (mockClientToImage , setupMockResponse (responseData , ContentType .IMAGE_JPEG ));
171173
172174 RestServicesConvertPdfServiceAdapter underTest = createAdapter (mockClientFactory );
173175
@@ -240,7 +242,7 @@ void testToImage_RestClientException() throws Exception {
240242 var underTest = createAdapter (mockClientFactory );
241243 when (toImageOptionsSpec .getImageConvertFormat ()).thenReturn (ImageConvertFormat .TIFF );
242244
243- var ex = mockForException (cause , ()->underTest .toImage (DUMMY_PDF , toImageOptionsSpec ));
245+ var ex = mockForException (mockClientToImage , cause , ()->underTest .toImage (DUMMY_PDF , toImageOptionsSpec ));
244246
245247 assertThat (ex , allOf (ExceptionMatchers .exceptionMsgContainsAll ("Error while POSTing to server" ),
246248 ExceptionMatchers .hasCause (cause )
@@ -255,7 +257,7 @@ void testToImage_IOException() throws Exception {
255257 var underTest = createAdapter (mockClientFactory );
256258 when (toImageOptionsSpec .getImageConvertFormat ()).thenReturn (ImageConvertFormat .PNG );
257259
258- var ex = mockForException (cause , ()->underTest .toImage (DUMMY_PDF , toImageOptionsSpec ));
260+ var ex = mockForException (mockClientToImage , cause , ()->underTest .toImage (DUMMY_PDF , toImageOptionsSpec ));
259261
260262 assertThat (ex , allOf (ExceptionMatchers .exceptionMsgContainsAll ("I/O Error while securing document" ),
261263 ExceptionMatchers .hasCause (cause )
@@ -265,7 +267,7 @@ void testToImage_IOException() throws Exception {
265267 @ Test
266268 void testToPS_HappyPath () throws Exception {
267269 byte [] responseData = "response Document Data" .getBytes ();
268- setupMocks (setupMockResponse (responseData , ContentType .APPLICATION_PS ));
270+ setupMocks (mockClientToPs , setupMockResponse (responseData , ContentType .APPLICATION_PS ));
269271
270272 RestServicesConvertPdfServiceAdapter underTest = createAdapter (mockClientFactory );
271273
@@ -347,7 +349,7 @@ void testToPS_RestClientException() throws Exception {
347349 var toPSOptionsSpec = Mockito .mock (ToPSOptionsSpec .class );
348350 var underTest = createAdapter (mockClientFactory );
349351
350- var ex = mockForException (cause , ()->underTest .toPS (DUMMY_PDF , toPSOptionsSpec ));
352+ var ex = mockForException (mockClientToPs , cause , ()->underTest .toPS (DUMMY_PDF , toPSOptionsSpec ));
351353
352354 assertThat (ex , allOf (ExceptionMatchers .exceptionMsgContainsAll ("Error while POSTing to server" ),
353355 ExceptionMatchers .hasCause (cause )
@@ -361,14 +363,14 @@ void testToPS_IOException() throws Exception {
361363 var toPSOptionsSpec = Mockito .mock (ToPSOptionsSpec .class );
362364 var underTest = createAdapter (mockClientFactory );
363365
364- var ex = mockForException (cause , ()->underTest .toPS (DUMMY_PDF , toPSOptionsSpec ));
366+ var ex = mockForException (mockClientToPs , cause , ()->underTest .toPS (DUMMY_PDF , toPSOptionsSpec ));
365367
366368 assertThat (ex , allOf (ExceptionMatchers .exceptionMsgContainsAll ("I/O Error while securing document" ),
367369 ExceptionMatchers .hasCause (cause )
368370 ));
369371 }
370372
371- private <T extends Exception > ConvertPdfServiceException mockForException (T exception , Executable test ) throws Exception {
373+ private <T extends Exception > ConvertPdfServiceException mockForException (RestClient mockClient , T exception , Executable test ) throws Exception {
372374
373375 Builder mockPayloadBuilder2 = Mockito .mock (Builder .class , Answers .RETURNS_SELF );
374376 when (mockClient .multipartPayloadBuilder ()).thenReturn (mockPayloadBuilder2 );
@@ -395,7 +397,7 @@ private static RestServicesConvertPdfServiceAdapter createAdapter(RestClientFact
395397 .build ();
396398 }
397399
398- private void setupMocks (Optional <Response > mockedResponse ) throws RestClientException {
400+ private void setupMocks (RestClient mockClient , Optional <Response > mockedResponse ) throws RestClientException {
399401 when (mockClient .multipartPayloadBuilder ()).thenReturn (mockPayloadBuilder );
400402 when (mockPayloadBuilder .build ()).thenReturn (mockPayload );
401403 when (mockPayload .postToServer (acceptableContentType .capture ())).thenReturn (mockedResponse );
@@ -406,4 +408,5 @@ private Optional<Response> setupMockResponse(byte[] responseData, ContentType ex
406408 when (mockResponse .data ()).thenReturn (new ByteArrayInputStream (responseData ));
407409 return Optional .of (mockResponse );
408410 }
409- }
411+
412+ }
0 commit comments