From a121cba206f6455c6cf2d34519995a3c7305ad4c Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 12 Oct 2013 14:23:06 +0200 Subject: [PATCH] Move temporary image-related classes to their final destinations. --- .../net/pterodactylus/sone/data/AlbumImpl.java | 4 +- .../net/pterodactylus/sone/data/ImageImpl.java | 32 ------ .../sone/data/impl/DefaultImageBuilder.java | 41 ++++++++ .../sone/data/impl/ImageBuilderImpl.java | 42 -------- .../sone/data/impl/DefaultImageBuilderTest.java | 117 +++++++++++++++++++++ .../sone/data/impl/ImageBuilderImplTest.java | 117 --------------------- 6 files changed, 160 insertions(+), 193 deletions(-) delete mode 100644 src/main/java/net/pterodactylus/sone/data/ImageImpl.java create mode 100644 src/main/java/net/pterodactylus/sone/data/impl/DefaultImageBuilder.java delete mode 100644 src/main/java/net/pterodactylus/sone/data/impl/ImageBuilderImpl.java create mode 100644 src/test/java/net/pterodactylus/sone/data/impl/DefaultImageBuilderTest.java delete mode 100644 src/test/java/net/pterodactylus/sone/data/impl/ImageBuilderImplTest.java diff --git a/src/main/java/net/pterodactylus/sone/data/AlbumImpl.java b/src/main/java/net/pterodactylus/sone/data/AlbumImpl.java index 5ee0c23..c236ee1 100644 --- a/src/main/java/net/pterodactylus/sone/data/AlbumImpl.java +++ b/src/main/java/net/pterodactylus/sone/data/AlbumImpl.java @@ -29,7 +29,7 @@ import java.util.List; import java.util.Map; import java.util.UUID; -import net.pterodactylus.sone.data.impl.ImageBuilderImpl; +import net.pterodactylus.sone.data.impl.DefaultImageBuilder; import net.pterodactylus.sone.database.ImageBuilder; import com.google.common.base.Function; @@ -267,7 +267,7 @@ public class AlbumImpl implements Album { @Override public ImageBuilder newImageBuilder() throws IllegalStateException { - return new ImageBuilderImpl(this) { + return new DefaultImageBuilder(this) { @Override public Image build() throws IllegalStateException { Image image = super.build(); diff --git a/src/main/java/net/pterodactylus/sone/data/ImageImpl.java b/src/main/java/net/pterodactylus/sone/data/ImageImpl.java deleted file mode 100644 index 47842ec..0000000 --- a/src/main/java/net/pterodactylus/sone/data/ImageImpl.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Sone - ImageImpl.java - Copyright © 2011–2013 David Roden - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package net.pterodactylus.sone.data; - -import net.pterodactylus.sone.data.impl.DefaultImage; - -/** - * Container for image metadata. - * - * @author David ‘Bombe’ Roden - */ -public class ImageImpl extends DefaultImage { - - public ImageImpl(String id, Sone sone, Album album, String key, long creationTime, int width, int height) { - super(id, sone, album, key, creationTime, width, height); - } - -} diff --git a/src/main/java/net/pterodactylus/sone/data/impl/DefaultImageBuilder.java b/src/main/java/net/pterodactylus/sone/data/impl/DefaultImageBuilder.java new file mode 100644 index 0000000..7f7f53f --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/data/impl/DefaultImageBuilder.java @@ -0,0 +1,41 @@ +/* + * Sone - ImageBuilderImpl.java - Copyright © 2013 David Roden + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.sone.data.impl; + +import net.pterodactylus.sone.data.Album; +import net.pterodactylus.sone.data.Image; +import net.pterodactylus.sone.database.ImageBuilder; + +/** + * {@link ImageBuilder} implementation that creates {@link DefaultImage} objects. + * + * @author David Roden + */ +public class DefaultImageBuilder extends AbstractImageBuilder { + + public DefaultImageBuilder(Album album) { + super(album); + } + + @Override + public Image build() throws IllegalStateException { + validate(); + return new DefaultImage(getId(), sone, album, key, getCreationTime(), width, height); + } + +} diff --git a/src/main/java/net/pterodactylus/sone/data/impl/ImageBuilderImpl.java b/src/main/java/net/pterodactylus/sone/data/impl/ImageBuilderImpl.java deleted file mode 100644 index d3f060d..0000000 --- a/src/main/java/net/pterodactylus/sone/data/impl/ImageBuilderImpl.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Sone - ImageBuilderImpl.java - Copyright © 2013 David Roden - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.pterodactylus.sone.data.impl; - -import net.pterodactylus.sone.data.Album; -import net.pterodactylus.sone.data.Image; -import net.pterodactylus.sone.data.ImageImpl; -import net.pterodactylus.sone.database.ImageBuilder; - -/** - * {@link ImageBuilder} implementation that creates {@link ImageImpl} objects. - * - * @author David Roden - */ -public class ImageBuilderImpl extends AbstractImageBuilder { - - public ImageBuilderImpl(Album album) { - super(album); - } - - @Override - public Image build() throws IllegalStateException { - validate(); - return new ImageImpl(getId(), sone, album, key, getCreationTime(), width, height); - } - -} diff --git a/src/test/java/net/pterodactylus/sone/data/impl/DefaultImageBuilderTest.java b/src/test/java/net/pterodactylus/sone/data/impl/DefaultImageBuilderTest.java new file mode 100644 index 0000000..38b50fa --- /dev/null +++ b/src/test/java/net/pterodactylus/sone/data/impl/DefaultImageBuilderTest.java @@ -0,0 +1,117 @@ +/* + * Sone - ImageBuilderImplTest.java - Copyright © 2013 David Roden + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.sone.data.impl; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.mockito.Mockito.mock; + +import net.pterodactylus.sone.data.Album; +import net.pterodactylus.sone.data.Image; +import net.pterodactylus.sone.data.Sone; +import net.pterodactylus.sone.database.ImageBuilder; + +import org.hamcrest.CoreMatchers; +import org.junit.Test; + +/** + * TODO + * + * @author David ‘Bombe’ Roden + */ +public class DefaultImageBuilderTest { + + private static final String ID = "12345"; + private static final long CREATION_TIME = 1234; + private static final String KEY = "key"; + private static final int WIDTH = 640; + private static final int HEIGHT = 270; + + private final Sone sone = mock(Sone.class); + private final Album album = mock(Album.class); + private final ImageBuilder imageBuilder = new DefaultImageBuilder(album); + + @Test + public void testImageCreationWithAllExplicitParameters() { + Image image = imageBuilder.withId(ID).by(sone).created(CREATION_TIME).at(KEY).sized(WIDTH, HEIGHT).build(); + assertThat(image, CoreMatchers.notNullValue()); + assertThat(image.getId(), is(ID)); + assertThat(image.getSone(), is(sone)); + assertThat(image.getCreationTime(), is(CREATION_TIME)); + assertThat(image.getKey(), is(KEY)); + assertThat(image.getWidth(), is(WIDTH)); + assertThat(image.getHeight(), is(HEIGHT)); + } + + @Test + public void testImageCreationWithRandomId() { + Sone sone = mock(Sone.class); + Image image = imageBuilder.randomId().by(sone).created(CREATION_TIME).at(KEY).sized(WIDTH, HEIGHT).build(); + assertThat(image, CoreMatchers.notNullValue()); + assertThat(image.getId(), notNullValue()); + assertThat(image.getSone(), is(sone)); + assertThat(image.getCreationTime(), is(CREATION_TIME)); + assertThat(image.getKey(), is(KEY)); + assertThat(image.getWidth(), is(WIDTH)); + assertThat(image.getHeight(), is(HEIGHT)); + } + + @Test + public void testImageCreationWithCurrentTime() { + Image image = imageBuilder.withId(ID).by(sone).createdNow().at(KEY).sized(WIDTH, HEIGHT).build(); + assertThat(image, CoreMatchers.notNullValue()); + assertThat(image.getId(), is(ID)); + assertThat(image.getSone(), is(sone)); + assertThat(image.getCreationTime() > 0, is(true)); + assertThat(image.getKey(), is(KEY)); + assertThat(image.getWidth(), is(WIDTH)); + assertThat(image.getHeight(), is(HEIGHT)); + } + + @Test(expected = IllegalStateException.class) + public void testThatImageCreationWithoutAnIdFails() { + imageBuilder.by(sone).created(CREATION_TIME).at(KEY).sized(WIDTH, HEIGHT).build(); + } + + @Test(expected = IllegalStateException.class) + public void testThatImageCreationWithoutASoneFails() { + imageBuilder.withId(ID).created(CREATION_TIME).at(KEY).sized(WIDTH, HEIGHT).build(); + } + + @Test(expected = IllegalStateException.class) + public void testThatImageCreationWithoutATimeFails() { + imageBuilder.withId(ID).by(sone).at(KEY).sized(WIDTH, HEIGHT).build(); + } + + @Test(expected = IllegalStateException.class) + public void testThatImageCreationWithoutASizeFails() { + imageBuilder.withId(ID).by(sone).createdNow().at(KEY).build(); + } + + @Test(expected = IllegalStateException.class) + public void testThatImageCreationWithoutInvalidWidthFails() { + imageBuilder.withId(ID).by(sone).createdNow().at(KEY).sized(0, 1).build(); + } + + @Test(expected = IllegalStateException.class) + public void testThatImageCreationWithoutInvalidHeightFails() { + imageBuilder.withId(ID).by(sone).createdNow().at(KEY).sized(1, 0).build(); + } + +} diff --git a/src/test/java/net/pterodactylus/sone/data/impl/ImageBuilderImplTest.java b/src/test/java/net/pterodactylus/sone/data/impl/ImageBuilderImplTest.java deleted file mode 100644 index b5d2a84..0000000 --- a/src/test/java/net/pterodactylus/sone/data/impl/ImageBuilderImplTest.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Sone - ImageBuilderImplTest.java - Copyright © 2013 David Roden - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.pterodactylus.sone.data.impl; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.mockito.Mockito.mock; - -import net.pterodactylus.sone.data.Album; -import net.pterodactylus.sone.data.Image; -import net.pterodactylus.sone.data.Sone; -import net.pterodactylus.sone.database.ImageBuilder; - -import org.hamcrest.CoreMatchers; -import org.junit.Test; - -/** - * TODO - * - * @author David ‘Bombe’ Roden - */ -public class ImageBuilderImplTest { - - private static final String ID = "12345"; - private static final long CREATION_TIME = 1234; - private static final String KEY = "key"; - private static final int WIDTH = 640; - private static final int HEIGHT = 270; - - private final Sone sone = mock(Sone.class); - private final Album album = mock(Album.class); - private final ImageBuilder imageBuilder = new ImageBuilderImpl(album); - - @Test - public void testImageCreationWithAllExplicitParameters() { - Image image = imageBuilder.withId(ID).by(sone).created(CREATION_TIME).at(KEY).sized(WIDTH, HEIGHT).build(); - assertThat(image, CoreMatchers.notNullValue()); - assertThat(image.getId(), is(ID)); - assertThat(image.getSone(), is(sone)); - assertThat(image.getCreationTime(), is(CREATION_TIME)); - assertThat(image.getKey(), is(KEY)); - assertThat(image.getWidth(), is(WIDTH)); - assertThat(image.getHeight(), is(HEIGHT)); - } - - @Test - public void testImageCreationWithRandomId() { - Sone sone = mock(Sone.class); - Image image = imageBuilder.randomId().by(sone).created(CREATION_TIME).at(KEY).sized(WIDTH, HEIGHT).build(); - assertThat(image, CoreMatchers.notNullValue()); - assertThat(image.getId(), notNullValue()); - assertThat(image.getSone(), is(sone)); - assertThat(image.getCreationTime(), is(CREATION_TIME)); - assertThat(image.getKey(), is(KEY)); - assertThat(image.getWidth(), is(WIDTH)); - assertThat(image.getHeight(), is(HEIGHT)); - } - - @Test - public void testImageCreationWithCurrentTime() { - Image image = imageBuilder.withId(ID).by(sone).createdNow().at(KEY).sized(WIDTH, HEIGHT).build(); - assertThat(image, CoreMatchers.notNullValue()); - assertThat(image.getId(), is(ID)); - assertThat(image.getSone(), is(sone)); - assertThat(image.getCreationTime() > 0, is(true)); - assertThat(image.getKey(), is(KEY)); - assertThat(image.getWidth(), is(WIDTH)); - assertThat(image.getHeight(), is(HEIGHT)); - } - - @Test(expected = IllegalStateException.class) - public void testThatImageCreationWithoutAnIdFails() { - imageBuilder.by(sone).created(CREATION_TIME).at(KEY).sized(WIDTH, HEIGHT).build(); - } - - @Test(expected = IllegalStateException.class) - public void testThatImageCreationWithoutASoneFails() { - imageBuilder.withId(ID).created(CREATION_TIME).at(KEY).sized(WIDTH, HEIGHT).build(); - } - - @Test(expected = IllegalStateException.class) - public void testThatImageCreationWithoutATimeFails() { - imageBuilder.withId(ID).by(sone).at(KEY).sized(WIDTH, HEIGHT).build(); - } - - @Test(expected = IllegalStateException.class) - public void testThatImageCreationWithoutASizeFails() { - imageBuilder.withId(ID).by(sone).createdNow().at(KEY).build(); - } - - @Test(expected = IllegalStateException.class) - public void testThatImageCreationWithoutInvalidWidthFails() { - imageBuilder.withId(ID).by(sone).createdNow().at(KEY).sized(0, 1).build(); - } - - @Test(expected = IllegalStateException.class) - public void testThatImageCreationWithoutInvalidHeightFails() { - imageBuilder.withId(ID).by(sone).createdNow().at(KEY).sized(1, 0).build(); - } - -} -- 2.7.4