3b6e3a044472c0f55006c9d92af73da532c54c26
[Sone.git] / src / test / java / net / pterodactylus / sone / fcp / Verifiers.java
1 /*
2  * Sone - Verifiers.java - Copyright © 2013 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.fcp;
19
20 import static java.lang.String.format;
21 import static org.hamcrest.MatcherAssert.assertThat;
22 import static org.hamcrest.Matchers.is;
23
24 import net.pterodactylus.sone.data.Post;
25 import net.pterodactylus.sone.data.PostReply;
26
27 import freenet.node.FSParseException;
28 import freenet.support.SimpleFieldSet;
29
30 /**
31  * Verifiers used throughout the {@link net.pterodactylus.sone.fcp} package.
32  *
33  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
34  */
35 public class Verifiers {
36
37         static void verifyPost(SimpleFieldSet replyParameters, String prefix, Post post) throws FSParseException {
38                 assertThat(replyParameters.get(format("%sID", prefix)), is(post.getId()));
39                 assertThat(replyParameters.get(format("%sSone", prefix)), is(post.getSone().getId()));
40                 assertThat(replyParameters.get(format("%sRecipient", prefix)), is(post.getRecipientId().orNull()));
41                 assertThat(replyParameters.getLong(format("%sTime", prefix)), is(post.getTime()));
42                 assertThat(replyParameters.get(format("%sText", prefix)), is(post.getText()));
43         }
44
45         static void verifyPostReply(SimpleFieldSet replyParameters, String prefix, PostReply postReply) throws FSParseException {
46                 assertThat(replyParameters.get(format("%sID", prefix)), is(postReply.getId()));
47                 assertThat(replyParameters.get(format("%sSone", prefix)), is(postReply.getSone().getId()));
48                 assertThat(replyParameters.getLong(format("%sTime", prefix)), is(postReply.getTime()));
49                 assertThat(replyParameters.get(format("%sText", prefix)), is(postReply.getText()));
50         }
51
52 }