2 * Sone - ImageBuilderImplTest.java - Copyright © 2013 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.sone.data.impl;
20 import static org.hamcrest.CoreMatchers.is;
21 import static org.hamcrest.CoreMatchers.notNullValue;
22 import static org.hamcrest.MatcherAssert.assertThat;
23 import static org.mockito.Mockito.mock;
25 import net.pterodactylus.sone.data.Album;
26 import net.pterodactylus.sone.data.Image;
27 import net.pterodactylus.sone.data.Sone;
28 import net.pterodactylus.sone.database.ImageBuilder;
30 import org.hamcrest.CoreMatchers;
31 import org.junit.Test;
36 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
38 public class ImageBuilderImplTest {
40 private static final String ID = "12345";
41 private static final long CREATION_TIME = 1234;
42 private static final String KEY = "key";
43 private static final int WIDTH = 640;
44 private static final int HEIGHT = 270;
46 private final Sone sone = mock(Sone.class);
47 private final Album album = mock(Album.class);
48 private final ImageBuilder imageBuilder = new ImageBuilderImpl(album);
51 public void testImageCreationWithAllExplicitParameters() {
52 Image image = imageBuilder.withId(ID).by(sone).created(CREATION_TIME).at(KEY).sized(WIDTH, HEIGHT).build();
53 assertThat(image, CoreMatchers.notNullValue());
54 assertThat(image.getId(), is(ID));
55 assertThat(image.getSone(), is(sone));
56 assertThat(image.getCreationTime(), is(CREATION_TIME));
57 assertThat(image.getKey(), is(KEY));
58 assertThat(image.getWidth(), is(WIDTH));
59 assertThat(image.getHeight(), is(HEIGHT));
63 public void testImageCreationWithRandomId() {
64 Sone sone = mock(Sone.class);
65 Image image = imageBuilder.randomId().by(sone).created(CREATION_TIME).at(KEY).sized(WIDTH, HEIGHT).build();
66 assertThat(image, CoreMatchers.notNullValue());
67 assertThat(image.getId(), notNullValue());
68 assertThat(image.getSone(), is(sone));
69 assertThat(image.getCreationTime(), is(CREATION_TIME));
70 assertThat(image.getKey(), is(KEY));
71 assertThat(image.getWidth(), is(WIDTH));
72 assertThat(image.getHeight(), is(HEIGHT));
76 public void testImageCreationWithCurrentTime() {
77 Image image = imageBuilder.withId(ID).by(sone).createdNow().at(KEY).sized(WIDTH, HEIGHT).build();
78 assertThat(image, CoreMatchers.notNullValue());
79 assertThat(image.getId(), is(ID));
80 assertThat(image.getSone(), is(sone));
81 assertThat(image.getCreationTime() > 0, is(true));
82 assertThat(image.getKey(), is(KEY));
83 assertThat(image.getWidth(), is(WIDTH));
84 assertThat(image.getHeight(), is(HEIGHT));
87 @Test(expected = IllegalStateException.class)
88 public void testThatImageCreationWithoutAnIdFails() {
89 imageBuilder.by(sone).created(CREATION_TIME).at(KEY).sized(WIDTH, HEIGHT).build();
92 @Test(expected = IllegalStateException.class)
93 public void testThatImageCreationWithoutASoneFails() {
94 imageBuilder.withId(ID).created(CREATION_TIME).at(KEY).sized(WIDTH, HEIGHT).build();
97 @Test(expected = IllegalStateException.class)
98 public void testThatImageCreationWithoutATimeFails() {
99 imageBuilder.withId(ID).by(sone).at(KEY).sized(WIDTH, HEIGHT).build();
102 @Test(expected = IllegalStateException.class)
103 public void testThatImageCreationWithoutASizeFails() {
104 imageBuilder.withId(ID).by(sone).createdNow().at(KEY).build();
107 @Test(expected = IllegalStateException.class)
108 public void testThatImageCreationWithoutInvalidWidthFails() {
109 imageBuilder.withId(ID).by(sone).createdNow().at(KEY).sized(0, 1).build();
112 @Test(expected = IllegalStateException.class)
113 public void testThatImageCreationWithoutInvalidHeightFails() {
114 imageBuilder.withId(ID).by(sone).createdNow().at(KEY).sized(1, 0).build();