2 * Sone - DeleteReplyCommandTest.java - Copyright © 2013 David Roden
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.
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.
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/>.
18 package net.pterodactylus.sone.fcp;
20 import static net.pterodactylus.sone.fcp.Verifiers.verifyAnswer;
21 import static net.pterodactylus.sone.freenet.fcp.Command.AccessType.DIRECT;
22 import static org.hamcrest.MatcherAssert.assertThat;
23 import static org.hamcrest.Matchers.is;
24 import static org.mockito.ArgumentCaptor.forClass;
25 import static org.mockito.Mockito.doNothing;
27 import net.pterodactylus.sone.data.Mocks;
28 import net.pterodactylus.sone.data.PostReply;
29 import net.pterodactylus.sone.data.Sone;
30 import net.pterodactylus.sone.freenet.SimpleFieldSetBuilder;
31 import net.pterodactylus.sone.freenet.fcp.Command.Response;
32 import net.pterodactylus.sone.freenet.fcp.FcpException;
34 import freenet.support.SimpleFieldSet;
36 import org.junit.Test;
37 import org.mockito.ArgumentCaptor;
40 * Unit test for {@link DeleteReplyCommand}.
42 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
44 public class DeleteReplyCommandTest {
46 private final Mocks mocks = new Mocks();
47 private final DeleteReplyCommand deleteReplyCommand = new DeleteReplyCommand(mocks.core);
50 public void verifyThatDeletingAReplyWorks() throws FcpException {
51 Sone sone = mocks.mockSone("SoneId").local().create();
52 PostReply postReply = mocks.mockPostReply(sone, "ReplyId").create();
53 ArgumentCaptor<PostReply> postReplyCaptor = forClass(PostReply.class);
54 doNothing().when(mocks.core).deleteReply(postReplyCaptor.capture());
55 SimpleFieldSet deleteReplyFieldSet = new SimpleFieldSetBuilder()
56 .put("Message", "DeleteReply")
57 .put("Reply", "ReplyId")
59 Response response = deleteReplyCommand.execute(deleteReplyFieldSet, null, DIRECT);
60 verifyAnswer(response, "ReplyDeleted");
61 assertThat(postReplyCaptor.getValue(), is(postReply));
64 @Test(expected = FcpException.class)
65 public void verifyThatDeletingAReplyWithAnInvalidReplyIdCausesAnError() throws FcpException {
66 SimpleFieldSet deleteReplyFieldSet = new SimpleFieldSetBuilder()
67 .put("Message", "DeleteReply")
68 .put("Reply", "ReplyId")
70 deleteReplyCommand.execute(deleteReplyFieldSet, null, DIRECT);
73 @Test(expected = FcpException.class)
74 public void verifyThatDeletingAReplyWithoutReplyIdCausesAnError() throws FcpException {
75 SimpleFieldSet deleteReplyFieldSet = new SimpleFieldSetBuilder()
76 .put("Message", "DeleteReply")
78 deleteReplyCommand.execute(deleteReplyFieldSet, null, DIRECT);
82 public void verifyThatDeletingAReplyFromANonLocalSoneCausesAnError() throws FcpException {
83 Sone sone = mocks.mockSone("SoneId").create();
84 mocks.mockPostReply(sone, "ReplyId").create();
85 SimpleFieldSet deleteReplyFieldSet = new SimpleFieldSetBuilder()
86 .put("Message", "DeleteReply")
87 .put("Reply", "ReplyId")
89 Response response = deleteReplyCommand.execute(deleteReplyFieldSet, null, DIRECT);
90 verifyAnswer(response, "Error");
91 assertThat(response.getReplyParameters().get("ErrorCode"), is("401"));