From: David ‘Bombe’ Roden Date: Mon, 27 Sep 2021 12:34:26 +0000 (+0200) Subject: Fix incorrect comparison X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=04f79f207d77abc1d28043fa22f4c4ad946dd1ae;p=Sone.git Fix incorrect comparison The result of Object.equals(Object) will _always_ be non-null because a primitive is always non-null. So once we use the correct method to check the result of the equals call everything will be fine. --- diff --git a/src/main/java/net/pterodactylus/sone/data/impl/ImageImpl.java b/src/main/java/net/pterodactylus/sone/data/impl/ImageImpl.java index 0dd84fe..9446cec 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/ImageImpl.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/ImageImpl.java @@ -95,7 +95,7 @@ public class ImageImpl implements Image { @Override public Image setAlbum(Album album) { checkNotNull(album, "album must not be null"); - checkNotNull(album.getSone().equals(getSone()), "album must belong to the same Sone as this image"); + checkState(album.getSone().equals(getSone()), "album must belong to the same Sone as this image"); this.album = album; return this; } diff --git a/src/test/kotlin/net/pterodactylus/sone/data/impl/ImageImplTest.kt b/src/test/kotlin/net/pterodactylus/sone/data/impl/ImageImplTest.kt index 022bde0..e1551e1 100644 --- a/src/test/kotlin/net/pterodactylus/sone/data/impl/ImageImplTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/data/impl/ImageImplTest.kt @@ -15,4 +15,13 @@ class ImageImplTest { image.modify().setTitle("").update() } + @Test(expected = IllegalStateException::class) + fun `album cannot be changed to album of different Sone`() { + val sone1 = IdOnlySone("Sone1") + val sone2 = IdOnlySone("Sone2") + image.modify().setSone(sone1).update() + val album = AlbumImpl(sone2) + image.album = album + } + }