Update mockito dependency to 2.1.0
[Sone.git] / src / test / java / net / pterodactylus / sone / text / SoneTextParserTest.java
1 /*
2  * Sone - SoneTextParserTest.java - Copyright © 2011–2016 David Roden
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 package net.pterodactylus.sone.text;
19
20 import static org.hamcrest.MatcherAssert.assertThat;
21 import static org.hamcrest.Matchers.is;
22 import static org.hamcrest.Matchers.isIn;
23 import static org.hamcrest.Matchers.notNullValue;
24
25 import java.io.IOException;
26 import java.util.Collection;
27
28 import net.pterodactylus.sone.data.Post;
29 import net.pterodactylus.sone.data.Sone;
30 import net.pterodactylus.sone.data.impl.IdOnlySone;
31 import net.pterodactylus.sone.database.PostProvider;
32 import net.pterodactylus.sone.database.SoneProvider;
33
34 import com.google.common.base.Function;
35 import com.google.common.base.Optional;
36 import org.junit.Test;
37
38 /**
39  * JUnit test case for {@link SoneTextParser}.
40  *
41  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
42  */
43 public class SoneTextParserTest {
44
45         private final SoneTextParser soneTextParser = new SoneTextParser(null, null);
46
47         @SuppressWarnings("static-method")
48         @Test
49         public void testPlainText() throws IOException {
50                 /* check basic operation. */
51                 Iterable<Part> parts = soneTextParser.parse("Test.", null);
52                 assertThat("Parts", parts, notNullValue());
53                 assertThat("Part Text", convertText(parts, PlainTextPart.class), is("Test."));
54
55                 /* check empty lines at start and end. */
56                 parts = soneTextParser.parse("\nTest.\n\n", null);
57                 assertThat("Parts", parts, notNullValue());
58                 assertThat("Part Text", convertText(parts, PlainTextPart.class), is("Test."));
59
60                 /* check duplicate empty lines in the text. */
61                 parts = soneTextParser.parse("\nTest.\n\n\nTest.", null);
62                 assertThat("Parts", parts, notNullValue());
63                 assertThat("Part Text", convertText(parts, PlainTextPart.class), is("Test.\n\nTest."));
64         }
65
66         @Test
67         public void consecutiveLinesAreSeparatedByLinefeed() {
68                 Iterable<Part> parts = soneTextParser.parse("Text.\nText", null);
69                 assertThat("Part Text", convertText(parts), is("Text.\nText"));
70         }
71
72         @Test
73         public void freenetLinksHaveTheFreenetPrefixRemoved() {
74                 Iterable<Part> parts = soneTextParser.parse("freenet:KSK@gpl.txt", null);
75                 assertThat("Part Text", convertText(parts), is("[KSK@gpl.txt|gpl.txt|gpl.txt]"));
76         }
77
78         @Test
79         public void onlyTheFirstItemInALineIsPrefixedWithALineBreak() {
80                 Iterable<Part> parts = soneTextParser.parse("Text.\nKSK@gpl.txt and KSK@gpl.txt", null);
81                 assertThat("Part Text", convertText(parts), is("Text.\n[KSK@gpl.txt|gpl.txt|gpl.txt] and [KSK@gpl.txt|gpl.txt|gpl.txt]"));
82         }
83
84         @Test
85         public void soneLinkWithTooShortSoneIdIsRenderedAsPlainText() {
86                 Iterable<Part> parts = soneTextParser.parse("sone://too-short", null);
87                 assertThat("Part Text", convertText(parts), is("sone://too-short"));
88         }
89
90         @Test
91         public void soneLinkIsRenderedCorrectlyIfSoneIsNotPresent() {
92                 SoneTextParser parser = new SoneTextParser(new AbsentSoneProvider(), null);
93                 Iterable<Part> parts = parser.parse("sone://DAxKQzS48mtaQc7sUVHIgx3fnWZPQBz0EueBreUVWrU", null);
94                 assertThat("Part Text", convertText(parts), is("[Sone|DAxKQzS48mtaQc7sUVHIgx3fnWZPQBz0EueBreUVWrU]"));
95         }
96
97         @Test
98         public void postLinkIsRenderedAsPlainTextIfPostIdIsTooShort() {
99                 Iterable<Part> parts = soneTextParser.parse("post://too-short", null);
100                 assertThat("Part Text", convertText(parts), is("post://too-short"));
101         }
102
103         @Test
104         public void postLinkIsRenderedCorrectlyIfPostIsPresent() {
105                 SoneTextParser parser = new SoneTextParser(null, new TestPostProvider());
106                 Iterable<Part> parts = parser.parse("post://f3757817-b45a-497a-803f-9c5aafc10dc6", null);
107                 assertThat("Part Text", convertText(parts), is("[Post|f3757817-b45a-497a-803f-9c5aafc10dc6|text]"));
108         }
109
110         @Test
111         public void postLinkIsRenderedAsPlainTextIfPostIsAbsent() {
112                 SoneTextParser parser = new SoneTextParser(null, new AbsentPostProvider());
113                 Iterable<Part> parts = parser.parse("post://f3757817-b45a-497a-803f-9c5aafc10dc6", null);
114                 assertThat("Part Text", convertText(parts), is("post://f3757817-b45a-497a-803f-9c5aafc10dc6"));
115         }
116
117         @Test
118         public void nameOfFreenetLinkDoesNotContainUrlParameters() {
119             Iterable<Part> parts = soneTextParser.parse("KSK@gpl.txt?max-size=12345", null);
120                 assertThat("Part Text", convertText(parts), is("[KSK@gpl.txt?max-size=12345|gpl.txt|gpl.txt]"));
121         }
122
123         @Test
124         public void trailingSlashInFreenetLinkIsRemovedForName() {
125                 Iterable<Part> parts = soneTextParser.parse("KSK@gpl.txt/", null);
126                 assertThat("Part Text", convertText(parts), is("[KSK@gpl.txt/|gpl.txt|gpl.txt]"));
127         }
128
129         @Test
130         public void lastMetaStringOfFreenetLinkIsUsedAsName() {
131                 Iterable<Part> parts = soneTextParser.parse("CHK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/COPYING", null);
132                 assertThat("Part Text", convertText(parts), is("[CHK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/COPYING|COPYING|COPYING]"));
133         }
134
135         @Test
136         public void freenetLinkWithoutMetaStringsAndDocNameGetsFirstNineCharactersOfKeyAsName() {
137                 Iterable<Part> parts = soneTextParser.parse("CHK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8", null);
138                 assertThat("Part Text", convertText(parts), is("[CHK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8|CHK@qM1nm|CHK@qM1nm]"));
139         }
140
141         @Test
142         public void malformedKeyIsRenderedAsPlainText() {
143                 Iterable<Part> parts = soneTextParser.parse("CHK@qM1nmgU", null);
144                 assertThat("Part Text", convertText(parts), is("CHK@qM1nmgU"));
145         }
146
147         @Test
148         public void httpsLinkHasItsPathsShortened() {
149                 Iterable<Part> parts = soneTextParser.parse("https://test.test/some-long-path/file.txt", null);
150                 assertThat("Part Text", convertText(parts), is("[https://test.test/some-long-path/file.txt|test.test/…/file.txt|test.test/…/file.txt]"));
151         }
152
153         @Test
154         public void httpLinksHaveTheirLastSlashRemoved() {
155             Iterable<Part> parts = soneTextParser.parse("http://test.test/test/", null);
156                 assertThat("Part Text", convertText(parts), is("[http://test.test/test/|test.test/…|test.test/…]"));
157         }
158
159         @Test
160         public void wwwPrefixIsRemovedForHostnameWithTwoDotsAndNoPath() {
161                 Iterable<Part> parts = soneTextParser.parse("http://www.test.test", null);
162                 assertThat("Part Text", convertText(parts), is("[http://www.test.test|test.test|test.test]"));
163         }
164
165         @Test
166         public void wwwPrefixIsRemovedForHostnameWithTwoDotsAndAPath() {
167                 Iterable<Part> parts = soneTextParser.parse("http://www.test.test/test.html", null);
168                 assertThat("Part Text", convertText(parts), is("[http://www.test.test/test.html|test.test/test.html|test.test/test.html]"));
169         }
170
171         @Test
172         public void hostnameIsKeptIntactIfNotBeginningWithWww() {
173                 Iterable<Part> parts = soneTextParser.parse("http://test.test.test/test.html", null);
174                 assertThat("Part Text", convertText(parts), is("[http://test.test.test/test.html|test.test.test/test.html|test.test.test/test.html]"));
175         }
176
177         @Test
178         public void hostnameWithOneDotButNoSlashIsKeptIntact() {
179                 Iterable<Part> parts = soneTextParser.parse("http://test.test", null);
180                 assertThat("Part Text", convertText(parts), is("[http://test.test|test.test|test.test]"));
181         }
182
183         @Test
184         public void urlParametersAreRemovedForHttpLinks() {
185                 Iterable<Part> parts = soneTextParser.parse("http://test.test?foo=bar", null);
186                 assertThat("Part Text", convertText(parts), is("[http://test.test?foo=bar|test.test|test.test]"));
187         }
188
189         @Test
190         public void emptyStringIsParsedCorrectly() {
191                 Iterable<Part> parts = soneTextParser.parse("", null);
192                 assertThat("Part Text", convertText(parts), is(""));
193         }
194
195         @Test
196         public void linksAreParsedInCorrectOrder() {
197                 Iterable<Part> parts = soneTextParser.parse("KSK@ CHK@", null);
198                 assertThat("Part Text", convertText(parts), is("KSK@ CHK@"));
199         }
200
201         @Test
202         public void sskLinkWithoutContextIsNotTrusted() {
203                 Iterable<Part> parts = soneTextParser.parse("SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test", null);
204                 assertThat("Part Text", convertText(parts), is("[SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test|test|test]"));
205         }
206
207         @Test
208         public void sskLinkWithContextWithoutSoneIsNotTrusted() {
209                 SoneTextParserContext context = new SoneTextParserContext(null);
210                 Iterable<Part> parts = soneTextParser.parse("SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test", context);
211                 assertThat("Part Text", convertText(parts), is("[SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test|test|test]"));
212         }
213
214         @Test
215         public void sskLinkWithContextWithDifferentSoneIsNotTrusted() {
216                 SoneTextParserContext context = new SoneTextParserContext(new IdOnlySone("DAxKQzS48mtaQc7sUVHIgx3fnWZPQBz0EueBreUVWrU"));
217                 Iterable<Part> parts = soneTextParser.parse("SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test", context);
218                 assertThat("Part Text", convertText(parts), is("[SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test|test|test]"));
219         }
220
221         @Test
222         public void sskLinkWithContextWithCorrectSoneIsTrusted() {
223                 SoneTextParserContext context = new SoneTextParserContext(new IdOnlySone("qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU"));
224                 Iterable<Part> parts = soneTextParser.parse("SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test", context);
225                 assertThat("Part Text", convertText(parts), is("[SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test|trusted|test|test]"));
226         }
227
228         @Test
229         public void uskLinkWithContextWithCorrectSoneIsTrusted() {
230                 SoneTextParserContext context = new SoneTextParserContext(new IdOnlySone("qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU"));
231                 Iterable<Part> parts = soneTextParser.parse("USK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test/0", context);
232                 assertThat("Part Text", convertText(parts), is("[USK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test/0|trusted|test|test]"));
233         }
234
235         @SuppressWarnings("static-method")
236         @Test
237         public void testKSKLinks() throws IOException {
238                 /* check basic links. */
239                 Iterable<Part> parts = soneTextParser.parse("KSK@gpl.txt", null);
240                 assertThat("Parts", parts, notNullValue());
241                 assertThat("Part Text", convertText(parts, FreenetLinkPart.class), is("[KSK@gpl.txt|gpl.txt|gpl.txt]"));
242
243                 /* check embedded links. */
244                 parts = soneTextParser.parse("Link is KSK@gpl.txt\u200b.", null);
245                 assertThat("Parts", parts, notNullValue());
246                 assertThat("Part Text", convertText(parts, PlainTextPart.class, FreenetLinkPart.class), is("Link is [KSK@gpl.txt|gpl.txt|gpl.txt]\u200b."));
247
248                 /* check embedded links and line breaks. */
249                 parts = soneTextParser.parse("Link is KSK@gpl.txt\nKSK@test.dat\n", null);
250                 assertThat("Parts", parts, notNullValue());
251                 assertThat("Part Text", convertText(parts, PlainTextPart.class, FreenetLinkPart.class), is("Link is [KSK@gpl.txt|gpl.txt|gpl.txt]\n[KSK@test.dat|test.dat|test.dat]"));
252         }
253
254         @SuppressWarnings({ "synthetic-access", "static-method" })
255         @Test
256         public void testEmptyLinesAndSoneLinks() throws IOException {
257                 SoneTextParser soneTextParser = new SoneTextParser(new TestSoneProvider(), null);
258
259                 /* check basic links. */
260                 Iterable<Part> parts = soneTextParser.parse("Some text.\n\nLink to sone://DAxKQzS48mtaQc7sUVHIgx3fnWZPQBz0EueBreUVWrU and stuff.", null);
261                 assertThat("Parts", parts, notNullValue());
262                 assertThat("Part Text", convertText(parts, PlainTextPart.class, SonePart.class), is("Some text.\n\nLink to [Sone|DAxKQzS48mtaQc7sUVHIgx3fnWZPQBz0EueBreUVWrU] and stuff."));
263         }
264
265         @SuppressWarnings({ "synthetic-access", "static-method" })
266         @Test
267         public void testEmpyHttpLinks() throws IOException {
268                 SoneTextParser soneTextParser = new SoneTextParser(new TestSoneProvider(), null);
269
270                 /* check empty http links. */
271                 Iterable<Part> parts = soneTextParser.parse("Some text. Empty link: http:// – nice!", null);
272                 assertThat("Parts", parts, notNullValue());
273                 assertThat("Part Text", convertText(parts, PlainTextPart.class), is("Some text. Empty link: http:// – nice!"));
274         }
275
276         @Test
277         public void httpLinkWithoutParensEndsAtNextClosingParen() {
278                 Iterable<Part> parts = soneTextParser.parse("Some text (and a link: http://example.sone/abc) – nice!", null);
279                 assertThat("Parts", parts, notNullValue());
280                 assertThat("Part Text", convertText(parts, PlainTextPart.class, LinkPart.class), is("Some text (and a link: [http://example.sone/abc|example.sone/abc|example.sone/abc]) – nice!"));
281         }
282
283         @Test
284         public void httpLinkWithOpenedAndClosedParensEndsAtNextClosingParen() {
285                 Iterable<Part> parts = soneTextParser.parse("Some text (and a link: http://example.sone/abc_(def)) – nice!", null);
286                 assertThat("Parts", parts, notNullValue());
287                 assertThat("Part Text", convertText(parts, PlainTextPart.class, LinkPart.class), is("Some text (and a link: [http://example.sone/abc_(def)|example.sone/abc_(def)|example.sone/abc_(def)]) – nice!"));
288         }
289
290         @Test
291         public void punctuationIsIgnoredAtEndOfLinkBeforeWhitespace() {
292                 SoneTextParser soneTextParser = new SoneTextParser(null, null);
293                 Iterable<Part> parts = soneTextParser.parse("Some text and a link: http://example.sone/abc. Nice!", null);
294                 assertThat("Parts", parts, notNullValue());
295                 assertThat("Part Text", convertText(parts, PlainTextPart.class, LinkPart.class), is("Some text and a link: [http://example.sone/abc|example.sone/abc|example.sone/abc]. Nice!"));
296         }
297
298         @Test
299         public void multiplePunctuationCharactersAreIgnoredAtEndOfLinkBeforeWhitespace() {
300                 Iterable<Part> parts = soneTextParser.parse("Some text and a link: http://example.sone/abc... Nice!", null);
301                 assertThat("Parts", parts, notNullValue());
302                 assertThat("Part Text", convertText(parts, PlainTextPart.class, LinkPart.class), is("Some text and a link: [http://example.sone/abc|example.sone/abc|example.sone/abc]... Nice!"));
303         }
304
305         @Test
306         public void commasAreIgnoredAtEndOfLinkBeforeWhitespace() {
307                 SoneTextParser soneTextParser = new SoneTextParser(null, null);
308                 Iterable<Part> parts = soneTextParser.parse("Some text and a link: http://example.sone/abc, nice!", null);
309                 assertThat("Parts", parts, notNullValue());
310                 assertThat("Part Text", convertText(parts, PlainTextPart.class, LinkPart.class), is("Some text and a link: [http://example.sone/abc|example.sone/abc|example.sone/abc], nice!"));
311         }
312
313         /**
314          * Converts all given {@link Part}s into a string, validating that the
315          * part’s classes match only the expected classes.
316          *
317          * @param parts
318          *            The parts to convert to text
319          * @param validClasses
320          *            The valid classes; if no classes are given, all classes are
321          *            valid
322          * @return The converted text
323          */
324         private static String convertText(Iterable<Part> parts, Class<?>... validClasses) {
325                 StringBuilder text = new StringBuilder();
326                 for (Part part : parts) {
327                         assertThat("Part", part, notNullValue());
328                         if (validClasses.length != 0) {
329                                 assertThat("Part’s class", part.getClass(), isIn(validClasses));
330                         }
331                         if (part instanceof PlainTextPart) {
332                                 text.append(((PlainTextPart) part).getText());
333                         } else if (part instanceof FreenetLinkPart) {
334                                 FreenetLinkPart freenetLinkPart = (FreenetLinkPart) part;
335                                 text.append('[').append(freenetLinkPart.getLink()).append('|').append(freenetLinkPart.isTrusted() ? "trusted|" : "").append(freenetLinkPart.getTitle()).append('|').append(freenetLinkPart.getText()).append(']');
336                         } else if (part instanceof LinkPart) {
337                                 LinkPart linkPart = (LinkPart) part;
338                                 text.append('[').append(linkPart.getLink()).append('|').append(linkPart.getTitle()).append('|').append(linkPart.getText()).append(']');
339                         } else if (part instanceof SonePart) {
340                                 SonePart sonePart = (SonePart) part;
341                                 text.append("[Sone|").append(sonePart.getSone().getId()).append(']');
342                         } else if (part instanceof PostPart) {
343                                 PostPart postPart = (PostPart) part;
344                                 text.append("[Post|").append(postPart.getPost().getId()).append("|").append(postPart.getPost().getText()).append("]");
345                         }
346                 }
347                 return text.toString();
348         }
349
350         /**
351          * Mock Sone provider.
352          *
353          * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
354          */
355         private static class TestSoneProvider implements SoneProvider {
356
357                 @Override
358                 public Function<String, Optional<Sone>> soneLoader() {
359                         return new Function<String, Optional<Sone>>() {
360                                 @Override
361                                 public Optional<Sone> apply(String soneId) {
362                                         return getSone(soneId);
363                                 }
364                         };
365                 }
366
367                 /**
368                  * {@inheritDoc}
369                  */
370                 @Override
371                 public Optional<Sone> getSone(final String soneId) {
372                         return Optional.<Sone>of(new IdOnlySone(soneId));
373                 }
374
375                 /**
376                  * {@inheritDocs}
377                  */
378                 @Override
379                 public Collection<Sone> getSones() {
380                         return null;
381                 }
382
383                 /**
384                  * {@inheritDocs}
385                  */
386                 @Override
387                 public Collection<Sone> getLocalSones() {
388                         return null;
389                 }
390
391                 /**
392                  * {@inheritDocs}
393                  */
394                 @Override
395                 public Collection<Sone> getRemoteSones() {
396                         return null;
397                 }
398
399         }
400
401         private static class AbsentSoneProvider extends TestSoneProvider {
402
403                 @Override
404                 public Optional<Sone> getSone(String soneId) {
405                         return Optional.absent();
406                 }
407
408         }
409
410         private static class TestPostProvider implements PostProvider {
411
412                 @Override
413                 public Optional<Post> getPost(final String postId) {
414                         return Optional.<Post>of(new Post() {
415                                 @Override
416                                 public String getId() {
417                                         return postId;
418                                 }
419
420                                 @Override
421                                 public boolean isLoaded() {
422                                         return false;
423                                 }
424
425                                 @Override
426                                 public Sone getSone() {
427                                         return null;
428                                 }
429
430                                 @Override
431                                 public Optional<String> getRecipientId() {
432                                         return null;
433                                 }
434
435                                 @Override
436                                 public Optional<Sone> getRecipient() {
437                                         return null;
438                                 }
439
440                                 @Override
441                                 public long getTime() {
442                                         return 0;
443                                 }
444
445                                 @Override
446                                 public String getText() {
447                                         return "text";
448                                 }
449
450                                 @Override
451                                 public boolean isKnown() {
452                                         return false;
453                                 }
454
455                                 @Override
456                                 public Post setKnown(boolean known) {
457                                         return null;
458                                 }
459                         });
460                 }
461
462                 @Override
463                 public Collection<Post> getPosts(String soneId) {
464                         return null;
465                 }
466
467                 @Override
468                 public Collection<Post> getDirectedPosts(String recipientId) {
469                         return null;
470                 }
471
472         }
473
474         private static class AbsentPostProvider extends TestPostProvider {
475
476                 @Override
477                 public Optional<Post> getPost(String postId) {
478                         return Optional.absent();
479                 }
480
481         }
482
483 }