🎨 Replace image events with Kotlin versions
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 28 Jun 2019 10:51:49 +0000 (12:51 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 28 Jun 2019 11:44:03 +0000 (13:44 +0200)
17 files changed:
src/main/java/net/pterodactylus/sone/core/Core.java
src/main/java/net/pterodactylus/sone/core/event/ImageEvent.java [deleted file]
src/main/java/net/pterodactylus/sone/core/event/ImageInsertAbortedEvent.java [deleted file]
src/main/java/net/pterodactylus/sone/core/event/ImageInsertFailedEvent.java [deleted file]
src/main/java/net/pterodactylus/sone/core/event/ImageInsertFinishedEvent.java [deleted file]
src/main/java/net/pterodactylus/sone/core/event/ImageInsertStartedEvent.java [deleted file]
src/main/java/net/pterodactylus/sone/core/event/MarkPostKnownEvent.java [deleted file]
src/main/java/net/pterodactylus/sone/core/event/MarkPostKnownEvent.kt [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/core/event/PostEvent.java [deleted file]
src/main/java/net/pterodactylus/sone/core/event/PostEvent.kt [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/WebInterface.java
src/main/kotlin/net/pterodactylus/sone/core/event/ImageEvent.kt [new file with mode: 0644]
src/main/kotlin/net/pterodactylus/sone/core/event/ImageInsertAbortedEvent.kt [new file with mode: 0644]
src/main/kotlin/net/pterodactylus/sone/core/event/ImageInsertFailedEvent.kt [new file with mode: 0644]
src/main/kotlin/net/pterodactylus/sone/core/event/ImageInsertFinishedEvent.kt [new file with mode: 0644]
src/main/kotlin/net/pterodactylus/sone/core/event/ImageInsertStartedEvent.kt [new file with mode: 0644]
src/test/java/net/pterodactylus/sone/core/FreenetInterfaceTest.java

index b0df7a9..f004cf2 100644 (file)
@@ -1680,9 +1680,9 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
         */
        @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();
        }
 
diff --git a/src/main/java/net/pterodactylus/sone/core/event/ImageEvent.java b/src/main/java/net/pterodactylus/sone/core/event/ImageEvent.java
deleted file mode 100644 (file)
index 6daef1a..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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;
-       }
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/core/event/ImageInsertAbortedEvent.java b/src/main/java/net/pterodactylus/sone/core/event/ImageInsertAbortedEvent.java
deleted file mode 100644 (file)
index 2bfa3a2..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * 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);
-       }
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/core/event/ImageInsertFailedEvent.java b/src/main/java/net/pterodactylus/sone/core/event/ImageInsertFailedEvent.java
deleted file mode 100644 (file)
index 430c64b..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * 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;
-       }
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/core/event/ImageInsertFinishedEvent.java b/src/main/java/net/pterodactylus/sone/core/event/ImageInsertFinishedEvent.java
deleted file mode 100644 (file)
index 4419311..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * 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;
-       }
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/core/event/ImageInsertStartedEvent.java b/src/main/java/net/pterodactylus/sone/core/event/ImageInsertStartedEvent.java
deleted file mode 100644 (file)
index ac9e3e3..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * 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);
-       }
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/core/event/MarkPostKnownEvent.java b/src/main/java/net/pterodactylus/sone/core/event/MarkPostKnownEvent.java
deleted file mode 100644 (file)
index 7c8a6c3..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * 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);
-       }
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/core/event/MarkPostKnownEvent.kt b/src/main/java/net/pterodactylus/sone/core/event/MarkPostKnownEvent.kt
new file mode 100644 (file)
index 0000000..0f12a86
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * 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)
diff --git a/src/main/java/net/pterodactylus/sone/core/event/PostEvent.java b/src/main/java/net/pterodactylus/sone/core/event/PostEvent.java
deleted file mode 100644 (file)
index 93a61c6..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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;
-       }
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/core/event/PostEvent.kt b/src/main/java/net/pterodactylus/sone/core/event/PostEvent.kt
new file mode 100644 (file)
index 0000000..04d46c6
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * 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
+       }
+
+}
index 3d131c8..0ed9e47 100644 (file)
@@ -981,7 +981,7 @@ public class WebInterface implements SessionProvider {
         */
        @Subscribe
        public void imageInsertStarted(ImageInsertStartedEvent imageInsertStartedEvent) {
-               insertingImagesNotification.add(imageInsertStartedEvent.image());
+               insertingImagesNotification.add(imageInsertStartedEvent.getImage());
                notificationManager.addNotification(insertingImagesNotification);
        }
 
@@ -993,7 +993,7 @@ public class WebInterface implements SessionProvider {
         */
        @Subscribe
        public void imageInsertAborted(ImageInsertAbortedEvent imageInsertAbortedEvent) {
-               insertingImagesNotification.remove(imageInsertAbortedEvent.image());
+               insertingImagesNotification.remove(imageInsertAbortedEvent.getImage());
        }
 
        /**
@@ -1004,8 +1004,8 @@ public class WebInterface implements SessionProvider {
         */
        @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);
        }
 
@@ -1017,8 +1017,8 @@ public class WebInterface implements SessionProvider {
         */
        @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);
        }
 
diff --git a/src/main/kotlin/net/pterodactylus/sone/core/event/ImageEvent.kt b/src/main/kotlin/net/pterodactylus/sone/core/event/ImageEvent.kt
new file mode 100644 (file)
index 0000000..0fca0ab
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * 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)
diff --git a/src/main/kotlin/net/pterodactylus/sone/core/event/ImageInsertAbortedEvent.kt b/src/main/kotlin/net/pterodactylus/sone/core/event/ImageInsertAbortedEvent.kt
new file mode 100644 (file)
index 0000000..55455c7
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * 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)
diff --git a/src/main/kotlin/net/pterodactylus/sone/core/event/ImageInsertFailedEvent.kt b/src/main/kotlin/net/pterodactylus/sone/core/event/ImageInsertFailedEvent.kt
new file mode 100644 (file)
index 0000000..07b82a8
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * 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)
diff --git a/src/main/kotlin/net/pterodactylus/sone/core/event/ImageInsertFinishedEvent.kt b/src/main/kotlin/net/pterodactylus/sone/core/event/ImageInsertFinishedEvent.kt
new file mode 100644 (file)
index 0000000..d275dd1
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * 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)
diff --git a/src/main/kotlin/net/pterodactylus/sone/core/event/ImageInsertStartedEvent.kt b/src/main/kotlin/net/pterodactylus/sone/core/event/ImageInsertStartedEvent.kt
new file mode 100644 (file)
index 0000000..939525d
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * 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)
index c91de68..9391bde 100644 (file)
@@ -75,6 +75,7 @@ import freenet.support.io.ArrayBucket;
 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;
@@ -353,22 +354,23 @@ public class FreenetInterfaceTest {
                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
@@ -378,8 +380,8 @@ public class FreenetInterfaceTest {
                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
@@ -389,7 +391,7 @@ public class FreenetInterfaceTest {
                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
@@ -407,8 +409,8 @@ public class FreenetInterfaceTest {
                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