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.Image;
26 import net.pterodactylus.sone.data.Sone;
27 import net.pterodactylus.sone.database.ImageBuilder;
29 import org.hamcrest.CoreMatchers;
30 import org.junit.Test;
35 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
37 public class ImageBuilderImplTest {
39 private static final String ID = "12345";
40 private static final long CREATION_TIME = 1234;
41 private static final String KEY = "key";
42 private static final int WIDTH = 640;
43 private static final int HEIGHT = 270;
45 private final ImageBuilder imageBuilder = new ImageBuilderImpl();
46 private final Sone sone = mock(Sone.class);
49 public void testImageCreationWithAllExplicitParameters() {
50 Image image = imageBuilder.withId(ID).by(sone).created(CREATION_TIME).at(KEY).sized(WIDTH, HEIGHT).build();
51 assertThat(image, CoreMatchers.notNullValue());
52 assertThat(image.getId(), is(ID));
53 assertThat(image.getSone(), is(sone));
54 assertThat(image.getCreationTime(), is(CREATION_TIME));
55 assertThat(image.getKey(), is(KEY));
56 assertThat(image.getWidth(), is(WIDTH));
57 assertThat(image.getHeight(), is(HEIGHT));
61 public void testImageCreationWithRandomId() {
62 Sone sone = mock(Sone.class);
63 Image image = imageBuilder.randomId().by(sone).created(CREATION_TIME).at(KEY).sized(WIDTH, HEIGHT).build();
64 assertThat(image, CoreMatchers.notNullValue());
65 assertThat(image.getId(), notNullValue());
66 assertThat(image.getSone(), is(sone));
67 assertThat(image.getCreationTime(), is(CREATION_TIME));
68 assertThat(image.getKey(), is(KEY));
69 assertThat(image.getWidth(), is(WIDTH));
70 assertThat(image.getHeight(), is(HEIGHT));
74 public void testImageCreationWithCurrentTime() {
75 Image image = imageBuilder.withId(ID).by(sone).createdNow().at(KEY).sized(WIDTH, HEIGHT).build();
76 assertThat(image, CoreMatchers.notNullValue());
77 assertThat(image.getId(), is(ID));
78 assertThat(image.getSone(), is(sone));
79 assertThat(image.getCreationTime() > 0, is(true));
80 assertThat(image.getKey(), is(KEY));
81 assertThat(image.getWidth(), is(WIDTH));
82 assertThat(image.getHeight(), is(HEIGHT));
85 @Test(expected = IllegalStateException.class)
86 public void testThatImageCreationWithoutAnIdFails() {
87 imageBuilder.by(sone).created(CREATION_TIME).at(KEY).sized(WIDTH, HEIGHT).build();
90 @Test(expected = IllegalStateException.class)
91 public void testThatImageCreationWithoutASoneFails() {
92 imageBuilder.withId(ID).created(CREATION_TIME).at(KEY).sized(WIDTH, HEIGHT).build();
95 @Test(expected = IllegalStateException.class)
96 public void testThatImageCreationWithoutATimeFails() {
97 imageBuilder.withId(ID).by(sone).at(KEY).sized(WIDTH, HEIGHT).build();
100 @Test(expected = IllegalStateException.class)
101 public void testThatImageCreationWithoutASizeFails() {
102 imageBuilder.withId(ID).by(sone).createdNow().at(KEY).build();
105 @Test(expected = IllegalStateException.class)
106 public void testThatImageCreationWithoutInvalidWidthFails() {
107 imageBuilder.withId(ID).by(sone).createdNow().at(KEY).sized(0, 1).build();
110 @Test(expected = IllegalStateException.class)
111 public void testThatImageCreationWithoutInvalidHeightFails() {
112 imageBuilder.withId(ID).by(sone).createdNow().at(KEY).sized(1, 0).build();