@Test public void should_post_decorate_field_and_return_decorator_result() { // GIVEN IUploadFileService uploadFileServiceMock = mock(IUploadFileService.class); INotificationService notificationServiceMock = mock(INotificationService.class); String expectedResult = "post-decorator result"; when(uploadFileServiceMock.upload(anyString(), anyString())).thenReturn(expectedResult); FileManager fileManager = new FileManager(); field("uploadFileService") .ofType(IUploadFileService.class) // .in(fileManager) .postDecorateWith(uploadFileServiceMock) .returningDecoratorResult(); field("notificationService") .ofType(INotificationService.class) .in(fileManager) .set(notificationServiceMock); // WHEN String fileName = "testFileName"; fileManager.manage(fileName); // THEN verify(uploadFileServiceMock, times(1)).upload(eq("testFileName"), anyString()); verify(notificationServiceMock, times(1)).notify(eq(expectedResult)); }
public void manage(String fileName) { notificationService.notify(uploadFileService.upload(fileName, DEFAULT_DESTINATION)); }