+ public void setupImage() {
+ final Image image = SoneDownloaderTest.this.image;
+ Image.Modifier modifier = new Image.Modifier() {
+ private Sone sone = image.getSone();
+ private long creationTime = image.getCreationTime();
+ private String key = image.getKey();
+ private String title = image.getTitle();
+ private String description = image.getDescription();
+ private int width = image.getWidth();
+ private int height = image.getHeight();
+
+ @Override
+ public Image.Modifier setSone(Sone sone) {
+ this.sone = sone;
+ return this;
+ }
+
+ @Override
+ public Image.Modifier setCreationTime(long creationTime) {
+ this.creationTime = creationTime;
+ return this;
+ }
+
+ @Override
+ public Image.Modifier setKey(String key) {
+ this.key = key;
+ return this;
+ }
+
+ @Override
+ public Image.Modifier setTitle(String title) {
+ this.title = title;
+ return this;
+ }
+
+ @Override
+ public Image.Modifier setDescription(String description) {
+ this.description = description;
+ return this;
+ }
+
+ @Override
+ public Image.Modifier setWidth(int width) {
+ this.width = width;
+ return this;
+ }
+
+ @Override
+ public Image.Modifier setHeight(int height) {
+ this.height = height;
+ return this;
+ }
+
+ @Override
+ public Image update() throws IllegalStateException {
+ when(image.getSone()).thenReturn(sone);
+ when(image.getCreationTime()).thenReturn(creationTime);
+ when(image.getKey()).thenReturn(key);
+ when(image.getTitle()).thenReturn(title);
+ when(image.getDescription()).thenReturn(description);
+ when(image.getWidth()).thenReturn(width);
+ when(image.getHeight()).thenReturn(height);
+ return image;
+ }
+ };
+ when(image.getSone()).thenReturn(sone);
+ when(image.modify()).thenReturn(modifier);
+ }
+
+ @Before
+ public void setupImageBuilder() {
+ when(imageBuilder.randomId()).thenAnswer(new Answer<ImageBuilder>() {
+ @Override
+ public ImageBuilder answer(InvocationOnMock invocation) {
+ when(image.getId()).thenReturn(randomUUID().toString());
+ return imageBuilder;
+ }
+ });
+ when(imageBuilder.withId(anyString())).thenAnswer(new Answer<ImageBuilder>() {
+ @Override
+ public ImageBuilder answer(InvocationOnMock invocation) {
+ when(image.getId()).thenReturn(
+ (String) invocation.getArguments()[0]);
+ return imageBuilder;
+ }
+ });
+ when(imageBuilder.build()).thenAnswer(new Answer<Image>() {
+ @Override
+ public Image answer(InvocationOnMock invocation) {
+ Image image = SoneDownloaderTest.this.image;
+ images.put(image.getId(), image);
+ SoneDownloaderTest.this.image = mock(Image.class);
+ setupImage();
+ return image;
+ }
+ });
+ when(core.imageBuilder()).thenReturn(imageBuilder);
+ }
+
+ @Before