*/
@Subscribe
public void imageInsertFinished(ImageInsertFinishedEvent imageInsertFinishedEvent) {
- logger.log(Level.WARNING, String.format("Image insert finished for %s: %s", imageInsertFinishedEvent.image(), imageInsertFinishedEvent.resultingUri()));
- imageInsertFinishedEvent.image().modify().setKey(imageInsertFinishedEvent.resultingUri().toString()).update();
- deleteTemporaryImage(imageInsertFinishedEvent.image().getId());
+ logger.log(Level.WARNING, String.format("Image insert finished for %s: %s", imageInsertFinishedEvent.getImage(), imageInsertFinishedEvent.getResultingUri()));
+ imageInsertFinishedEvent.getImage().modify().setKey(imageInsertFinishedEvent.getResultingUri().toString()).update();
+ deleteTemporaryImage(imageInsertFinishedEvent.getImage().getId());
touchConfiguration();
}
+++ /dev/null
-/*
- * Sone - ImageEvent.java - Copyright © 2013–2019 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 <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.core.event;
-
-import net.pterodactylus.sone.data.Image;
-
-/**
- * Base class for {@link Image} events.
- */
-public abstract class ImageEvent {
-
- /** The image this event is about. */
- private final Image image;
-
- /**
- * Creates a new image event.
- *
- * @param image
- * The image this event is about
- */
- protected ImageEvent(Image image) {
- this.image = image;
- }
-
- //
- // ACCESSORS
- //
-
- /**
- * Returns the image this event is about.
- *
- * @return The image this event is about
- */
- public Image image() {
- return image;
- }
-
-}
+++ /dev/null
-/*
- * Sone - ImageInsertAbortedEvent.java - Copyright © 2013–2019 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 <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.core.event;
-
-import net.pterodactylus.sone.data.Image;
-
-/**
- * Event that signals that an {@link Image} insert is aborted.
- */
-public class ImageInsertAbortedEvent extends ImageEvent {
-
- /**
- * Creates a new “image insert aborted” event.
- *
- * @param image
- * The image whose insert aborted
- */
- public ImageInsertAbortedEvent(Image image) {
- super(image);
- }
-
-}
+++ /dev/null
-/*
- * Sone - ImageInsertFailedEvent.java - Copyright © 2013–2019 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 <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.core.event;
-
-import net.pterodactylus.sone.data.Image;
-
-/**
- * Event that signals that an {@link Image} insert has failed.
- */
-public class ImageInsertFailedEvent extends ImageEvent {
-
- /** The cause of the insert failure. */
- private final Throwable cause;
-
- /**
- * Creates a new “image insert failed” event.
- *
- * @param image
- * The image whose insert failed
- * @param cause
- * The cause of the insert failure
- */
- public ImageInsertFailedEvent(Image image, Throwable cause) {
- super(image);
- this.cause = cause;
- }
-
- //
- // ACCESSORS
- //
-
- /**
- * Returns the cause of the insert failure.
- *
- * @return The cause of the insert failure
- */
- public Throwable cause() {
- return cause;
- }
-
-}
+++ /dev/null
-/*
- * Sone - ImageInsertFinishedEvent.java - Copyright © 2013–2019 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 <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.core.event;
-
-import net.pterodactylus.sone.data.Image;
-import freenet.keys.FreenetURI;
-
-/**
- * Event that signals that an {@link Image} insert is finished.
- */
-public class ImageInsertFinishedEvent extends ImageEvent {
-
- /** The URI of the image. */
- private final FreenetURI resultingUri;
-
- /**
- * Creates a new “image insert finished” event.
- *
- * @param image
- * The image whose insert finished
- * @param resultingUri
- * The resulting URI of the image
- */
- public ImageInsertFinishedEvent(Image image, FreenetURI resultingUri) {
- super(image);
- this.resultingUri = resultingUri;
- }
-
- //
- // ACCESSORS
- //
-
- /**
- * Returns the URI of the image.
- *
- * @return The URI of the image
- */
- public FreenetURI resultingUri() {
- return resultingUri;
- }
-
-}
+++ /dev/null
-/*
- * Sone - ImageInsertStartedEvent.java - Copyright © 2013–2019 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 <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.core.event;
-
-import net.pterodactylus.sone.data.Image;
-
-/**
- * Event that signals that an {@link Image} is not being inserted.
- */
-public class ImageInsertStartedEvent extends ImageEvent {
-
- /**
- * Creates a new “image is inserted” event.
- *
- * @param image
- * The image that is being inserted
- */
- public ImageInsertStartedEvent(Image image) {
- super(image);
- }
-
-}
+++ /dev/null
-/*
- * Sone - MarkPostKnownEvent.java - Copyright © 2013–2019 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 <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.core.event;
-
-import net.pterodactylus.sone.data.Post;
-
-/**
- * Event that signals that a {@link Post} has been marked as
- * {@link Post#isKnown() known}.
- */
-public class MarkPostKnownEvent extends PostEvent {
-
- /**
- * Creates a new “post marked known” event.
- *
- * @param post
- * The post that was marked as known
- */
- public MarkPostKnownEvent(Post post) {
- super(post);
- }
-
-}
--- /dev/null
+/*
+ * Sone - MarkPostKnownEvent.java - Copyright © 2013–2019 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 <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.core.event
+
+import net.pterodactylus.sone.data.Post
+
+/**
+ * Event that signals that a [Post] has been marked as
+ * [known][Post.isKnown].
+ */
+class MarkPostKnownEvent
+/**
+ * Creates a new “post marked known” event.
+ *
+ * @param post
+ * The post that was marked as known
+ */
+(post: Post) : PostEvent(post)
+++ /dev/null
-/*
- * Sone - PostEvent.java - Copyright © 2013–2019 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 <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.core.event;
-
-import net.pterodactylus.sone.data.Post;
-
-/**
- * Base class for post events.
- */
-public class PostEvent {
-
- /** The post the event is about. */
- private final Post post;
-
- /**
- * Creates a new post event.
- *
- * @param post
- * The post the event is about
- */
- protected PostEvent(Post post) {
- this.post = post;
- }
-
- //
- // ACCESSORS
- //
-
- /**
- * Returns the post the event is about.
- *
- * @return The post the event is about
- */
- public Post post() {
- return post;
- }
-
-}
--- /dev/null
+/*
+ * Sone - PostEvent.java - Copyright © 2013–2019 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 <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.core.event
+
+import net.pterodactylus.sone.data.Post
+
+/**
+ * Base class for post events.
+ */
+open class PostEvent
+/**
+ * Creates a new post event.
+ *
+ * @param post
+ * The post the event is about
+ */
+protected constructor(
+ /** The post the event is about. */
+ private val post: Post) {
+
+ //
+ // ACCESSORS
+ //
+
+ /**
+ * Returns the post the event is about.
+ *
+ * @return The post the event is about
+ */
+ fun post(): Post {
+ return post
+ }
+
+}
*/
@Subscribe
public void imageInsertStarted(ImageInsertStartedEvent imageInsertStartedEvent) {
- insertingImagesNotification.add(imageInsertStartedEvent.image());
+ insertingImagesNotification.add(imageInsertStartedEvent.getImage());
notificationManager.addNotification(insertingImagesNotification);
}
*/
@Subscribe
public void imageInsertAborted(ImageInsertAbortedEvent imageInsertAbortedEvent) {
- insertingImagesNotification.remove(imageInsertAbortedEvent.image());
+ insertingImagesNotification.remove(imageInsertAbortedEvent.getImage());
}
/**
*/
@Subscribe
public void imageInsertFinished(ImageInsertFinishedEvent imageInsertFinishedEvent) {
- insertingImagesNotification.remove(imageInsertFinishedEvent.image());
- insertedImagesNotification.add(imageInsertFinishedEvent.image());
+ insertingImagesNotification.remove(imageInsertFinishedEvent.getImage());
+ insertedImagesNotification.add(imageInsertFinishedEvent.getImage());
notificationManager.addNotification(insertedImagesNotification);
}
*/
@Subscribe
public void imageInsertFailed(ImageInsertFailedEvent imageInsertFailedEvent) {
- insertingImagesNotification.remove(imageInsertFailedEvent.image());
- imageInsertFailedNotification.add(imageInsertFailedEvent.image());
+ insertingImagesNotification.remove(imageInsertFailedEvent.getImage());
+ imageInsertFailedNotification.add(imageInsertFailedEvent.getImage());
notificationManager.addNotification(imageInsertFailedNotification);
}
--- /dev/null
+/*
+ * Sone - ImageEvent.kt - Copyright © 2013–2019 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 <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.core.event
+
+import net.pterodactylus.sone.data.*
+
+/**
+ * Base class for [Image] events.
+ */
+abstract class ImageEvent(val image: Image)
--- /dev/null
+/*
+ * Sone - ImageInsertAbortedEvent.kt - Copyright © 2013–2019 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 <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.core.event
+
+import net.pterodactylus.sone.data.*
+
+/**
+ * Event that signals that an [Image] insert is aborted.
+ */
+class ImageInsertAbortedEvent(image: Image) : ImageEvent(image)
--- /dev/null
+/*
+ * Sone - ImageInsertFailedEvent.kt - Copyright © 2013–2019 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 <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.core.event
+
+import net.pterodactylus.sone.data.*
+
+/**
+ * Event that signals that an [Image] insert has failed.
+ */
+class ImageInsertFailedEvent(image: Image, val cause: Throwable) : ImageEvent(image)
--- /dev/null
+/*
+ * Sone - ImageInsertFinishedEvent.kt - Copyright © 2013–2019 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 <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.core.event
+
+import freenet.keys.*
+import net.pterodactylus.sone.data.*
+
+/**
+ * Event that signals that an [Image] insert is finished.
+ */
+class ImageInsertFinishedEvent(image: Image, val resultingUri: FreenetURI) : ImageEvent(image)
--- /dev/null
+/*
+ * Sone - ImageInsertStartedEvent.kt - Copyright © 2013–2019 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 <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.core.event
+
+import net.pterodactylus.sone.data.*
+
+/**
+ * Event that signals that an [Image] is not being inserted.
+ */
+class ImageInsertStartedEvent(image: Image) : ImageEvent(image)
import freenet.support.io.ResumeFailedException;
import com.google.common.eventbus.EventBus;
+import org.hamcrest.*;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
insertToken.setClientPutter(clientPutter);
ArgumentCaptor<ImageInsertStartedEvent> imageInsertStartedEvent = forClass(ImageInsertStartedEvent.class);
verify(eventBus).post(imageInsertStartedEvent.capture());
- assertThat(imageInsertStartedEvent.getValue().image(), is(image));
+ assertThat(imageInsertStartedEvent.getValue().getImage(), is(image));
insertToken.cancel();
ArgumentCaptor<ImageInsertAbortedEvent> imageInsertAbortedEvent = forClass(ImageInsertAbortedEvent.class);
verify(eventBus, times(2)).post(imageInsertAbortedEvent.capture());
verify(bucket).free();
- assertThat(imageInsertAbortedEvent.getValue().image(), is(image));
+ assertThat(imageInsertAbortedEvent.getValue().getImage(), is(image));
}
@Test
public void failureWithoutExceptionSendsFailedEvent() {
- insertToken.onFailure(null, null);
+ InsertException insertException = new InsertException(mock(InsertException.class));
+ insertToken.onFailure(insertException, null);
ArgumentCaptor<ImageInsertFailedEvent> imageInsertFailedEvent = forClass(ImageInsertFailedEvent.class);
verify(eventBus).post(imageInsertFailedEvent.capture());
verify(bucket).free();
- assertThat(imageInsertFailedEvent.getValue().image(), is(image));
- assertThat(imageInsertFailedEvent.getValue().cause(), nullValue());
+ assertThat(imageInsertFailedEvent.getValue().getImage(), is(image));
+ assertThat(imageInsertFailedEvent.getValue().getCause(), Matchers.<Throwable>is(insertException));
}
@Test
ArgumentCaptor<ImageInsertFailedEvent> imageInsertFailedEvent = forClass(ImageInsertFailedEvent.class);
verify(eventBus).post(imageInsertFailedEvent.capture());
verify(bucket).free();
- assertThat(imageInsertFailedEvent.getValue().image(), is(image));
- assertThat(imageInsertFailedEvent.getValue().cause(), is((Throwable) insertException));
+ assertThat(imageInsertFailedEvent.getValue().getImage(), is(image));
+ assertThat(imageInsertFailedEvent.getValue().getCause(), is((Throwable) insertException));
}
@Test
ArgumentCaptor<ImageInsertAbortedEvent> imageInsertAbortedEvent = forClass(ImageInsertAbortedEvent.class);
verify(eventBus).post(imageInsertAbortedEvent.capture());
verify(bucket).free();
- assertThat(imageInsertAbortedEvent.getValue().image(), is(image));
+ assertThat(imageInsertAbortedEvent.getValue().getImage(), is(image));
}
@Test
ArgumentCaptor<ImageInsertFinishedEvent> imageInsertFinishedEvent = forClass(ImageInsertFinishedEvent.class);
verify(eventBus).post(imageInsertFinishedEvent.capture());
verify(bucket).free();
- assertThat(imageInsertFinishedEvent.getValue().image(), is(image));
- assertThat(imageInsertFinishedEvent.getValue().resultingUri(), is(generatedUri));
+ assertThat(imageInsertFinishedEvent.getValue().getImage(), is(image));
+ assertThat(imageInsertFinishedEvent.getValue().getResultingUri(), is(generatedUri));
}
@Test