From 381ae78f799b609194c53c3da256cff9daa4d2ff Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 28 Jun 2019 12:51:49 +0200 Subject: [PATCH] =?utf8?q?=F0=9F=8E=A8=20Replace=20image=20events=20with?= =?utf8?q?=20Kotlin=20versions?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../java/net/pterodactylus/sone/core/Core.java | 6 +-- .../pterodactylus/sone/core/event/ImageEvent.java | 53 -------------------- .../sone/core/event/ImageInsertAbortedEvent.java | 37 -------------- .../sone/core/event/ImageInsertFailedEvent.java | 56 --------------------- .../sone/core/event/ImageInsertFinishedEvent.java | 57 ---------------------- .../sone/core/event/ImageInsertStartedEvent.java | 37 -------------- .../sone/core/event/MarkPostKnownEvent.java | 38 --------------- .../sone/core/event/MarkPostKnownEvent.kt | 33 +++++++++++++ .../pterodactylus/sone/core/event/PostEvent.java | 53 -------------------- .../net/pterodactylus/sone/core/event/PostEvent.kt | 49 +++++++++++++++++++ .../net/pterodactylus/sone/web/WebInterface.java | 12 ++--- .../pterodactylus/sone/core/event/ImageEvent.kt | 25 ++++++++++ .../sone/core/event/ImageInsertAbortedEvent.kt | 25 ++++++++++ .../sone/core/event/ImageInsertFailedEvent.kt | 25 ++++++++++ .../sone/core/event/ImageInsertFinishedEvent.kt | 26 ++++++++++ .../sone/core/event/ImageInsertStartedEvent.kt | 25 ++++++++++ .../sone/core/FreenetInterfaceTest.java | 22 +++++---- 17 files changed, 229 insertions(+), 350 deletions(-) delete mode 100644 src/main/java/net/pterodactylus/sone/core/event/ImageEvent.java delete mode 100644 src/main/java/net/pterodactylus/sone/core/event/ImageInsertAbortedEvent.java delete mode 100644 src/main/java/net/pterodactylus/sone/core/event/ImageInsertFailedEvent.java delete mode 100644 src/main/java/net/pterodactylus/sone/core/event/ImageInsertFinishedEvent.java delete mode 100644 src/main/java/net/pterodactylus/sone/core/event/ImageInsertStartedEvent.java delete mode 100644 src/main/java/net/pterodactylus/sone/core/event/MarkPostKnownEvent.java create mode 100644 src/main/java/net/pterodactylus/sone/core/event/MarkPostKnownEvent.kt delete mode 100644 src/main/java/net/pterodactylus/sone/core/event/PostEvent.java create mode 100644 src/main/java/net/pterodactylus/sone/core/event/PostEvent.kt create mode 100644 src/main/kotlin/net/pterodactylus/sone/core/event/ImageEvent.kt create mode 100644 src/main/kotlin/net/pterodactylus/sone/core/event/ImageInsertAbortedEvent.kt create mode 100644 src/main/kotlin/net/pterodactylus/sone/core/event/ImageInsertFailedEvent.kt create mode 100644 src/main/kotlin/net/pterodactylus/sone/core/event/ImageInsertFinishedEvent.kt create mode 100644 src/main/kotlin/net/pterodactylus/sone/core/event/ImageInsertStartedEvent.kt diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index b0df7a9..f004cf2 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -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 index 6daef1a..0000000 --- a/src/main/java/net/pterodactylus/sone/core/event/ImageEvent.java +++ /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 . - */ - -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 index 2bfa3a2..0000000 --- a/src/main/java/net/pterodactylus/sone/core/event/ImageInsertAbortedEvent.java +++ /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 . - */ - -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 index 430c64b..0000000 --- a/src/main/java/net/pterodactylus/sone/core/event/ImageInsertFailedEvent.java +++ /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 . - */ - -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 index 4419311..0000000 --- a/src/main/java/net/pterodactylus/sone/core/event/ImageInsertFinishedEvent.java +++ /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 . - */ - -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 index ac9e3e3..0000000 --- a/src/main/java/net/pterodactylus/sone/core/event/ImageInsertStartedEvent.java +++ /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 . - */ - -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 index 7c8a6c3..0000000 --- a/src/main/java/net/pterodactylus/sone/core/event/MarkPostKnownEvent.java +++ /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 . - */ - -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 index 0000000..0f12a86 --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/core/event/MarkPostKnownEvent.kt @@ -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 . + */ + +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 index 93a61c6..0000000 --- a/src/main/java/net/pterodactylus/sone/core/event/PostEvent.java +++ /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 . - */ - -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 index 0000000..04d46c6 --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/core/event/PostEvent.kt @@ -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 . + */ + +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 + } + +} diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index 3d131c8..0ed9e47 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -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 index 0000000..0fca0ab --- /dev/null +++ b/src/main/kotlin/net/pterodactylus/sone/core/event/ImageEvent.kt @@ -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 . + */ + +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 index 0000000..55455c7 --- /dev/null +++ b/src/main/kotlin/net/pterodactylus/sone/core/event/ImageInsertAbortedEvent.kt @@ -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 . + */ + +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 index 0000000..07b82a8 --- /dev/null +++ b/src/main/kotlin/net/pterodactylus/sone/core/event/ImageInsertFailedEvent.kt @@ -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 . + */ + +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 index 0000000..d275dd1 --- /dev/null +++ b/src/main/kotlin/net/pterodactylus/sone/core/event/ImageInsertFinishedEvent.kt @@ -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 . + */ + +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 index 0000000..939525d --- /dev/null +++ b/src/main/kotlin/net/pterodactylus/sone/core/event/ImageInsertStartedEvent.kt @@ -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 . + */ + +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) diff --git a/src/test/java/net/pterodactylus/sone/core/FreenetInterfaceTest.java b/src/test/java/net/pterodactylus/sone/core/FreenetInterfaceTest.java index c91de68..9391bde 100644 --- a/src/test/java/net/pterodactylus/sone/core/FreenetInterfaceTest.java +++ b/src/test/java/net/pterodactylus/sone/core/FreenetInterfaceTest.java @@ -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 = forClass(ImageInsertStartedEvent.class); verify(eventBus).post(imageInsertStartedEvent.capture()); - assertThat(imageInsertStartedEvent.getValue().image(), is(image)); + assertThat(imageInsertStartedEvent.getValue().getImage(), is(image)); insertToken.cancel(); ArgumentCaptor 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 = 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.is(insertException)); } @Test @@ -378,8 +380,8 @@ public class FreenetInterfaceTest { ArgumentCaptor 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 = 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 = 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 -- 2.7.4