Remove obsolete import.
[Sone.git] / src / test / java / net / pterodactylus / sone / TestImageBuilder.java
1 package net.pterodactylus.sone;
2
3 import static java.util.UUID.randomUUID;
4 import static org.mockito.Mockito.mock;
5 import static org.mockito.Mockito.when;
6
7 import net.pterodactylus.sone.data.Image;
8 import net.pterodactylus.sone.data.Sone;
9 import net.pterodactylus.sone.database.ImageBuilder;
10
11 /**
12  * {@link ImageBuilder} implementation that returns a mocked {@link Image}.
13  *
14  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
15  */
16 public class TestImageBuilder implements ImageBuilder {
17
18         private final Image image;
19
20         public TestImageBuilder() {
21                 image = mock(Image.class);
22                 Image.Modifier imageModifier = new Image.Modifier() {
23                         private Sone sone = image.getSone();
24                         private long creationTime = image.getCreationTime();
25                         private String key = image.getKey();
26                         private String title = image.getTitle();
27                         private String description = image.getDescription();
28                         private int width = image.getWidth();
29                         private int height = image.getHeight();
30
31                         @Override
32                         public Image.Modifier setSone(Sone sone) {
33                                 this.sone = sone;
34                                 return this;
35                         }
36
37                         @Override
38                         public Image.Modifier setCreationTime(long creationTime) {
39                                 this.creationTime = creationTime;
40                                 return this;
41                         }
42
43                         @Override
44                         public Image.Modifier setKey(String key) {
45                                 this.key = key;
46                                 return this;
47                         }
48
49                         @Override
50                         public Image.Modifier setTitle(String title) {
51                                 this.title = title;
52                                 return this;
53                         }
54
55                         @Override
56                         public Image.Modifier setDescription(String description) {
57                                 this.description = description;
58                                 return this;
59                         }
60
61                         @Override
62                         public Image.Modifier setWidth(int width) {
63                                 this.width = width;
64                                 return this;
65                         }
66
67                         @Override
68                         public Image.Modifier setHeight(int height) {
69                                 this.height = height;
70                                 return this;
71                         }
72
73                         @Override
74                         public Image update() throws IllegalStateException {
75                                 when(image.getSone()).thenReturn(sone);
76                                 when(image.getCreationTime()).thenReturn(creationTime);
77                                 when(image.getKey()).thenReturn(key);
78                                 when(image.getTitle()).thenReturn(title);
79                                 when(image.getDescription()).thenReturn(description);
80                                 when(image.getWidth()).thenReturn(width);
81                                 when(image.getHeight()).thenReturn(height);
82                                 return image;
83                         }
84                 };
85                 when(image.modify()).thenReturn(imageModifier);
86         }
87
88         @Override
89         public ImageBuilder randomId() {
90                 when(image.getId()).thenReturn(randomUUID().toString());
91                 return this;
92         }
93
94         @Override
95         public ImageBuilder withId(String id) {
96                 when(image.getId()).thenReturn(id);
97                 return this;
98         }
99
100         @Override
101         public Image build() throws IllegalStateException {
102                 return image;
103         }
104
105 }