-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathImageProcessorTest.java
More file actions
61 lines (48 loc) · 2.19 KB
/
ImageProcessorTest.java
File metadata and controls
61 lines (48 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import de.telran.ImageProcessor;
import de.telran.entity.ActionableImage;
import de.telran.entity.ImageDescriptor;
import de.telran.service.DownloadService;
import de.telran.service.FileService;
import de.telran.service.ImageDescriptorService;
import de.telran.service.ImageService;
import org.junit.Before;
import org.junit.Test;
import java.util.Arrays;
import java.util.List;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
public class ImageProcessorTest {
ImageDescriptorService imageDescriptorService = mock(ImageDescriptorService.class);
DownloadService downloadService = mock(DownloadService.class);
ImageService imageService = mock(ImageService.class);
FileService fileService = mock(FileService.class);
ImageProcessor processor;
@Before
public void setUp() {
processor = new ImageProcessor(imageDescriptorService, downloadService, imageService, fileService);
}
@Test
public void testDoProcessing() {
//configure mock
List<ImageDescriptor> testImageDescriptors = createTestImageDescriptors();
when(imageDescriptorService.getImageDescriptors(any())).thenReturn(testImageDescriptors);
when(downloadService.downloadImages(any())).thenReturn(createDownloadedImage());
//execute test method
processor.doProcessing("test.txt");
//verify
verify(imageDescriptorService, times(1)).getImageDescriptors("test.txt");
verify(downloadService, times(1)).downloadImages(testImageDescriptors);
verify(fileService, times(2)).saveImageAsFile(any());
}
private static List<ActionableImage> createDownloadedImage() {
return Arrays.asList(
new ActionableImage(null, true, new ImageDescriptor("http://server.com/image1.jpg", "PREVIEW")),
new ActionableImage(null, true, new ImageDescriptor("http://server.com/image2.jpg", "THUMBNAIL"))
);
}
private static List<ImageDescriptor> createTestImageDescriptors() {
return Arrays.asList(
new ImageDescriptor("http://server.com/image1.jpg", "PREVIEW"),
new ImageDescriptor("http://server.com/image2.jpg", "THUMBNAIL"));
}
}