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.
@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;
}
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
+ }
+
}