eac52870a426c1b6354063f4e66c32d9dbac22d6
[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(sone, album);
49
50         @Test
51         public void testImageCreationWithAllExplicitParameters() {
52                 Image image = imageBuilder.withId(ID).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                 Image image = imageBuilder.randomId().created(CREATION_TIME).at(KEY).sized(WIDTH, HEIGHT).build();
65                 assertThat(image, CoreMatchers.notNullValue());
66                 assertThat(image.getId(), notNullValue());
67                 assertThat(image.getSone(), is(sone));
68                 assertThat(image.getCreationTime(), is(CREATION_TIME));
69                 assertThat(image.getKey(), is(KEY));
70                 assertThat(image.getWidth(), is(WIDTH));
71                 assertThat(image.getHeight(), is(HEIGHT));
72         }
73
74         @Test
75         public void testImageCreationWithCurrentTime() {
76                 Image image = imageBuilder.withId(ID).createdNow().at(KEY).sized(WIDTH, HEIGHT).build();
77                 assertThat(image, CoreMatchers.notNullValue());
78                 assertThat(image.getId(), is(ID));
79                 assertThat(image.getSone(), is(sone));
80                 assertThat(image.getCreationTime() > 0, is(true));
81                 assertThat(image.getKey(), is(KEY));
82                 assertThat(image.getWidth(), is(WIDTH));
83                 assertThat(image.getHeight(), is(HEIGHT));
84         }
85
86         @Test(expected = IllegalStateException.class)
87         public void testThatImageCreationWithoutAnIdFails() {
88                 imageBuilder.created(CREATION_TIME).at(KEY).sized(WIDTH, HEIGHT).build();
89         }
90
91         @Test(expected = IllegalStateException.class)
92         public void testThatImageCreationWithoutATimeFails() {
93                 imageBuilder.withId(ID).at(KEY).sized(WIDTH, HEIGHT).build();
94         }
95
96         @Test(expected = IllegalStateException.class)
97         public void testThatImageCreationWithoutASizeFails() {
98                 imageBuilder.withId(ID).createdNow().at(KEY).build();
99         }
100
101         @Test(expected = IllegalStateException.class)
102         public void testThatImageCreationWithoutInvalidWidthFails() {
103                 imageBuilder.withId(ID).createdNow().at(KEY).sized(0, 1).build();
104         }
105
106         @Test(expected = IllegalStateException.class)
107         public void testThatImageCreationWithoutInvalidHeightFails() {
108                 imageBuilder.withId(ID).createdNow().at(KEY).sized(1, 0).build();
109         }
110
111 }