503e6f12f7387239ab6759254153eea8cbbbd53b
[Sone.git] / src / test / java / net / pterodactylus / sone / data / impl / ImageBuilderImplTest.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.Image;
26 import net.pterodactylus.sone.data.Sone;
27 import net.pterodactylus.sone.database.ImageBuilder;
28
29 import org.hamcrest.CoreMatchers;
30 import org.junit.Test;
31
32 /**
33  * TODO
34  *
35  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
36  */
37 public class ImageBuilderImplTest {
38
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;
44
45         private final ImageBuilder imageBuilder = new ImageBuilderImpl();
46         private final Sone sone = mock(Sone.class);
47
48         @Test
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));
58         }
59
60         @Test
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));
71         }
72
73         @Test
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));
83         }
84
85         @Test(expected = IllegalStateException.class)
86         public void testThatImageCreationWithoutAnIdFails() {
87                 imageBuilder.by(sone).created(CREATION_TIME).at(KEY).sized(WIDTH, HEIGHT).build();
88         }
89
90         @Test(expected = IllegalStateException.class)
91         public void testThatImageCreationWithoutASoneFails() {
92                 imageBuilder.withId(ID).created(CREATION_TIME).at(KEY).sized(WIDTH, HEIGHT).build();
93         }
94
95         @Test(expected = IllegalStateException.class)
96         public void testThatImageCreationWithoutATimeFails() {
97                 imageBuilder.withId(ID).by(sone).at(KEY).sized(WIDTH, HEIGHT).build();
98         }
99
100         @Test(expected = IllegalStateException.class)
101         public void testThatImageCreationWithoutASizeFails() {
102                 imageBuilder.withId(ID).by(sone).createdNow().at(KEY).build();
103         }
104
105         @Test(expected = IllegalStateException.class)
106         public void testThatImageCreationWithoutInvalidWidthFails() {
107                 imageBuilder.withId(ID).by(sone).createdNow().at(KEY).sized(0, 1).build();
108         }
109
110         @Test(expected = IllegalStateException.class)
111         public void testThatImageCreationWithoutInvalidHeightFails() {
112                 imageBuilder.withId(ID).by(sone).createdNow().at(KEY).sized(1, 0).build();
113         }
114
115 }