X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftext%2FSoneTextParserTest.java;h=ef98e3633c51fe2e0f54ae392fa6fd927487c28a;hp=8dc1d4a07e4ebb39c38b42c24e56e326a74b9318;hb=616d826774d0ac43e1152ec6a4f5c3c198b95483;hpb=00a434a23c9ea1e57c63d8a3c0fc4b09277af431 diff --git a/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java b/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java index 8dc1d4a..ef98e36 100644 --- a/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java +++ b/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java @@ -31,9 +31,11 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; +import net.pterodactylus.sone.data.Album; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.data.impl.IdOnlySone; +import net.pterodactylus.sone.database.AlbumProvider; import net.pterodactylus.sone.database.PostProvider; import net.pterodactylus.sone.database.SoneProvider; @@ -50,7 +52,8 @@ public class SoneTextParserTest { private final SoneProvider soneProvider = new TestSoneProvider(); private final TestPostProvider postProvider = new TestPostProvider(); - private final SoneTextParser soneTextParser = new SoneTextParser(soneProvider, postProvider); + private final TestAlbumProvider albumProvider = new TestAlbumProvider(); + private final SoneTextParser soneTextParser = new SoneTextParser(soneProvider, postProvider, albumProvider); /** * Tests basic plain-text operation of the parser. @@ -153,6 +156,13 @@ public class SoneTextParserTest { assertThat(convertText(parts, PlainTextPart.class, PostPart.class), is("This [post|old|foo|Post about foo...] is awesome.")); } + @Test + public void linksToAlbumIsParsedCorrectly() throws IOException { + albumProvider.addAlbumTitle("album-id", "Super Album"); + Iterable parts = soneTextParser.parse(null, new StringReader("This album://album-id rocks!")); + assertThat(convertText(parts, PlainTextPart.class, AlbumPart.class), is("This [album|album-id|Super Album] rocks!")); + } + // // PRIVATE METHODS // @@ -213,6 +223,9 @@ public class SoneTextParserTest { .append('|') .append(postPart.getPost().getText()) .append(']'); + } else if (part instanceof AlbumPart) { + Album album = ((AlbumPart) part).getAlbum(); + text.append(String.format("[album|%s|%s]", album.getId(), album.getTitle())); } } return text.toString(); @@ -311,4 +324,25 @@ public class SoneTextParserTest { } + private static class TestAlbumProvider implements AlbumProvider { + + private final Map albumTitles = new HashMap(); + + public void addAlbumTitle(String albumId, String albumTitle) { + albumTitles.put(albumId, albumTitle); + } + + @Override + public Optional getAlbum(String albumId) { + if (albumTitles.containsKey(albumId)) { + Album album = mock(Album.class); + when(album.getId()).thenReturn(albumId); + when(album.getTitle()).thenReturn(albumTitles.get(albumId)); + return Optional.of(album); + } + return Optional.absent(); + } + + } + }