38b50fac103cdfc0711bb3106fe6d3ad3c0f9558
[Sone.git] / src / test / java / net / pterodactylus / sone / data / impl / DefaultImageBuilderTest.java
1 /*
2  * Sone - ImageBuilderImplTest.java - Copyright © 2013 David Roden
3  *
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.
8  *
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.
13  *
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/>.
16  */
17
18 package net.pterodactylus.sone.data.impl;
19
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;
24
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;
29
30 import org.hamcrest.CoreMatchers;
31 import org.junit.Test;
32
33 /**
34  * TODO
35  *
36  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
37  */
38 public class DefaultImageBuilderTest {
39
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;
45
46         private final Sone sone = mock(Sone.class);
47         private final Album album = mock(Album.class);
48         private final ImageBuilder imageBuilder = new DefaultImageBuilder(album);
49
50         @Test
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));
60         }
61
62         @Test
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));
73         }
74
75         @Test
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));
85         }
86
87         @Test(expected = IllegalStateException.class)
88         public void testThatImageCreationWithoutAnIdFails() {
89                 imageBuilder.by(sone).created(CREATION_TIME).at(KEY).sized(WIDTH, HEIGHT).build();
90         }
91
92         @Test(expected = IllegalStateException.class)
93         public void testThatImageCreationWithoutASoneFails() {
94                 imageBuilder.withId(ID).created(CREATION_TIME).at(KEY).sized(WIDTH, HEIGHT).build();
95         }
96
97         @Test(expected = IllegalStateException.class)
98         public void testThatImageCreationWithoutATimeFails() {
99                 imageBuilder.withId(ID).by(sone).at(KEY).sized(WIDTH, HEIGHT).build();
100         }
101
102         @Test(expected = IllegalStateException.class)
103         public void testThatImageCreationWithoutASizeFails() {
104                 imageBuilder.withId(ID).by(sone).createdNow().at(KEY).build();
105         }
106
107         @Test(expected = IllegalStateException.class)
108         public void testThatImageCreationWithoutInvalidWidthFails() {
109                 imageBuilder.withId(ID).by(sone).createdNow().at(KEY).sized(0, 1).build();
110         }
111
112         @Test(expected = IllegalStateException.class)
113         public void testThatImageCreationWithoutInvalidHeightFails() {
114                 imageBuilder.withId(ID).by(sone).createdNow().at(KEY).sized(1, 0).build();
115         }
116
117 }